Skip to content
Browse files

added tests for get_current_wizard_step and next! and previous!

  • Loading branch information...
1 parent 2b4f19e commit 7c6cd11f84f802bc2cb5f1990696657147b149f2 @adkron committed May 30, 2008
Showing with 36 additions and 19 deletions.
  1. +1 −11 lib/acts_as_wizard.rb
  2. +31 −8 test/acts_as_wizard_test.rb
  3. +4 −0 test/schema.rb
View
12 lib/acts_as_wizard.rb
@@ -36,7 +36,7 @@ def acts_as_wizard(*opts)
opts.each do |opt|
has_one opt, :dependent => :destroy
- state opt, :after => :current_page
+ state opt
end
event :next do
@@ -52,11 +52,6 @@ def acts_as_wizard(*opts)
end
module InstanceMethods
- # return the model for the current wizard page
- def current_page
- @current_page ||= find_page(self.get_current_wizard_step)
- end
-
# returns a symbol for the current wizard page
def get_current_wizard_step
current_state
@@ -95,11 +90,6 @@ def get_wizard_page
def switch_wizard_page(direction)
send(direction)
end
-
- private
- def find_page(state)
- page_class.send("find_by_#{self.class.to_s.underscore}_id",self.id)
- end
end
module ClassMethods
View
39 test/acts_as_wizard_test.rb
@@ -23,13 +23,17 @@
class MainModel < ActiveRecord::Base
- acts_as_wizard :first_page
+ acts_as_wizard :first_page, :second_page
end
class FirstPage < ActiveRecord::Base
acts_as_wizard_page :main_model
end
+class SecondPage < ActiveRecord::Base
+ acts_as_wizard_page :main_model
+end
+
class EmptyModel < ActiveRecord::Base
end
@@ -53,13 +57,6 @@ def test_no_errors
EmptyModel.acts_as_wizard(:foo)
end
- def test_current_page_raises_error_if_model_does_not_exist
- EmptyModel.acts_as_wizard(:foo)
- @bunk_model = EmptyModel.new
- e = assert_raise(NoMethodError) { @bunk_model.current_page }
- assert_equal("undefined method `to_sym' for nil:NilClass", e.message)
- end
-
def test_get_wizard_page_returns_a_new_first_page_when_there_is_no_first_page
@page = @main_model.get_wizard_page
assert_equal(FirstPage, @page.class)
@@ -73,4 +70,30 @@ def test_get_wizard_page_returns_the_first_page_when_there_is_a_first_page
assert_equal(@expected_page, @page)
end
+ def test_get_current_wizard_step_returns_first_page_on_new_model
+ assert_equal(:first_page, @main_model.get_current_wizard_step)
+ end
+
+ def test_get_current_wizard_step_returns_second_page_after_next_called
+ @main_model.next!
+ assert_equal(:second_page, @main_model.get_current_wizard_step)
+ end
+
+ def test_get_current_wizard_step_returns_first_page_after_next_called_and_then_previous_called
+ @main_model.next!
+ @main_model.previous!
+ assert_equal(:first_page, @main_model.get_current_wizard_step)
+ end
+
+ def test_get_current_wizard_step_returns_first_page_if_previous_called_on_first_page
+ @main_model.previous!
+ assert_equal(:first_page, @main_model.get_current_wizard_step)
+ end
+
+ def test_get_current_wizard_step_returns_second_page_after_next_called_and_next_called_again
+ @main_model.next!
+ @main_model.next!
+ assert_equal(:second_page, @main_model.get_current_wizard_step)
+ end
+
end
View
4 test/schema.rb
@@ -10,4 +10,8 @@
create_table :first_pages, :force => true do |t|
t.integer :main_model_id
end
+
+ create_table :second_pages, :force => true do |t|
+ t.integer :main_model_id
+ end
end

0 comments on commit 7c6cd11

Please sign in to comment.
Something went wrong with that request. Please try again.