statemachine 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +12 -0
- data/Rakefile +21 -20
- data/doc/website/README +6 -0
- data/doc/website/config.yaml +2 -0
- data/doc/website/index.html +39 -0
- data/doc/website/src/default.css +110 -0
- data/doc/website/src/default.template +41 -0
- data/doc/website/src/documentation.page +45 -0
- data/doc/website/src/example.page +13 -0
- data/doc/website/src/example1.page +59 -0
- data/doc/website/src/example2.page +96 -0
- data/doc/website/src/example3.page +76 -0
- data/doc/website/src/example4.page +65 -0
- data/doc/website/src/images/8l_star.png +0 -0
- data/doc/website/src/images/bg.png +0 -0
- data/doc/website/src/images/bottom_border.png +0 -0
- data/doc/website/src/images/bottom_edge.png +0 -0
- data/doc/website/src/images/examples/vending_machine.png +0 -0
- data/doc/website/src/images/examples/vending_machine2.png +0 -0
- data/doc/website/src/images/examples/vending_machine3.png +0 -0
- data/doc/website/src/images/examples/vending_machine4a.png +0 -0
- data/doc/website/src/images/examples/vending_machine4b.png +0 -0
- data/doc/website/src/images/left_edge.png +0 -0
- data/doc/website/src/images/logo.png +0 -0
- data/doc/website/src/images/right_edge.png +0 -0
- data/doc/website/src/images/side_borders.png +0 -0
- data/doc/website/src/index.page +20 -0
- data/generate_tests/dot_graph/turnstile.rb +29 -0
- data/generate_tests/dot_graph/turnstile2.rb +48 -0
- data/generate_tests/java/turnstile.rb +54 -0
- data/generate_tests/java/turnstile2.rb +72 -0
- data/lib/statemachine/action_invokation.rb +0 -19
- data/lib/statemachine/version.rb +2 -2
- data/rails_plugin/README +183 -0
- data/rails_plugin/Rakefile +11 -0
- data/rails_plugin/app/controllers/admin_controller.rb +43 -0
- data/rails_plugin/app/controllers/application.rb +7 -0
- data/rails_plugin/app/controllers/main_controller.rb +34 -0
- data/rails_plugin/app/helpers/admin_helper.rb +2 -0
- data/rails_plugin/app/helpers/application_helper.rb +3 -0
- data/rails_plugin/app/helpers/main_helper.rb +7 -0
- data/rails_plugin/app/models/product.rb +21 -0
- data/rails_plugin/app/models/vending_machine.rb +36 -0
- data/rails_plugin/app/models/vending_machine_interface.rb +101 -0
- data/rails_plugin/app/models/vending_statemachine.rb +41 -0
- data/rails_plugin/app/views/admin/index.rhtml +45 -0
- data/rails_plugin/app/views/layouts/main.rhtml +12 -0
- data/rails_plugin/app/views/main/_info.rhtml +13 -0
- data/rails_plugin/app/views/main/event.rjs +27 -0
- data/rails_plugin/app/views/main/index.rhtml +38 -0
- data/rails_plugin/config/boot.rb +45 -0
- data/rails_plugin/config/database.yml +21 -0
- data/rails_plugin/config/environment.rb +60 -0
- data/rails_plugin/config/environments/development.rb +21 -0
- data/rails_plugin/config/environments/production.rb +18 -0
- data/rails_plugin/config/environments/test.rb +19 -0
- data/rails_plugin/config/routes.rb +23 -0
- data/rails_plugin/db/migrate/001_create_vending_machines.rb +12 -0
- data/rails_plugin/db/migrate/002_create_products.rb +14 -0
- data/rails_plugin/db/migrate/003_add_position_to_products.rb +9 -0
- data/rails_plugin/db/schema.rb +20 -0
- data/rails_plugin/doc/README_FOR_APP +2 -0
- data/rails_plugin/lib/tasks/base.rake +5 -0
- data/rails_plugin/public/.htaccess +40 -0
- data/rails_plugin/public/404.html +30 -0
- data/rails_plugin/public/500.html +30 -0
- data/rails_plugin/public/dispatch.cgi +10 -0
- data/rails_plugin/public/dispatch.fcgi +24 -0
- data/rails_plugin/public/dispatch.rb +10 -0
- data/rails_plugin/public/favicon.ico +0 -0
- data/rails_plugin/public/images/bricks.jpg +0 -0
- data/rails_plugin/public/images/cash_release_button.png +0 -0
- data/rails_plugin/public/images/change.png +0 -0
- data/rails_plugin/public/images/dime.png +0 -0
- data/rails_plugin/public/images/dollar.png +0 -0
- data/rails_plugin/public/images/money_panel.png +0 -0
- data/rails_plugin/public/images/nickel.png +0 -0
- data/rails_plugin/public/images/quarter.png +0 -0
- data/rails_plugin/public/images/rails.png +0 -0
- data/rails_plugin/public/images/vending_machine_body.png +0 -0
- data/rails_plugin/public/index.html +277 -0
- data/rails_plugin/public/javascripts/application.js +2 -0
- data/rails_plugin/public/javascripts/controls.js +833 -0
- data/rails_plugin/public/javascripts/dragdrop.js +942 -0
- data/rails_plugin/public/javascripts/effects.js +1088 -0
- data/rails_plugin/public/javascripts/prototype.js +2515 -0
- data/rails_plugin/public/robots.txt +1 -0
- data/rails_plugin/public/stylesheets/layout.css +163 -0
- data/rails_plugin/script/about +3 -0
- data/rails_plugin/script/breakpointer +3 -0
- data/rails_plugin/script/console +3 -0
- data/rails_plugin/script/destroy +3 -0
- data/rails_plugin/script/generate +3 -0
- data/rails_plugin/script/performance/benchmarker +3 -0
- data/rails_plugin/script/performance/profiler +3 -0
- data/rails_plugin/script/plugin +3 -0
- data/rails_plugin/script/process/inspector +3 -0
- data/rails_plugin/script/process/reaper +3 -0
- data/rails_plugin/script/process/spawner +3 -0
- data/rails_plugin/script/rails_spec +11 -0
- data/rails_plugin/script/rails_spec_server +43 -0
- data/rails_plugin/script/runner +3 -0
- data/rails_plugin/script/server +3 -0
- data/rails_plugin/spec/controllers/admin_controller_spec.rb +7 -0
- data/rails_plugin/spec/controllers/main_controller_spec.rb +38 -0
- data/rails_plugin/spec/fixtures/products.yml +2 -0
- data/rails_plugin/spec/fixtures/vending_machines.yml +2 -0
- data/rails_plugin/spec/helpers/admin_helper_spec.rb +5 -0
- data/rails_plugin/spec/helpers/main_helper_spec.rb +5 -0
- data/rails_plugin/spec/models/product_spec.rb +16 -0
- data/rails_plugin/spec/models/vending_machine_interface_spec.rb +168 -0
- data/rails_plugin/spec/models/vending_machine_spec.rb +30 -0
- data/rails_plugin/spec/models/vending_statemachine_spec.rb +130 -0
- data/rails_plugin/spec/plugins/context_support_spec.rb +28 -0
- data/rails_plugin/spec/plugins/controller_support_spec.rb +98 -0
- data/rails_plugin/spec/spec.opts +1 -0
- data/rails_plugin/spec/spec_helper.rb +28 -0
- data/rails_plugin/spec/views/main/event_spec.rb +61 -0
- data/rails_plugin/vendor/plugins/statemachine/README +4 -0
- data/rails_plugin/vendor/plugins/statemachine/Rakefile +22 -0
- data/rails_plugin/vendor/plugins/statemachine/init.rb +2 -0
- data/rails_plugin/vendor/plugins/statemachine/install.rb +1 -0
- data/rails_plugin/vendor/plugins/statemachine/lib/context_support.rb +22 -0
- data/rails_plugin/vendor/plugins/statemachine/lib/controller_support.rb +85 -0
- data/rails_plugin/vendor/plugins/statemachine/lib/statemachine_on_rails.rb +11 -0
- data/rails_plugin/vendor/plugins/statemachine/tasks/statemachine_tasks.rake +4 -0
- data/spec/action_invokation_spec.rb +1 -1
- data/spec/builder_spec.rb +1 -1
- data/spec/default_transition_spec.rb +1 -1
- data/spec/generate/dot_graph/dot_graph_stagemachine_spec.rb +1 -1
- data/spec/history_spec.rb +1 -1
- data/spec/sm_action_parameterization_spec.rb +1 -1
- data/spec/sm_entry_exit_actions_spec.rb +1 -1
- data/spec/sm_odds_n_ends_spec.rb +1 -1
- data/spec/sm_simple_spec.rb +1 -1
- data/spec/sm_super_state_spec.rb +1 -1
- data/spec/sm_turnstile_spec.rb +1 -1
- data/spec/transition_spec.rb +1 -1
- metadata +162 -46
@@ -0,0 +1 @@
|
|
1
|
+
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
|
@@ -0,0 +1,163 @@
|
|
1
|
+
body {
|
2
|
+
padding: 0px;
|
3
|
+
background-image: url('../images/bricks.jpg');
|
4
|
+
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
|
5
|
+
font-size: 13px;
|
6
|
+
}
|
7
|
+
|
8
|
+
#vending_machine_body {
|
9
|
+
position: absolute;
|
10
|
+
top: 0px;
|
11
|
+
left: 50px;
|
12
|
+
z-index: 1;
|
13
|
+
}
|
14
|
+
|
15
|
+
#money_panel {
|
16
|
+
position: absolute;
|
17
|
+
top: 100px;
|
18
|
+
left: 353px;
|
19
|
+
z-index: 2;
|
20
|
+
}
|
21
|
+
|
22
|
+
#cash_release_button {
|
23
|
+
position: absolute;
|
24
|
+
top: 197px;
|
25
|
+
left: 442px;
|
26
|
+
border: none;
|
27
|
+
z-index: 3;
|
28
|
+
}
|
29
|
+
|
30
|
+
#quartz_screen {
|
31
|
+
position: absolute;
|
32
|
+
top: 115px;
|
33
|
+
left: 359px;
|
34
|
+
width: 115px;
|
35
|
+
height: 32px;
|
36
|
+
text-align: right;
|
37
|
+
font-size: 12pt;
|
38
|
+
color: #64F847;
|
39
|
+
z-index: 100;
|
40
|
+
}
|
41
|
+
|
42
|
+
#dispenser {
|
43
|
+
position: absolute;
|
44
|
+
top: 577px;
|
45
|
+
left: 133px;
|
46
|
+
width: 142px;
|
47
|
+
height: 70px;
|
48
|
+
text-align: center;
|
49
|
+
font-size: 12pt;
|
50
|
+
z-index: 100;
|
51
|
+
}
|
52
|
+
|
53
|
+
#dispenser p {
|
54
|
+
border: 1px solid red;
|
55
|
+
margin: 20px 10px 0px 10px;
|
56
|
+
padding: 5px;
|
57
|
+
background-color: black;
|
58
|
+
color: red;
|
59
|
+
}
|
60
|
+
|
61
|
+
#product_list {
|
62
|
+
position: absolute;
|
63
|
+
top: 235px;
|
64
|
+
left: 355px;
|
65
|
+
width: 125px;
|
66
|
+
height: 440px;
|
67
|
+
text-align: center;
|
68
|
+
z-index: 100;
|
69
|
+
}
|
70
|
+
|
71
|
+
#product_list a {
|
72
|
+
display: block;
|
73
|
+
margin: 5px;
|
74
|
+
padding: 5px;
|
75
|
+
color: black;
|
76
|
+
text-decoration: none;
|
77
|
+
}
|
78
|
+
|
79
|
+
#product_list a:hover {
|
80
|
+
color: blue;
|
81
|
+
background-color: grey;
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
.non_affordable {
|
86
|
+
border: 1px solid black;
|
87
|
+
background-color: lightgrey;
|
88
|
+
}
|
89
|
+
|
90
|
+
.affordable {
|
91
|
+
border: 1px solid green;
|
92
|
+
background-color: lightgreen;
|
93
|
+
}
|
94
|
+
|
95
|
+
#info {
|
96
|
+
position: absolute;
|
97
|
+
top: 275px;
|
98
|
+
left: 525px;
|
99
|
+
width: 250px;
|
100
|
+
padding: 10px;
|
101
|
+
border: 1px solid black;
|
102
|
+
z-index: 100;
|
103
|
+
}
|
104
|
+
|
105
|
+
#cash {
|
106
|
+
position: absolute;
|
107
|
+
top: 50px;
|
108
|
+
left: 525px;
|
109
|
+
width: 250px;
|
110
|
+
padding: 10px;
|
111
|
+
border: 1px solid black;
|
112
|
+
text-align: center;
|
113
|
+
z-index: 100;
|
114
|
+
}
|
115
|
+
|
116
|
+
#links {
|
117
|
+
position: absolute;
|
118
|
+
top: 25px;
|
119
|
+
height: 20px;
|
120
|
+
left: 525px;
|
121
|
+
width: 250px;
|
122
|
+
text-align: center;
|
123
|
+
z-index: 2;
|
124
|
+
}
|
125
|
+
|
126
|
+
h3 {
|
127
|
+
text-align: center;
|
128
|
+
margin: 5px;
|
129
|
+
font-size: 20pt;
|
130
|
+
}
|
131
|
+
|
132
|
+
.money_active {
|
133
|
+
background-color: yellow;
|
134
|
+
}
|
135
|
+
|
136
|
+
#change {
|
137
|
+
position: absolute;
|
138
|
+
top: 681px;
|
139
|
+
left: 362px;
|
140
|
+
z-index: 2;
|
141
|
+
}
|
142
|
+
|
143
|
+
#change_amount {
|
144
|
+
position: absolute;
|
145
|
+
top: 681px;
|
146
|
+
left: 362px;
|
147
|
+
width: 109px;
|
148
|
+
height: 74px;
|
149
|
+
z-index: 100;
|
150
|
+
text-align: center;
|
151
|
+
}
|
152
|
+
|
153
|
+
#change_amount p {
|
154
|
+
border: 1px solid #64F847;
|
155
|
+
margin: 20px 10px 0px 10px;
|
156
|
+
padding: 5px;
|
157
|
+
background-color: black;
|
158
|
+
color: #64F847;
|
159
|
+
}
|
160
|
+
|
161
|
+
th {
|
162
|
+
text-align: left;
|
163
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "drb/drb"
|
4
|
+
|
5
|
+
begin
|
6
|
+
DRb.start_service
|
7
|
+
rails_spec_server = DRbObject.new_with_uri("druby://localhost:8989")
|
8
|
+
rails_spec_server.run(ARGV, STDERR, STDOUT)
|
9
|
+
rescue DRb::DRbConnError
|
10
|
+
puts "No rails_spec_server is running. Please start one via 'script/rails_spec_server'"
|
11
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
|
3
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
|
4
|
+
require 'rubygems'
|
5
|
+
require 'drb/drb'
|
6
|
+
require 'rbconfig'
|
7
|
+
require 'spec'
|
8
|
+
|
9
|
+
module Spec
|
10
|
+
module Runner
|
11
|
+
class RailsSpecServer
|
12
|
+
def run(args, stderr, stdout)
|
13
|
+
$stdout = stdout
|
14
|
+
$stderr = stderr
|
15
|
+
|
16
|
+
::Dispatcher.reset_application!
|
17
|
+
::Dependencies.mechanism = :load
|
18
|
+
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
|
19
|
+
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
|
20
|
+
|
21
|
+
::Spec::Runner::CommandLine.run(args, stderr, stdout, false, true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
puts "Loading Rails environment"
|
27
|
+
|
28
|
+
ENV["RAILS_ENV"] = "test"
|
29
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
30
|
+
require 'dispatcher'
|
31
|
+
|
32
|
+
def restart_test_server
|
33
|
+
puts "restarting"
|
34
|
+
config = ::Config::CONFIG
|
35
|
+
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
36
|
+
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
37
|
+
exec(command_line)
|
38
|
+
end
|
39
|
+
|
40
|
+
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
|
41
|
+
puts "Ready"
|
42
|
+
DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
|
43
|
+
DRb.thread.join
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "The MainController" do
|
4
|
+
controller_name :main
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "Index View spec" do
|
9
|
+
controller_name :main
|
10
|
+
integrate_views
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@vm = VendingMachine.new
|
14
|
+
@product = @vm.add_product(10, "Glue", 100)
|
15
|
+
@vm.save!
|
16
|
+
|
17
|
+
post :index, :id => @vm.id
|
18
|
+
end
|
19
|
+
|
20
|
+
it "Has required divs" do
|
21
|
+
response.should have_tag(:img, :attributes)=> { :id => "vending_machine_body" }
|
22
|
+
response.should have_tag(:img, :attributes)=> { :id => "money_panel" }
|
23
|
+
response.should have_tag(:a, :attributes)=> { :id => "cash_release_button" }
|
24
|
+
response.should have_tag(:div, :attributes)=> { :id => "product_list" }
|
25
|
+
response.should have_tag(:img, :attributes)=> { :id => "change" }
|
26
|
+
response.should have_tag(:div, :attributes)=> { :id => "change_amount" }
|
27
|
+
response.should have_tag(:div, :attributes)=> { :id => "cash" }
|
28
|
+
response.should have_tag(:div, :attributes)=> { :id => "quartz_screen" }
|
29
|
+
response.should have_tag(:div, :attributes)=> { :id => "dispenser" }
|
30
|
+
response.should have_tag(:div, :attributes)=> { :id => "info" }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "products" do
|
34
|
+
response.should have_tag(:a, :attributes)=> { :id => "product_#{@product.id}" }
|
35
|
+
response.should have_tag(:span, :attributes)=> { :id => "product_#{@product.id}_price" }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Product class with fixtures loaded" do
|
4
|
+
fixtures :products
|
5
|
+
|
6
|
+
it "Saved with name and price" do
|
7
|
+
saved = Product.new(:name => "Water", :price => 150)
|
8
|
+
saved.save!
|
9
|
+
|
10
|
+
loaded = Product.find(saved.id)
|
11
|
+
loaded.name.should eql("Water")
|
12
|
+
loaded.price.should equal 150
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Vending Machine Interface" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@display = VendingMachineInterface.new
|
7
|
+
@vm = VendingMachine.new
|
8
|
+
@water = @vm.add_product(10, "Water", 100)
|
9
|
+
@tea = @vm.add_product(10, "Tea", 125)
|
10
|
+
@chocolate = @vm.add_product(10, "Chocolate", 135)
|
11
|
+
@danish = @vm.add_product(10, "Danish", 140)
|
12
|
+
@display.vending_machine = @vm
|
13
|
+
end
|
14
|
+
|
15
|
+
it "message" do
|
16
|
+
@display.message.should eql("Insert Money")
|
17
|
+
@display.add_dollar
|
18
|
+
@display.message.should eql(")$1.00"
|
19
|
+
@display.add_quarter
|
20
|
+
@display.message.should eql(")$1.25"
|
21
|
+
@display.add_dime
|
22
|
+
@display.message.should eql(")$1.35"
|
23
|
+
@display.add_nickel
|
24
|
+
@display.message.should eql(")$1.40"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "message when refusing money" do
|
28
|
+
@display.add_dollar
|
29
|
+
@display.refuse_money
|
30
|
+
@display.message.should eql("Select Item")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "available items" do
|
34
|
+
@display.affordable_items.should eql []
|
35
|
+
@display.non_affordable_items.should eql [@water, @tea, @chocolate, @danish]
|
36
|
+
|
37
|
+
@display.add_dollar
|
38
|
+
@display.affordable_items.should eql [@water]
|
39
|
+
@display.non_affordable_items.should eql [@tea, @chocolate, @danish]
|
40
|
+
|
41
|
+
@display.add_quarter
|
42
|
+
@display.affordable_items.should eql [@water, @tea]
|
43
|
+
@display.non_affordable_items.should eql [@chocolate, @danish]
|
44
|
+
|
45
|
+
@display.add_dime
|
46
|
+
@display.affordable_items.should eql [@water, @tea, @chocolate]
|
47
|
+
@display.non_affordable_items.should eql [@danish]
|
48
|
+
|
49
|
+
@display.add_nickel
|
50
|
+
@display.affordable_items.should eql [@water, @tea, @chocolate, @danish]
|
51
|
+
@display.non_affordable_items.should eql []
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sold out items" do
|
55
|
+
@display.sold_out_items.should eql []
|
56
|
+
@water.inventory = 0
|
57
|
+
@display.sold_out_items.should eql [@water]
|
58
|
+
@danish.inventory = 0
|
59
|
+
@display.sold_out_items.should eql [@water, @danish]
|
60
|
+
|
61
|
+
@display.add_dollar
|
62
|
+
@display.add_quarter
|
63
|
+
@display.affordable_items.should eql [@tea]
|
64
|
+
@display.non_affordable_items.should eql [@chocolate]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "dispense change" do
|
68
|
+
@display.add_dollar
|
69
|
+
@display.dispense_change
|
70
|
+
|
71
|
+
@display.amount_tendered.should equal 0
|
72
|
+
@display.change.should eql(")$1.00"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
describe "Vending Machine Display Spec" do
|
79
|
+
|
80
|
+
before(:each) do
|
81
|
+
@display = VendingMachineInterface.new
|
82
|
+
@sm = mock("vending statemachine")
|
83
|
+
@display.statemachine = @sm
|
84
|
+
|
85
|
+
@vending_machine = VendingMachine.new
|
86
|
+
@milk = @vending_machine.add_product(10, "Milk", 100)
|
87
|
+
@whiskey = @vending_machine.add_product(10, "Whiskey", 200)
|
88
|
+
@vending_machine.save!
|
89
|
+
|
90
|
+
@display.vending_machine = @vending_machine
|
91
|
+
end
|
92
|
+
|
93
|
+
it "start state" do
|
94
|
+
@display.amount_tendered.should equal 0
|
95
|
+
@display.accepting_money.should equal true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "dollar" do
|
99
|
+
@display.add_dollar
|
100
|
+
@display.amount_tendered.should equal 100
|
101
|
+
@display.accepting_money.should equal true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "quarter" do
|
105
|
+
@display.add_quarter
|
106
|
+
@display.amount_tendered.should equal 25
|
107
|
+
@display.accepting_money.should equal true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "dime" do
|
111
|
+
@display.add_dime
|
112
|
+
@display.amount_tendered.should equal 10
|
113
|
+
@display.accepting_money.should equal true
|
114
|
+
end
|
115
|
+
|
116
|
+
it "nickel" do
|
117
|
+
@display.add_nickel
|
118
|
+
@display.amount_tendered.should equal 5
|
119
|
+
@display.accepting_money.should equal true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "dollar when max price is a dollar" do
|
123
|
+
@display.refuse_money
|
124
|
+
@display.accepting_money.should equal false
|
125
|
+
end
|
126
|
+
|
127
|
+
it "make sale" do
|
128
|
+
@display.add_dollar
|
129
|
+
@display.load_product(@milk.id)
|
130
|
+
@display.make_sale
|
131
|
+
|
132
|
+
@display.amount_tendered.should equal 0
|
133
|
+
@display.dispensed_item.name.should eql("Milk")
|
134
|
+
@display.change.should eql(")$0.00"
|
135
|
+
Product.find(@milk.id).inventory.should equal 9
|
136
|
+
@vending_machine.cash.should equal 100
|
137
|
+
end
|
138
|
+
|
139
|
+
it "check affordability with inssuficient funds" do
|
140
|
+
@display.add_dollar
|
141
|
+
@display.load_product(@whiskey.id)
|
142
|
+
|
143
|
+
@sm.should_receive(:refuse_purchase)
|
144
|
+
@display.check_affordability
|
145
|
+
end
|
146
|
+
|
147
|
+
it "check affordability with suficient funds" do
|
148
|
+
@display.add_dollar
|
149
|
+
@display.add_dollar
|
150
|
+
@display.load_product(@whiskey.id)
|
151
|
+
|
152
|
+
@sm.should_receive(:accept_purchase)
|
153
|
+
@display.check_affordability
|
154
|
+
end
|
155
|
+
|
156
|
+
it "check affordability with inssuficient funds" do
|
157
|
+
@whiskey.inventory = 0
|
158
|
+
@whiskey.save!
|
159
|
+
|
160
|
+
@display.add_dollar
|
161
|
+
@display.add_dollar
|
162
|
+
@display.load_product(@whiskey.id)
|
163
|
+
|
164
|
+
@sm.should_receive(:refuse_purchase)
|
165
|
+
@display.check_affordability
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|