- # Model
- class Panel < ActiveRecord::Base
- validates_presence_of :serial
- validates_presence_of :kind
- validates_presence_of :voc
- validates_presence_of :isc
- validates_presence_of :pm
- validates_presence_of :vm
- validates_presence_of :im
- validates_presence_of :ff
- validates_presence_of :n
- validates_presence_of :container_number
- validates_numericality_of :voc
- validates_numericality_of :isc
- validates_numericality_of :pm
- validates_numericality_of :vm
- validates_numericality_of :im
- validates_numericality_of :ff
- validates_numericality_of :n
- validates_uniqueness_of :serial
- end
- # == Schema Information
- #
- # Table name: panels
- #
- # id :integer(4) not null, primary key
- # serial :string(255)
- # kind :string(255)
- # voc :decimal(38, 2)
- # isc :decimal(38, 2)
- # pm :decimal(38, 2)
- # vm :decimal(38, 2)
- # im :decimal(38, 2)
- # ff :decimal(38, 2)
- # n :decimal(38, 2)
- # container_number :string(255)
- # created_at :datetime
- # updated_at :datetime
- #
- # Controller
- class Admin::PanelsController < ApplicationController
- before_filter :require_user
- layout 'admin'
- def index
- @panels = Panel.paginate(:page => params[:page])
- end
- def new
- @panel = Panel.new
- end
- def create
- @panel = Panel.new(params[:panel])
- # raise params[:panel].inspect
- # raise @panel.inspect
- if @panel.save
- redirect_to admin_panels_path
- else
- render :new
- end
- end
- end
- # Form
- - semantic_form_for [:admin, @panel] do |f|
- = f.inputs :serial, :kind, :voc, :isc, :pm, :vm, :im, :ff, :n, :container_number
- - f.buttons do
- = f.commit_button
- # Scenario
- Scenario: Create new panel
- Given I am logged in as "john@doe.org" with password "myverysecretpassword"
- And I am on the panels page in the admin area
- When I follow "New Panel"
- And I fill in "Serial" with "SN12345"
- And I fill in "Type" with "Typ A"
- And I fill in "VOC" with "1.32"
- And I fill in "ISC" with "23.21"
- And I fill in "PM" with "12.77"
- And I fill in "VM" with "66.45"
- And I fill in "IM" with "44.0"
- And I fill in "FF" with "77.0"
- And I fill in "N" with "34.7"
- And I fill in "Container" with "Container 3"
- And I press "Save"
- Then I should be on the panels page in the admin area
- And show me the page
- And 1 panels should exist with serial: "SN12345", kind: "Typ A", voc: 1.32, isc: 23.21, pm: 12.77, vm: 66.45, im: 44, ff: 77, n: 34, container_number: "Container 3"
- # Model & Params, created by cucumber:
- Params: {"container_number"=>"Container 3", "ff"=>"77.0", "kind"=>"Typ A", "serial"=>"SN12345", "vm"=>"66.45", "n"=>"34.7", "isc"=>"23.21", "im"=>"44.0", "pm"=>"12.77", "voc"=>"1.32"} Panel: #<Panel id: nil, serial: "SN12345", kind: "Typ A", voc: 1, isc: 23, pm: 12, vm: 66, im: 44, ff: 77, n: 34, container_number: "Container 3", created_at: nil, updated_at: nil>
- # Model & Params, created manually:
- Params: {"serial"=>"SN12345", "kind"=>"Typ A", "ff"=>"77.0", "container_number"=>"Container 3", "vm"=>"66.45", "isc"=>"23.21", "n"=>"34.7", "im"=>"44.0", "pm"=>"12.77", "voc"=>"1.32"} Panel: #<Panel id: nil, serial: "SN12345", kind: "Typ A", voc: #<BigDecimal:25ce264,'0.132E1',8(8)>, isc: #<BigDecimal:25ce110,'0.2321E2',8(8)>, pm: #<BigDecimal:25ce0c0,'0.1277E2',8(8)>, vm: #<BigDecimal:25ce070,'0.6645E2',8(8)>, im: #<BigDecimal:25cdfd0,'0.44E2',4(8)>, ff: #<BigDecimal:25cdea4,'0.77E2',4(8)>, n: #<BigDecimal:25cde54,'0.347E2',8(8)>, container_number: "Container 3", created_at: nil, updated_at: nil>