thoughtbot-shoulda 2.9.1 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/README.rdoc +27 -5
  2. data/Rakefile +2 -2
  3. data/lib/shoulda.rb +1 -1
  4. data/lib/shoulda/{controller.rb → action_controller.rb} +6 -8
  5. data/lib/shoulda/{controller → action_controller}/helpers.rb +1 -16
  6. data/lib/shoulda/action_controller/macros.rb +277 -0
  7. data/lib/shoulda/action_controller/matchers.rb +37 -0
  8. data/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  9. data/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  10. data/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  11. data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  12. data/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +81 -0
  13. data/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  14. data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  15. data/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  16. data/lib/shoulda/action_view.rb +10 -0
  17. data/lib/shoulda/action_view/macros.rb +56 -0
  18. data/lib/shoulda/active_record/macros.rb +8 -13
  19. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +1 -1
  20. data/lib/shoulda/rails.rb +4 -3
  21. data/lib/shoulda/rspec.rb +7 -5
  22. data/test/functional/posts_controller_test.rb +28 -22
  23. data/test/functional/users_controller_test.rb +0 -19
  24. data/test/matchers/{allow_mass_assignment_of_matcher_test.rb → active_record/allow_mass_assignment_of_matcher_test.rb} +1 -1
  25. data/test/matchers/{allow_value_matcher_test.rb → active_record/allow_value_matcher_test.rb} +1 -1
  26. data/test/matchers/{association_matcher_test.rb → active_record/association_matcher_test.rb} +1 -1
  27. data/test/matchers/{ensure_inclusion_of_matcher_test.rb → active_record/ensure_inclusion_of_matcher_test.rb} +1 -1
  28. data/test/matchers/{ensure_length_of_matcher_test.rb → active_record/ensure_length_of_matcher_test.rb} +1 -1
  29. data/test/matchers/{have_db_column_matcher_test.rb → active_record/have_db_column_matcher_test.rb} +1 -1
  30. data/test/matchers/{have_index_matcher_test.rb → active_record/have_index_matcher_test.rb} +1 -1
  31. data/test/matchers/{have_named_scope_matcher_test.rb → active_record/have_named_scope_matcher_test.rb} +1 -1
  32. data/test/matchers/{have_readonly_attributes_matcher_test.rb → active_record/have_readonly_attributes_matcher_test.rb} +1 -1
  33. data/test/matchers/{validate_acceptance_of_matcher_test.rb → active_record/validate_acceptance_of_matcher_test.rb} +1 -1
  34. data/test/matchers/{validate_numericality_of_matcher_test.rb → active_record/validate_numericality_of_matcher_test.rb} +1 -1
  35. data/test/matchers/{validate_presence_of_matcher_test.rb → active_record/validate_presence_of_matcher_test.rb} +1 -1
  36. data/test/matchers/{validate_uniqueness_of_matcher_test.rb → active_record/validate_uniqueness_of_matcher_test.rb} +8 -2
  37. data/test/matchers/controller/assign_to_matcher_test.rb +35 -0
  38. data/test/matchers/controller/filter_param_matcher_test.rb +32 -0
  39. data/test/matchers/controller/render_with_layout_matcher_test.rb +33 -0
  40. data/test/matchers/controller/respond_with_content_type_matcher_test.rb +27 -0
  41. data/test/matchers/controller/respond_with_matcher_test.rb +106 -0
  42. data/test/matchers/controller/route_matcher_test.rb +58 -0
  43. data/test/matchers/controller/set_session_matcher_test.rb +27 -0
  44. data/test/matchers/controller/set_the_flash_matcher.rb +41 -0
  45. data/test/model_builder.rb +47 -2
  46. data/test/rails_root/app/models/user.rb +2 -1
  47. data/test/rails_root/config/environment.rb +1 -1
  48. data/test/rspec_test.rb +207 -0
  49. data/test/unit/user_test.rb +10 -1
  50. metadata +43 -24
  51. data/lib/shoulda/controller/formats/html.rb +0 -199
  52. data/lib/shoulda/controller/formats/xml.rb +0 -168
  53. data/lib/shoulda/controller/macros.rb +0 -336
  54. data/lib/shoulda/controller/resource_options.rb +0 -233
