stepper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.document +5 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +144 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +84 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/app/views/stepper/_fields.html.erb +17 -0
  9. data/config/locales/stepper.yml +6 -0
  10. data/lib/stepper.rb +3 -0
  11. data/lib/stepper/controllers/controller_additions.rb +75 -0
  12. data/lib/stepper/controllers/controller_resource.rb +58 -0
  13. data/lib/stepper/engine.rb +4 -0
  14. data/lib/stepper/exceptions.rb +4 -0
  15. data/lib/stepper/helper/action_view_additions.rb +14 -0
  16. data/lib/stepper/models/active_record_additions.rb +96 -0
  17. data/lib/stepper/railtie.rb +26 -0
  18. data/stepper.gemspec +136 -0
  19. data/test/controllers/controller_additions_test.rb +16 -0
  20. data/test/controllers/controller_resource_test.rb +49 -0
  21. data/test/controllers/controller_test.rb +138 -0
  22. data/test/helper.rb +20 -0
  23. data/test/helpers/helper_test.rb +49 -0
  24. data/test/integration/steps_test.rb +39 -0
  25. data/test/models/assigns_test.rb +15 -0
  26. data/test/models/instance_test.rb +65 -0
  27. data/test/models/models_test.rb +26 -0
  28. data/test/models/validation_test.rb +36 -0
  29. data/test/rails_app/Rakefile +7 -0
  30. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  31. data/test/rails_app/app/controllers/companies_controller.rb +11 -0
  32. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  33. data/test/rails_app/app/mailers/.gitkeep +0 -0
  34. data/test/rails_app/app/models/.gitkeep +0 -0
  35. data/test/rails_app/app/models/company.rb +18 -0
  36. data/test/rails_app/app/models/users.rb +3 -0
  37. data/test/rails_app/app/views/companies/_step1_step.html.erb +2 -0
  38. data/test/rails_app/app/views/companies/_step2_step.html.erb +2 -0
  39. data/test/rails_app/app/views/companies/_step3_step.html.erb +2 -0
  40. data/test/rails_app/app/views/companies/index.html.erb +1 -0
  41. data/test/rails_app/app/views/companies/new.html.erb +14 -0
  42. data/test/rails_app/app/views/companies/show.html.erb +1 -0
  43. data/test/rails_app/app/views/layouts/application.html.erb +14 -0
  44. data/test/rails_app/config.ru +4 -0
  45. data/test/rails_app/config/application.rb +43 -0
  46. data/test/rails_app/config/boot.rb +6 -0
  47. data/test/rails_app/config/database.yml +13 -0
  48. data/test/rails_app/config/environment.rb +5 -0
  49. data/test/rails_app/config/environments/development.rb +30 -0
  50. data/test/rails_app/config/environments/production.rb +60 -0
  51. data/test/rails_app/config/environments/test.rb +42 -0
  52. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/rails_app/config/initializers/inflections.rb +10 -0
  54. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  55. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  56. data/test/rails_app/config/initializers/session_store.rb +8 -0
  57. data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
  58. data/test/rails_app/config/locales/en.yml +10 -0
  59. data/test/rails_app/config/routes.rb +3 -0
  60. data/test/rails_app/db/migrate/20110928102949_create_tables.rb +25 -0
  61. data/test/rails_app/db/schema.rb +20 -0
  62. data/test/rails_app/lib/assets/.gitkeep +0 -0
  63. data/test/rails_app/lib/tasks/.gitkeep +0 -0
  64. data/test/rails_app/public/404.html +26 -0
  65. data/test/rails_app/public/422.html +26 -0
  66. data/test/rails_app/public/500.html +26 -0
  67. data/test/rails_app/public/favicon.ico +0 -0
  68. data/test/rails_app/public/index.html +241 -0
  69. data/test/rails_app/public/robots.txt +5 -0
  70. data/test/rails_app/script/rails +6 -0
  71. metadata +232 -0
