Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 3.78 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. # Model
  3.  
  4. class Panel < ActiveRecord::Base
  5.  
  6.   validates_presence_of      :serial
  7.   validates_presence_of      :kind
  8.   validates_presence_of      :voc
  9.   validates_presence_of      :isc
  10.   validates_presence_of      :pm
  11.   validates_presence_of      :vm
  12.   validates_presence_of      :im
  13.   validates_presence_of      :ff
  14.   validates_presence_of      :n
  15.   validates_presence_of      :container_number
  16.   validates_numericality_of  :voc
  17.   validates_numericality_of  :isc
  18.   validates_numericality_of  :pm
  19.   validates_numericality_of  :vm
  20.   validates_numericality_of  :im
  21.   validates_numericality_of  :ff
  22.   validates_numericality_of  :n
  23.   validates_uniqueness_of    :serial
  24.  
  25. end
  26. # == Schema Information
  27. #
  28. # Table name: panels
  29. #
  30. #  id               :integer(4)      not null, primary key
  31. #  serial           :string(255)
  32. #  kind             :string(255)
  33. #  voc              :decimal(38, 2)
  34. #  isc              :decimal(38, 2)
  35. #  pm               :decimal(38, 2)
  36. #  vm               :decimal(38, 2)
  37. #  im               :decimal(38, 2)
  38. #  ff               :decimal(38, 2)
  39. #  n                :decimal(38, 2)
  40. #  container_number :string(255)
  41. #  created_at       :datetime
  42. #  updated_at       :datetime
  43. #
  44.  
  45.  
  46. # Controller
  47.  
  48. class Admin::PanelsController < ApplicationController
  49.   before_filter :require_user
  50.   layout 'admin'
  51.  
  52.   def index
  53.     @panels = Panel.paginate(:page => params[:page])
  54.   end
  55.  
  56.   def new
  57.     @panel = Panel.new
  58.   end
  59.  
  60.   def create
  61.     @panel = Panel.new(params[:panel])
  62.     # raise params[:panel].inspect
  63.     # raise @panel.inspect
  64.     if @panel.save
  65.       redirect_to admin_panels_path
  66.     else
  67.       render :new
  68.     end
  69.   end
  70.  
  71. end
  72.  
  73.  
  74. # Form
  75.  
  76. - semantic_form_for [:admin, @panel] do |f|
  77.   = f.inputs :serial, :kind, :voc, :isc, :pm, :vm, :im, :ff, :n, :container_number
  78.   - f.buttons do
  79.     = f.commit_button
  80.  
  81.  
  82. # Scenario
  83.  
  84. Scenario: Create new panel
  85.     Given I am logged in as "john@doe.org" with password "myverysecretpassword"
  86.       And I am on the panels page in the admin area
  87.     When I follow "New Panel"
  88.       And I fill in "Serial" with "SN12345"
  89.       And I fill in "Type" with "Typ A"
  90.       And I fill in "VOC" with "1.32"
  91.       And I fill in "ISC" with "23.21"
  92.       And I fill in "PM" with "12.77"
  93.       And I fill in "VM" with "66.45"
  94.       And I fill in "IM" with "44.0"
  95.       And I fill in "FF" with "77.0"
  96.       And I fill in "N" with "34.7"
  97.       And I fill in "Container" with "Container 3"
  98.       And I press "Save"
  99.     Then I should be on the panels page in the admin area
  100.       And show me the page
  101.       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"
  102.  
  103.  
  104. # Model & Params, created by cucumber:
  105.  
  106. 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>
  107.  
  108.  
  109. # Model & Params, created manually:
  110.  
  111. 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>