@@ -14,8 +14,10 @@ class Test::Unit::TestCase
14
14
  end
15
15
  end
16
16
 
17
- def define_model_class(class_name, &block)
18
- klass = Class.new(ActiveRecord::Base)
17
+ def define_constant(class_name, base, &block)
18
+ class_name = class_name.to_s.camelize
19
+
20
+ klass = Class.new(base)
19
21
  Object.const_set(class_name, klass)
20
22
 
21
23
  klass.class_eval(&block) if block_given?
@@ -26,6 +28,10 @@ class Test::Unit::TestCase
26
28
  klass
27
29
  end
28
30
 
31
+ def define_model_class(class_name, &block)
32
+ define_constant(class_name, ActiveRecord::Base, &block)
33
+ end
34
+
29
35
  def define_model(name, columns = {}, &block)
30
36
  class_name = name.to_s.pluralize.classify
31
37
  table_name = class_name.tableize
@@ -39,6 +45,37 @@ class Test::Unit::TestCase
39
45
  define_model_class(class_name, &block)
40
46
  end
41
47
 
48
+ def define_controller(class_name, &block)
49
+ class_name = class_name.to_s
50
+ class_name << 'Controller' unless class_name =~ /Controller$/
51
+ define_constant(class_name, ActionController::Base, &block)
52
+ end
53
+
54
+ def define_routes(&block)
55
+ @replaced_routes = ActionController::Routing::Routes
56
+ new_routes = ActionController::Routing::RouteSet.new
57
+ silence_warnings do
58
+ ActionController::Routing.const_set('Routes', new_routes)
59
+ end
60
+ new_routes.draw(&block)
61
+ end
62
+
63
+ def build_response(&block)
64
+ klass = define_controller('Examples')
65
+ block ||= lambda { render :nothing => true }
66
+ klass.class_eval { define_method(:example, &block) }
67
+ define_routes do |map|
68
+ map.connect 'examples', :controller => 'examples', :action => 'example'
69
+ end
70
+
71
+ @controller = klass.new
72
+ @request = ActionController::TestRequest.new
73
+ @response = ActionController::TestResponse.new
74
+ get :example
75
+
76
+ @controller
77
+ end
78
+
42
79
  def teardown_with_models
43
80
  if @defined_constants
44
81
  @defined_constants.each do |class_name|
@@ -54,6 +91,14 @@ class Test::Unit::TestCase
54
91
  end
55
92
  end
56
93
 
94
+ if @replaced_routes
95
+ ActionController::Routing::Routes.clear!
96
+ silence_warnings do
97
+ ActionController::Routing.const_set('Routes', @replaced_routes)
98
+ end
99
+ @replaced_routes.reload!
100
+ end
101
+
57
102
  teardown_without_models
58
103
  end
59
104
  alias_method :teardown_without_models, :teardown
@@ -20,7 +20,8 @@ class User < ActiveRecord::Base
20
20
 
21
21
  validates_format_of :email, :with => /\w*@\w*.com/
22
22
  validates_length_of :email, :in => 1..100
23
- validates_inclusion_of :age, :in => 1..100
23
+ validates_numericality_of :age, :greater_than_or_equal_to => 1,
24
+ :less_than_or_equal_to => 100
24
25
  validates_acceptance_of :eula
25
26
  validates_uniqueness_of :email, :scope => :name, :case_sensitive => false
26
27
  validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
@@ -1,6 +1,6 @@
1
1
  # Specifies gem version of Rails to use when vendor/rails is not present
2
2
  old_verbose, $VERBOSE = $VERBOSE, nil