@@ -0,0 +1,4 @@
1
+ module Stepper #:nodoc:
2
+ class Engine < ::Rails::Engine #:nodoc:
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Stepper
2
+ class StepperException < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Stepper
2
+ module ActionViewAdditions
3
+ module InstanceMethods
4
+ def stepper(form)
5
+ resource = self.instance_variable_get :@_stepper_resource_instance
6
+ current_step_column = resource.class._stepper_current_step_column
7
+ self.render(:partial => "stepper/fields",
8
+ :locals => { :f => form,
9
+ :resource => resource,
10
+ :current_step_column => current_step_column }).to_s
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,96 @@
1
+ module Stepper
2
+ module ActiveRecordAdditions
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.validate :current_step_validation
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_steps(options = {})
11
+ #check options
12
+ raise Stepper::StepperException.new("Options for has_steps must be in a hash.") unless options.is_a? Hash
13
+ options.each do |key, value|
14
+ unless [:current_step_column, :steps].include? key
15
+ raise Stepper::StepperException.new("Unknown option for has_steps: #{key.inspect} => #{value.inspect}.")
16
+ end
17
+ end
18
+
19
+ raise Stepper::StepperException.new(":steps condition can't be blank") if options[:steps].blank?
20
+
21
+ #set current step column
22
+ class_attribute :_stepper_current_step_column
23
+ self._stepper_current_step_column = options[:current_step_column] || :current_step
24
+
25
+ class_attribute :_stepper_steps
26
+ self._stepper_steps= options[:steps]
27
+
28
+ include InstanceMethods
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+
34
+ def stepper_current_step_column
35
+ self.class._stepper_current_step_column
36
+ end
37
+
38
+ def stepper_steps
39
+ self.class._stepper_steps
40
+ end
41
+
42
+ def stepper_current_step_index
43
+ stepper_steps.index(stepper_current_step)
44
+ end
45
+
46
+ alias_method(:steps, :stepper_steps) unless self.respond_to? :steps
47
+
48
+ def stepper_current_step
49
+ self.send(self.class._stepper_current_step_column)
50
+ end
51
+
52
+ def stepper_current_step=(step)
53
+ self.send("#{self.class._stepper_current_step_column}=", step)
54
+ end
55
+
56
+ def last_step?(step = stepper_current_step)
57
+ step == self.stepper_steps.last
58
+ end
59
+
60
+ def first_step?(step = stepper_current_step)
61
+ (step == stepper_steps.first) or stepper_current_step.blank? && step.blank?
62
+ end
63
+
64
+ def previous_step
65
+ return nil if (first_step? or stepper_current_step.blank?)
66
+ stepper_steps[stepper_steps.index(stepper_current_step) - 1]
67
+ end
68
+
69
+ def previous_step!
70
+ self.stepper_current_step = self.previous_step
71
+ self
72
+ end
73
+
74
+ def next_step
75
+ return stepper_steps.first if self.stepper_current_step.blank?
76
+ return nil if self.last_step?
77
+ stepper_steps[stepper_steps.index(stepper_current_step) + 1]
78
+ end
79
+
80
+ def next_step!
81
+ self.stepper_current_step = self.next_step
82
+ self
83
+ end
84
+
85
+ protected
86
+
87
+ def current_step_validation
88
+ return if stepper_current_step.blank?
89
+ for i in 0..stepper_current_step_index do
90
+ self.send("validate_#{stepper_steps[i]}") if self.respond_to?("validate_#{stepper_steps[i]}", true)
91
+ end
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails'
2
+
3
+ require 'stepper/engine'
4
+ require 'stepper/controllers/controller_additions'
5
+ require 'stepper/controllers/controller_resource'
6
+ require 'stepper/exceptions'
7
+ require 'stepper/models/active_record_additions'
8
+ require 'stepper/helper/action_view_additions'
9
+
10
+ module Stepper
11
+ class Railtie < ::Rails::Railtie #:nodoc:
12
+ initializer 'stepper' do |app|
13
+ ActiveSupport.on_load(:active_record) do
14
+ ::ActiveRecord::Base.send :include, Stepper::ActiveRecordAdditions
15
+ end
16
+
17
+ ActiveSupport.on_load(:action_controller) do
18
+ ::ActionController::Base.send :include, Stepper::ControllerAdditions
19
+ end
20
+
21
+ ActiveSupport.on_load(:action_view) do
22
+ ::ActionView::Base.send :include, Stepper::ActionViewAdditions::InstanceMethods
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,136 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{stepper}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Anton Versal}]
12
+ s.date = %q{2011-09-30}
13
+ s.description = %q{Stepper is multistep form (wizard) solution for Rails 3. Stepper allows you to split up your large form into series of pages that users can navigate through to complete the form and save it state.}
14
+ s.email = %q{ant.ver@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "app/views/stepper/_fields.html.erb",
28
+ "config/locales/stepper.yml",
29
+ "lib/stepper.rb",
30
+ "lib/stepper/controllers/controller_additions.rb",
31
+ "lib/stepper/controllers/controller_resource.rb",
32
+ "lib/stepper/engine.rb",
33
+ "lib/stepper/exceptions.rb",
34
+ "lib/stepper/helper/action_view_additions.rb",
35
+ "lib/stepper/models/active_record_additions.rb",
36
+ "lib/stepper/railtie.rb",
37
+ "stepper.gemspec",
38
+ "test/controllers/controller_additions_test.rb",
39
+ "test/controllers/controller_resource_test.rb",
40
+ "test/controllers/controller_test.rb",
41
+ "test/helper.rb",
42
+ "test/helpers/helper_test.rb",
43
+ "test/integration/steps_test.rb",
44
+ "test/models/assigns_test.rb",
45
+ "test/models/instance_test.rb",
46
+ "test/models/models_test.rb",
47
+ "test/models/validation_test.rb",
48
+ "test/rails_app/Rakefile",
49
+ "test/rails_app/app/controllers/application_controller.rb",
50
+ "test/rails_app/app/controllers/companies_controller.rb",
51
+ "test/rails_app/app/helpers/application_helper.rb",
52
+ "test/rails_app/app/mailers/.gitkeep",
53
+ "test/rails_app/app/models/.gitkeep",
54
+ "test/rails_app/app/models/company.rb",
55
+ "test/rails_app/app/models/users.rb",
56
+ "test/rails_app/app/views/companies/_step1_step.html.erb",
57
+ "test/rails_app/app/views/companies/_step2_step.html.erb",
58
+ "test/rails_app/app/views/companies/_step3_step.html.erb",
59
+ "test/rails_app/app/views/companies/index.html.erb",
60
+ "test/rails_app/app/views/companies/new.html.erb",
61
+ "test/rails_app/app/views/companies/show.html.erb",
62
+ "test/rails_app/app/views/layouts/application.html.erb",
63
+ "test/rails_app/config.ru",
64
+ "test/rails_app/config/application.rb",
65
+ "test/rails_app/config/boot.rb",
66
+ "test/rails_app/config/database.yml",
67
+ "test/rails_app/config/environment.rb",
68
+ "test/rails_app/config/environments/development.rb",
69
+ "test/rails_app/config/environments/production.rb",
70
+ "test/rails_app/config/environments/test.rb",
71
+ "test/rails_app/config/initializers/backtrace_silencers.rb",
72
+ "test/rails_app/config/initializers/inflections.rb",
73
+ "test/rails_app/config/initializers/mime_types.rb",
74
+ "test/rails_app/config/initializers/secret_token.rb",
75
+ "test/rails_app/config/initializers/session_store.rb",
76
+ "test/rails_app/config/initializers/wrap_parameters.rb",
77
+ "test/rails_app/config/locales/en.yml",
78
+ "test/rails_app/config/routes.rb",
79
+ "test/rails_app/db/migrate/20110928102949_create_tables.rb",
80
+ "test/rails_app/db/schema.rb",
81
+ "test/rails_app/lib/assets/.gitkeep",
82
+ "test/rails_app/lib/tasks/.gitkeep",
83
+ "test/rails_app/public/404.html",
84
+ "test/rails_app/public/422.html",
85
+ "test/rails_app/public/500.html",
86
+ "test/rails_app/public/favicon.ico",
87
+ "test/rails_app/public/index.html",
88
+ "test/rails_app/public/robots.txt",
89
+ "test/rails_app/script/rails"
90
+ ]
91
+ s.homepage = %q{http://github.com/antonversal/stepper}
92
+ s.licenses = [%q{MIT}]
93
+ s.require_paths = [%q{lib}]
94
+ s.rubygems_version = %q{1.8.6}
95
+ s.summary = %q{Stepper is multistep form (wizard) solution for Rails 3.}
96
+
97
+ if s.respond_to? :specification_version then
98
+ s.specification_version = 3
99
+
100
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
101
+ s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"])
102
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
103
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
104
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
105
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
106
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
107
+ s.add_development_dependency(%q<rcov>, [">= 0"])
108
+ s.add_development_dependency(%q<mocha>, [">= 0"])
109
+ s.add_development_dependency(%q<capybara>, [">= 0"])
110
+ s.add_development_dependency(%q<launchy>, [">= 0"])
111
+ else
112
+ s.add_dependency(%q<rails>, ["~> 3.1.0"])
113
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
114
+ s.add_dependency(%q<sqlite3>, [">= 0"])
115
+ s.add_dependency(%q<shoulda>, [">= 0"])
116
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
117
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
118
+ s.add_dependency(%q<rcov>, [">= 0"])
119
+ s.add_dependency(%q<mocha>, [">= 0"])
120
+ s.add_dependency(%q<capybara>, [">= 0"])
121
+ s.add_dependency(%q<launchy>, [">= 0"])
122
+ end
123
+ else
124
+ s.add_dependency(%q<rails>, ["~> 3.1.0"])
125
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
126
+ s.add_dependency(%q<sqlite3>, [">= 0"])
127
+ s.add_dependency(%q<shoulda>, [">= 0"])
128
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
129
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
130
+ s.add_dependency(%q<rcov>, [">= 0"])
131
+ s.add_dependency(%q<mocha>, [">= 0"])
132
+ s.add_dependency(%q<capybara>, [">= 0"])
133
+ s.add_dependency(%q<launchy>, [">= 0"])
134
+ end
135
+ end
136
+
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class ControllerAdditionsTest < ActiveSupport::TestCase
4
+ setup do
5
+ @controller_class = Class.new
6
+ @controller = @controller_class.new
7
+ @controller_class.send(:include, Stepper::ControllerAdditions)
8
+ end
9
+
10
+ test "should has_steps setup before filter which passes call to ControllerResource" do
11
+ Stepper::ControllerResource.stubs(:new).with(@controller, nil).stubs(:load_resource)
12
+ @controller_class.stubs(:before_filter).with(:only => [:create, :update, :new])
13
+ @controller_class.has_steps
14
+ end
15
+
16
+ end
@@ -0,0 +1,49 @@
1
+ require 'helper'
2
+
3
+ class ControllerResourceTest < ActiveSupport::TestCase
4
+ setup do
5
+ @params = HashWithIndifferentAccess.new(:controller => "companies")
6
+ @controller_class = Class.new
7
+ @controller = @controller_class.new
8
+ @controller.stubs(:params).returns(@params)
9
+ end
10
+
11
+ test "should load resource into instance variable if params[:id] is specified" do
12
+ Company.stubs(:find).with(1).returns(mock_company(:id => 1))
13
+ @params.merge!(:action => "new", :id => mock_company.id)
14
+ resource = Stepper::ControllerResource.new(@controller)
15
+ resource.load_resource
16
+ assert_equal @controller.instance_variable_get(:@company), mock_company
17
+ end
18
+
19
+ test "should build resource and load into instance variable if params[:id] is not specified" do
20
+ Company.stubs(:new).returns(mock_company)
21
+ @params.merge!(:action => "new")
22
+ resource = Stepper::ControllerResource.new(@controller)
23
+ resource.load_resource
24
+ assert_equal @controller.instance_variable_get(:@company), mock_company
25
+ end
26
+
27
+ test "should load resource into instance variable(:new)" do
28
+ Company.stubs(:new).returns(mock_company)
29
+ @params.merge!(:action => "create")
30
+ resource = Stepper::ControllerResource.new(@controller)
31
+ resource.load_resource
32
+ assert_equal @controller.instance_variable_get(:@company), mock_company
33
+ end
34
+
35
+ test "should not load resource into instance variable if instance variable exists" do
36
+ @controller.instance_variable_set(:@company, mock_company)
37
+ @params.merge!(:action => "next_step", :id => 15)
38
+ resource = Stepper::ControllerResource.new(@controller)
39
+ resource.load_resource
40
+ assert_equal @controller.instance_variable_get(:@company), mock_company
41
+ end
42
+
43
+ protected
44
+ def mock_company(stubs={})
45
+ @mock_company ||= mock(stubs)
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,138 @@
1
+ require 'helper'
2
+
3
+ class CompaniesControllerTest < ActionController::TestCase
4
+ tests CompaniesController
5
+
6
+ test "should raise error if commit is unknown" do
7
+ Company.expects(:new).with({'name' => 'Hina'}).returns(mock_company)
8
+ mock_company.expects(:save).returns(true)
9
+ mock_company.stubs(:id).returns(1)
10
+ assert_raise Stepper::StepperException do
11
+ post(:create, {:company => {:name => "Hina"}, :commit => "some commit"})
12
+ end
13
+ end
14
+
15
+ test "should assign resource if params[:id] exists" do
16
+ @controller.expects(:render)
17
+ Company.expects(:find).with('1').returns(mock_company)
18
+ get :new, :id => 1
19
+ assert_response :success
20
+ assert_equal assigns(:company), mock_company
21
+ end
22
+
23
+ test "should get existing assigns" do
24
+ @controller.expects(:render)
25
+ @controller.instance_variable_set(:@company, mock_company)
26
+ get :new, :id => 1
27
+ assert_equal assigns(:company), mock_company
28
+ end
29
+
30
+ protected
31
+ def mock_company(stubs={})
32
+ @mock_company ||= mock(stubs)
33
+ end
34
+ end
35
+
36
+ class CompaniesCreateControllerTest < ActionController::TestCase
37
+ tests CompaniesController
38
+
39
+ setup do
40
+ Company.expects(:new).with({'name' => 'Hina'}).returns(mock_company)
41
+ mock_company.expects(:save).returns(true)
42
+ mock_company.stubs(:id).returns(1)
43
+ end
44
+
45
+ test "should redirect to next step if commit 'Next step'" do
46
+ mock_company.stubs(:stepper_current_step).returns("step1")
47
+ post(:create, {:company => {:name => "Hina"}, :commit => "Next step"})
48
+ assert_response :redirect
49
+ assert_redirected_to "http://test.host/companies/new?id=1"
50
+ assert_equal flash[:notice], "Step Step1 was successfully created."
51
+ end
52
+
53
+ test "should redirect to index if commit 'Finish later'" do
54
+ post(:create, {:company => {:name => "Hina"}, :commit => "Finish later"})
55
+ assert_response :redirect
56
+ assert_redirected_to "http://test.host/companies"
57
+ end
58
+
59
+ protected
60
+ def mock_company(stubs={})
61
+ @mock_company ||= mock(stubs)
62
+ end
63
+ end
64
+
65
+ class CompaniesUpdateControllerTest < ActionController::TestCase
66
+ tests CompaniesController
67
+
68
+ setup do
69
+ Company.expects(:find).with('1').returns(mock_company)
70
+ mock_company.expects(:attributes=).with({'code' => '23'}).returns(true)
71
+ mock_company.expects(:save).returns(true)
72
+ mock_company.stubs(:id).returns(1)
73
+ end
74
+
75
+ test "should redirect to next step if commit 'Next step'" do
76
+ mock_company.stubs(:stepper_current_step).returns("step2")
77
+ put(:update, {:company => {:code => "23"}, :commit => "Next step", :id => 1})
78
+ assert_response :redirect
79
+ assert_redirected_to "http://test.host/companies/new?id=1"
80
+ assert_equal flash[:notice], "Step Step2 was successfully created."
81
+ end
82
+
83
+ test "should redirect to index if commit 'Finish later'" do
84
+ mock_company.stubs(:previous_step!)
85
+ put(:update, {:company => {:code => "23"}, :commit => "Finish later", :id => 1})
86
+ assert_response :redirect
87
+ assert_redirected_to "http://test.host/companies"
88
+ end
89
+
90
+ test "should redirect to previous step if commit 'Previous step'" do
91
+ mock_company.expects(:previous_step!).returns(mock_company).at_least(2)
92
+ mock_company.stubs(:current_step).returns("step2")
93
+ put(:update, {:company => {:code => "23"}, :commit => "Previous step", :id => 1})
94
+ assert_response :redirect
95
+ assert_redirected_to "http://test.host/companies/new?id=1"
96
+ end
97
+
98
+ test "should redirect to show if commit 'Finish form'" do
99
+ put(:update, {:company => {:code => "23"}, :commit => "Finish form", :id => 1})
100
+ assert_response :redirect
101
+ assert_redirected_to "http://test.host/companies/1"
102
+ end
103
+
104
+ protected
105
+ def mock_company(stubs={})
106
+ @mock_company ||= mock(stubs)
107
+ end
108
+ end
109
+
110
+ class CompaniesInvalidParamsControllerTest < ActionController::TestCase
111
+ tests CompaniesController
112
+
113
+ setup do
114
+ @controller.expects(:render).at_least_once
115
+ end
116
+
117
+ test "should create action render to new action if object.save returns false" do
118
+ Company.expects(:new).with({'name' => 'Hina'}).returns(mock_company)
119
+ mock_company.expects(:save).returns(false)
120
+ mock_company.expects(:previous_step!)
121
+ post(:create, {:company => {:name => "Hina"}, :commit => "Next step"})
122
+ assert_response :success
123
+ end
124
+
125
+ test "should update action redirect to new action if object.save returns false" do
126
+ Company.expects(:find).with('1').returns(mock_company)
127
+ mock_company.expects(:attributes=).with({"name" => "Hina"}).returns(true)
128
+ mock_company.expects(:save).returns(false)
129
+ mock_company.expects(:previous_step!)
130
+ post(:update, {:company => {:name => "Hina"}, :id => 1, :commit => "Next step"})
131
+ assert_response :success
132
+ end
133
+
134
+ protected
135
+ def mock_company(stubs={})
136
+ @mock_company ||= mock(stubs)
137
+ end
138
+ end