3
- RAILS_GEM_VERSION = '>= 2.1.0' unless defined? RAILS_GEM_VERSION
3
+ RAILS_GEM_VERSION = '= 2.2.2' unless defined? RAILS_GEM_VERSION
4
4
  $VERBOSE = old_verbose
5
5
 
6
6
  require File.join(File.dirname(__FILE__), 'boot')
@@ -0,0 +1,207 @@
1
+ require 'test_helper'
2
+
3
+ begin
4
+ gem 'rspec'
5
+ gem 'rspec-rails'
6
+ rescue LoadError => exception
7
+ puts exception.message
8
+ puts "RSpec integration was not tested because RSpec is not available"
9
+ else
10
+
11
+ class RspecTest < Test::Unit::TestCase
12
+
13
+ SHOULDA_ROOT =
14
+ File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
15
+
16
+ def setup
17
+ build_gemspec
18
+ end
19
+
20
+ def teardown
21
+ FileUtils.rm_rf(project_dir)
22
+ FileUtils.rm_rf("#{shoulda_root}/pkg")
23
+ end
24
+
25
+ should "integrate correctly when using config.gem in test.rb" do
26
+ create_project
27
+ insert(rspec_dependencies, "config/environments/test.rb")
28
+ vendor_gems('test')
29
+ configure_spec_rails
30
+ assert_configured
31
+ end
32
+
33
+ should "integrate correctly when using config.gem in environment.rb" do
34
+ create_project
35
+ insert(rspec_dependencies,
36
+ "config/environment.rb",
37
+ /Rails::Initializer\.run/)
38
+ vendor_gems('development')
39
+ configure_spec_rails
40
+ assert_configured
41
+ end
42
+
43
+ should "integrate correctly when using require in spec_helper" do
44
+ create_project
45
+ configure_spec_rails
46
+ insert(%{gem 'shoulda'; require 'shoulda'},
47
+ "spec/spec_helper.rb",
48
+ %{require 'spec/rails'})
49
+ assert_configured
50
+ end
51
+
52
+ should "integrate correctly when unpacked and required in spec_helper" do
53
+ create_project
54
+ configure_spec_rails
55
+ insert(%{require 'shoulda'},
56
+ "spec/spec_helper.rb",
57
+ %{require 'spec/rails'})
58
+ unpack_gems
59
+ assert_configured
60
+ end
61
+
62
+ def create_project
63
+ command "rails #{project_dir}"
64
+ end
65
+
66
+ def vendor_gems(env)
67
+ project_command "rake gems:unpack RAILS_ENV=#{env}"
68
+ end
69
+
70
+ def unpack_gems
71
+ FileUtils.mkdir_p "#{project_dir}/vendor/gems"
72
+ FileUtils.cd "#{project_dir}/vendor/gems" do
73
+ %w(rspec rspec-rails shoulda).each do |gem|
74
+ command "gem unpack #{gem}"
75
+ end
76
+ end
77
+
78
+ insert('config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/*/lib"]',
79
+ "config/environment.rb",
80
+ /Rails::Initializer\.run/)
81
+ end
82
+
83
+ def command(command)
84
+ output = `GEM_PATH=#{shoulda_root}/pkg #{command} 2>&1`
85
+ unless $? == 0
86
+ flunk("Command failed with status #{$?}\n#{command}\n#{output}")
87
+ end
88
+ @command_output ||= ''
89
+ @command_output << output
90
+ output
91
+ end
92
+
93
+ def project_command(command)
94
+ result = nil
95
+ FileUtils.cd project_dir do
96
+ result = command(command)
97
+ end
98
+ result
99
+ end
100
+
101
+ def shoulda_command(command)
102
+ FileUtils.cd shoulda_root do
103
+ command(command)
104
+ end
105
+ end
106
+
107
+ def project_name
108
+ 'example_rails_project'
109
+ end
110
+
111
+ def project_dir
112
+ File.expand_path(File.join(File.dirname(__FILE__), project_name))
113
+ end
114
+
115
+ def insert(content, path, after = nil)
116
+ path = File.join(project_dir, path)
117
+ contents = IO.read(path)
118
+ if after
119
+ contents.gsub!(/^(.*#{after}.*)$/, "\\1\n#{content}")
120
+ else
121
+ contents << "\n" << content
122
+ end
123
+ File.open(path, 'w') {|file| file.write(contents) }
124
+ end
125
+
126
+ def rspec_dependencies
127
+ return <<-EOS
128
+ config.gem 'rspec', :lib => 'spec'
129
+ config.gem 'rspec-rails', :lib => false
130
+ config.gem 'shoulda', :lib => 'shoulda'
131
+ EOS
132
+ end
133
+
134
+ def configure_spec_rails
135
+ project_command "script/generate rspec"
136
+ end
137
+
138
+ def assert_configured
139
+ create_model
140
+ migrate
141
+ create_controller
142
+ assert_spec_passes
143
+ end
144
+
145
+ def create_model
146
+ project_command "script/generate rspec_model person name:string"
147
+ insert "validates_presence_of :name",
148
+ "app/models/person.rb",
149
+ /class Person/
150
+ insert "it { should validate_presence_of(:name) }",
151
+ "spec/models/person_spec.rb",
152
+ /describe Person do/
153
+ end
154
+
155
+ def create_controller
156
+ project_command "script/generate rspec_controller people"
157
+ insert "def index; render :text => 'Hello'; end",
158
+ "app/controllers/people_controller.rb",
159
+ /class PeopleController/
160
+ shoulda_controller_example = <<-EOS
161
+ describe PeopleController, "on GET index" do
162
+ integrate_views
163
+ subject { controller }
164
+ before(:each) { get :index }
165
+ it { should respond_with(:success) }
166
+ end
167
+ EOS
168
+ insert shoulda_controller_example,
169
+ "spec/controllers/people_controller_spec.rb"
170
+ end
171
+
172
+ def migrate
173
+ project_command "rake db:migrate"
174
+ end
175
+
176
+ def assert_spec_passes
177
+ result = project_command("rake spec SPEC_OPTS=-fs")
178
+ assert_match /should require name to be set/, result
179
+ assert_match /should respond with 200/, result
180
+ end
181
+
182
+ def shoulda_root
183
+ SHOULDA_ROOT
184
+ end
185
+
186
+ def build_gemspec
187
+ backup_gemspec do
188
+ shoulda_command "rake gemspec"
189
+ shoulda_command "rake gem"
190
+ shoulda_command "gem install --no-ri --no-rdoc -i pkg pkg/shoulda*.gem"
191
+ end
192
+ end
193
+
194
+ def backup_gemspec
195
+ actual = "#{shoulda_root}/shoulda.gemspec"
196
+ backup = "#{shoulda_root}/backup.gemspec"
197
+ FileUtils.mv(actual, backup)
198
+ begin
199
+ yield
200
+ ensure
201
+ FileUtils.mv(backup, actual)
202
+ end
203
+ end
204
+
205
+ end
206
+
207
+ end
@@ -38,7 +38,16 @@ class UserTest < Test::Unit::TestCase
38
38
  should_not_allow_values_for :email, "blah", "b lah"
39
39
  should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
40
40
  should_ensure_length_in_range :email, 1..100
41
- should_ensure_value_in_range :age, 1..100
41
+ should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
42
+ :high_message => /less/
43
+ should_fail do
44
+ should_ensure_value_in_range :age, 1..100, :low_message => /more/,
45
+ :high_message => /less/
46
+ end
47
+ should_fail do
48
+ should_ensure_value_in_range :age, 1..100, :low_message => /greater/,
49
+ :high_message => /fewer/
50
+ end
42
51
  should_not_allow_mass_assignment_of :password
43
52
  should_have_class_methods :find, :destroy
44
53
  should_have_instance_methods :email, :age, :email=, :valid?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.1
4
+ version: 2.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-04 00:00:00 -08:00
12
+ date: 2009-03-03 00:00:00 -08:00
13
13
  default_executable: convert_to_should_syntax
14
14
  dependencies: []
15
15
 
@@ -29,9 +29,26 @@ files:
29
29
  - README.rdoc
30
30
  - bin/convert_to_should_syntax
31
31
  - lib/shoulda
32
+ - lib/shoulda/action_controller
33
+ - lib/shoulda/action_controller/helpers.rb
34
+ - lib/shoulda/action_controller/macros.rb
35
+ - lib/shoulda/action_controller/matchers
36
+ - lib/shoulda/action_controller/matchers/assign_to_matcher.rb
37
+ - lib/shoulda/action_controller/matchers/filter_param_matcher.rb
38
+ - lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
39
+ - lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb
40
+ - lib/shoulda/action_controller/matchers/respond_with_matcher.rb
41
+ - lib/shoulda/action_controller/matchers/route_matcher.rb
42
+ - lib/shoulda/action_controller/matchers/set_session_matcher.rb
43
+ - lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb
44
+ - lib/shoulda/action_controller/matchers.rb
45
+ - lib/shoulda/action_controller.rb
32
46
  - lib/shoulda/action_mailer
33
47
  - lib/shoulda/action_mailer/assertions.rb
34
48
  - lib/shoulda/action_mailer.rb
49
+ - lib/shoulda/action_view
50
+ - lib/shoulda/action_view/macros.rb
51
+ - lib/shoulda/action_view.rb
35
52
  - lib/shoulda/active_record
36
53
  - lib/shoulda/active_record/assertions.rb
37
54
  - lib/shoulda/active_record/helpers.rb
@@ -56,14 +73,6 @@ files:
56
73
  - lib/shoulda/assertions.rb
57
74
  - lib/shoulda/autoload_macros.rb
58
75
  - lib/shoulda/context.rb
59
- - lib/shoulda/controller
60
- - lib/shoulda/controller/formats
61
- - lib/shoulda/controller/formats/html.rb
62
- - lib/shoulda/controller/formats/xml.rb
63
- - lib/shoulda/controller/helpers.rb
64
- - lib/shoulda/controller/macros.rb
65
- - lib/shoulda/controller/resource_options.rb
66
- - lib/shoulda/controller.rb
67
76
  - lib/shoulda/helpers.rb
68
77
  - lib/shoulda/macros.rb
69
78
  - lib/shoulda/private_helpers.rb
@@ -90,19 +99,29 @@ files:
90
99
  - test/functional/posts_controller_test.rb
91
100
  - test/functional/users_controller_test.rb
92
101
  - test/matchers
93
- - test/matchers/allow_mass_assignment_of_matcher_test.rb
94
- - test/matchers/allow_value_matcher_test.rb
95
- - test/matchers/association_matcher_test.rb
96
- - test/matchers/ensure_inclusion_of_matcher_test.rb
97
- - test/matchers/ensure_length_of_matcher_test.rb
98
- - test/matchers/have_db_column_matcher_test.rb
99
- - test/matchers/have_index_matcher_test.rb
100
- - test/matchers/have_named_scope_matcher_test.rb
101
- - test/matchers/have_readonly_attributes_matcher_test.rb
102
- - test/matchers/validate_acceptance_of_matcher_test.rb
103
- - test/matchers/validate_numericality_of_matcher_test.rb
104
- - test/matchers/validate_presence_of_matcher_test.rb
105
- - test/matchers/validate_uniqueness_of_matcher_test.rb
102
+ - test/matchers/active_record
103
+ - test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb
104
+ - test/matchers/active_record/allow_value_matcher_test.rb
105
+ - test/matchers/active_record/association_matcher_test.rb
106
+ - test/matchers/active_record/ensure_inclusion_of_matcher_test.rb
107
+ - test/matchers/active_record/ensure_length_of_matcher_test.rb
108
+ - test/matchers/active_record/have_db_column_matcher_test.rb
109
+ - test/matchers/active_record/have_index_matcher_test.rb
110
+ - test/matchers/active_record/have_named_scope_matcher_test.rb
111
+ - test/matchers/active_record/have_readonly_attributes_matcher_test.rb
112
+ - test/matchers/active_record/validate_acceptance_of_matcher_test.rb
113
+ - test/matchers/active_record/validate_numericality_of_matcher_test.rb
114
+ - test/matchers/active_record/validate_presence_of_matcher_test.rb
115
+ - test/matchers/active_record/validate_uniqueness_of_matcher_test.rb
116
+ - test/matchers/controller
117
+ - test/matchers/controller/assign_to_matcher_test.rb
118
+ - test/matchers/controller/filter_param_matcher_test.rb
119
+ - test/matchers/controller/render_with_layout_matcher_test.rb
120
+ - test/matchers/controller/respond_with_content_type_matcher_test.rb
121
+ - test/matchers/controller/respond_with_matcher_test.rb
122
+ - test/matchers/controller/route_matcher_test.rb
123
+ - test/matchers/controller/set_session_matcher_test.rb
124
+ - test/matchers/controller/set_the_flash_matcher.rb
106
125
  - test/model_builder.rb
107
126
  - test/other
108
127
  - test/other/autoload_macro_test.rb
@@ -195,6 +214,7 @@ files:
195
214
  - test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros
196
215
  - test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb
197
216
  - test/README
217
+ - test/rspec_test.rb
198
218
  - test/test_helper.rb
199
219
  - test/unit
200
220
  - test/unit/address_test.rb
@@ -211,7 +231,6 @@ homepage: http://thoughtbot.com/projects/shoulda
211
231
  post_install_message:
212
232
  rdoc_options:
213
233
  - --line-numbers
214
- - --inline-source
215
234
  - --main
216
235
  - README.rdoc
217
236
  require_paths:
@@ -1,199 +0,0 @@
1
- module Shoulda # :nodoc:
2
- module Controller # :nodoc:
3
- module HTML # :nodoc: all
4
- def self.included(other)
5
- other.class_eval do
6
- extend Shoulda::Controller::HTML::ClassMethods
7
- end
8
- end
9
-
10
- module ClassMethods
11
- def controller_name_from_class
12
- self.name.gsub(/Test/, '')
13
- end
14
-
15
- def make_show_html_tests(res)
16
- context "on GET to #{controller_name_from_class}#show" do
17
- setup do
18
- record = get_existing_record(res)
19
- parent_params = make_parent_params(res, record)
20
- get :show, parent_params.merge({ res.identifier => record.to_param })
21
- end
22
-
23
- if res.denied.actions.include?(:show)
24
- should_not_assign_to res.object
25
- should_redirect_to res.denied.redirect
26
- should_set_the_flash_to res.denied.flash
27
- else
28
- should_assign_to res.object
29
- should_respond_with :success
30
- should_render_template :show
31
- should_not_set_the_flash
32
- end
33
- end
34
- end
35
-
36
- def make_edit_html_tests(res)
37
- context "on GET to #{controller_name_from_class}#edit" do
38
- setup do
39
- @record = get_existing_record(res)
40
- parent_params = make_parent_params(res, @record)
41
- get :edit, parent_params.merge({ res.identifier => @record.to_param })
42
- end
43
-
44
- if res.denied.actions.include?(:edit)
45
- should_not_assign_to res.object
46
- should_redirect_to res.denied.redirect
47
- should_set_the_flash_to res.denied.flash
48
- else
49
- should_assign_to res.object
50
- should_respond_with :success
51
- should_render_template :edit
52
- should_not_set_the_flash
53
- should_render_a_form
54
- should "set @#{res.object} to requested instance" do
55
- assert_equal @record, assigns(res.object)
56
- end
57
- end
58
- end
59
- end
60
-
61
- def make_index_html_tests(res)
62
- context "on GET to #{controller_name_from_class}#index" do
63
- setup do
64
- record = get_existing_record(res) rescue nil
65
- parent_params = make_parent_params(res, record)
66
- get(:index, parent_params)
67
- end
68
-
69
- if res.denied.actions.include?(:index)
70
- should_not_assign_to res.object.to_s.pluralize
71
- should_redirect_to res.denied.redirect
72
- should_set_the_flash_to res.denied.flash
73
- else
74
- should_respond_with :success
75
- should_assign_to res.object.to_s.pluralize
76
- should_render_template :index
77
- should_not_set_the_flash
78
- end
79
- end
80
- end
81
-
82
- def make_new_html_tests(res)
83
- context "on GET to #{controller_name_from_class}#new" do
84
- setup do
85
- record = get_existing_record(res) rescue nil
86
- parent_params = make_parent_params(res, record)
87
- get(:new, parent_params)
88
- end
89
-
90
- if res.denied.actions.include?(:new)
91
- should_not_assign_to res.object
92
- should_redirect_to res.denied.redirect
93
- should_set_the_flash_to res.denied.flash
94
- else
95
- should_respond_with :success
96
- should_assign_to res.object
97
- should_not_set_the_flash
98
- should_render_template :new
99
- should_render_a_form
100
- end
101
- end
102
- end
103
-
104
- def make_destroy_html_tests(res)
105
- context "on DELETE to #{controller_name_from_class}#destroy" do
106
- setup do
107
- @record = get_existing_record(res)
108
- parent_params = make_parent_params(res, @record)
109
- delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
110
- end
111
-
112
- if res.denied.actions.include?(:destroy)
113
- should_redirect_to res.denied.redirect
114
- should_set_the_flash_to res.denied.flash
115
-
116
- should "not destroy record" do
117
- assert_nothing_raised { assert @record.reload }
118
- end
119
- else
120
- should_set_the_flash_to res.destroy.flash
121
- if res.destroy.redirect.is_a? Symbol
122
- should_respond_with res.destroy.redirect
123
- else
124
- should_redirect_to res.destroy.redirect
125
- end
126
-
127
- should "destroy record" do
128
- assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
129
- @record.reload
130
- end
131
- end
132
- end
133
- end
134
- end
135
-
136
- def make_create_html_tests(res)
137
- context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do
138
- setup do
139
- record = get_existing_record(res) rescue nil
140
- parent_params = make_parent_params(res, record)
141
- @count = res.klass.count
142
- post :create, parent_params.merge(res.object => res.create.params)
143
- end
144
-
145
- if res.denied.actions.include?(:create)
146
- should_redirect_to res.denied.redirect
147
- should_set_the_flash_to res.denied.flash
148
- should_not_assign_to res.object
149
-
150
- should "not create new record" do
151
- assert_equal @count, res.klass.count
152
- end
153
- else
154
- should_assign_to res.object
155
- should_set_the_flash_to res.create.flash
156
- if res.create.redirect.is_a? Symbol
157
- should_respond_with res.create.redirect
158
- else
159
- should_redirect_to res.create.redirect
160
- end
161
-
162
- should "not have errors on @#{res.object}" do
163
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
164
- end
165
- end
166
- end
167
- end
168
-
169
- def make_update_html_tests(res)
170
- context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do
171
- setup do
172
- @record = get_existing_record(res)
173
- parent_params = make_parent_params(res, @record)
174
- put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
175
- end
176
-
177
- if res.denied.actions.include?(:update)
178
- should_not_assign_to res.object
179
- should_redirect_to res.denied.redirect
180
- should_set_the_flash_to res.denied.flash
181
- else
182
- should_assign_to res.object
183
- should_set_the_flash_to(res.update.flash)
184
- if res.update.redirect.is_a? Symbol
185
- should_respond_with res.update.redirect
186
- else
187
- should_redirect_to res.update.redirect
188
- end
189
-
190
- should "not have errors on @#{res.object}" do
191
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
192
- end
193
- end
194
- end
195
- end
196
- end
197
- end
198
- end
199
- end