restful_controller 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +13 -28
  3. data/lib/restful.rb +3 -3
  4. data/lib/restful/actions.rb +8 -8
  5. data/lib/restful/base.rb +32 -30
  6. data/lib/restful/dummy_responder.rb +7 -1
  7. data/lib/restful/version.rb +1 -1
  8. data/test/actions_definition_test.rb +90 -102
  9. data/test/alternates_controller_test.rb +3 -3
  10. data/test/base_controller_test.rb +3 -3
  11. data/test/blocks_controller_test.rb +21 -19
  12. data/test/custom_notices_controller_test.rb +15 -15
  13. data/test/dummy/Rakefile +1 -1
  14. data/test/dummy/app/controllers/admin/prefix_controller.rb +1 -2
  15. data/test/dummy/app/controllers/alternates_controller.rb +1 -0
  16. data/test/dummy/app/controllers/blocks_controller.rb +1 -0
  17. data/test/dummy/app/controllers/custom_notices_controller.rb +3 -2
  18. data/test/dummy/app/controllers/documents_controller.rb +1 -0
  19. data/test/dummy/app/controllers/home_controller.rb +1 -1
  20. data/test/dummy/bin/bundle +2 -2
  21. data/test/dummy/bin/rails +3 -3
  22. data/test/dummy/bin/rake +2 -2
  23. data/test/dummy/bin/setup +9 -9
  24. data/test/dummy/bin/update +9 -9
  25. data/test/dummy/config.ru +1 -1
  26. data/test/dummy/config/application.rb +2 -2
  27. data/test/dummy/config/boot.rb +2 -2
  28. data/test/dummy/config/environment.rb +1 -1
  29. data/test/dummy/config/environments/development.rb +2 -2
  30. data/test/dummy/config/environments/production.rb +2 -2
  31. data/test/dummy/config/environments/test.rb +1 -1
  32. data/test/dummy/config/initializers/assets.rb +1 -1
  33. data/test/dummy/config/initializers/new_framework_defaults.rb +0 -3
  34. data/test/dummy/config/initializers/secret_token.rb +1 -1
  35. data/test/dummy/config/initializers/session_store.rb +1 -1
  36. data/test/dummy/config/routes.rb +7 -7
  37. data/test/dummy/config/spring.rb +2 -2
  38. data/test/dummy/db/schema.rb +0 -3
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/dummy/log/test.log +8594 -10176
  41. data/test/dummy/test/fixtures/documents.yml +0 -1
  42. data/test/dummy/test/models/document_test.rb +1 -1
  43. data/test/dummy/tmp/cache/assets/sprockets/v3.0/6J/6JkRVOkWfpJgVdKJvc1Pw_0hopmCAb8LywBOAgbTxPY.cache +0 -0
  44. data/test/dummy/tmp/cache/assets/sprockets/v3.0/7C/7CBb8IrKtRa1tAFouXDuh69wf5M06FA1kGvLkb2rHhY.cache +0 -0
  45. data/test/dummy/tmp/cache/assets/sprockets/v3.0/8c/8cL_BBqA8ZjvsO8Qr4y_QwPuT4zY3k9Q9fMic6AyjN4.cache +1 -0
  46. data/test/dummy/tmp/cache/assets/sprockets/v3.0/AA/AA4BDcLoeiNWhgY32FTQ__Sr3wut5WWRnqftFgs6HqA.cache +1 -0
  47. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Fb/fBhPDroIt06Go-FnHxcjidNjJDKR034ZPsNs7oBfVLQ.cache +1 -0
  48. data/test/dummy/tmp/cache/assets/sprockets/v3.0/K3/K3gWPcnFXATaCRmXOiumXOa1X07zA5D6dmFexyOpZEg.cache +1 -0
  49. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Mx/MxcniQVVd54UqFgKOAgwMU27DUDTLRNqbGUi3VXisf0.cache +1 -0
  50. data/test/dummy/tmp/cache/assets/sprockets/v3.0/PS/PS_LEWVle-SdbOI5lVVO7nThhXYrlos5PIdBhuOpLhc.cache +0 -0
  51. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Sp/SpEnq27QAQ0Li1vhxbAKlA33LXAQAnMiJJWPd83x8Ak.cache +1 -0
  52. data/test/dummy/tmp/cache/assets/sprockets/v3.0/cn/cnx0JDK2DwkXAXAchod20Tv0QD0mugtgHIm2tQjgElE.cache +0 -0
  53. data/test/dummy/tmp/cache/assets/sprockets/v3.0/dF/dFunnXYtuyxPw2A4Z33UaEfLNGNvYfZDVJHW2OJtiK4.cache +0 -0
  54. data/test/dummy/tmp/cache/assets/sprockets/v3.0/gT/gT4D8n7iBAqnfdzwUO999860TnF3meQhBBQ6JC7vfdQ.cache +0 -0
  55. data/test/dummy/tmp/cache/assets/sprockets/v3.0/hj/hj8Ir9wcVSy1KYrnWu9bpD24vDhCG3tvt-nKbNxb1Wg.cache +0 -0
  56. data/test/dummy/tmp/cache/assets/sprockets/v3.0/oC/oCsZTGZyV4kH8Y4OeSDUdrwfkJFPzTODZjuBKZB8oGQ.cache +0 -0
  57. data/test/dummy/tmp/cache/assets/sprockets/v3.0/op/opx04YlnioOc0nGwDSqFh0tpSqmnUr0EmTdwAiRhO6Y.cache +1 -0
  58. data/test/dummy/tmp/cache/assets/sprockets/v3.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +0 -0
  59. data/test/dummy/tmp/cache/assets/sprockets/v3.0/sT/sTqWjekGJXt3YciElxAQDbFO3BP9xe1PvjaHnQZPUnc.cache +1 -0
  60. data/test/dummy/tmp/cache/assets/sprockets/v3.0/u2/u2rh3TQBtssLxkixwJPY8KX4qWgNmCCawH5FVfY73gY.cache +0 -0
  61. data/test/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +0 -0
  62. data/test/dummy/tmp/cache/assets/sprockets/v3.0/yU/yUT_twoB3H2TPF6vxGkWJTz0YEE8DxpwPOQNnIT_8Cc.cache +0 -0
  63. data/test/prefix_controller_test.rb +29 -31
  64. data/test/resourceful_test.rb +4 -5
  65. data/test/support/base_actions.rb +90 -88
  66. data/test/test_helper.rb +9 -16
  67. metadata +100 -113
  68. data/test/dummy/log/development.log +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c86fe3cf54305c3c7d1a1cb15279ed126c72a147
4
- data.tar.gz: ccb03fc65324b5a9a5de62ff9339692ea5a3237c
2
+ SHA256:
3
+ metadata.gz: 49c7211f87084860d5ae09b39ece25ac705bd892b99adcb82cdcc1f13cbc356d
4
+ data.tar.gz: ef8650d7bf3331e8faf2d2b883478dd315a688bde0e726b0cec9ec06cf6fde20
5
5
  SHA512:
6
- metadata.gz: 5b0c6420f98e2265fd99d4652491277e46f1962ec77d5d2b685ac428591584e862d504a3469ac8825db11a208e0c59182b0af6c99307bfe67e92285965d3a2e6
7
- data.tar.gz: e091d43deb32a44975fed7db8a22564cdf3c45ebe40151dfaeb200025872917ff62212a24ee5d6b41c43f86dda265845dee80cf20f0e82c4eb6a19637ca93a40
6
+ metadata.gz: 4548866520a2951e1c9188e33cb32de8a1170d992bc70432c207738609ad1704363090166a0cffcc02885980603decb1e5db30e14523b3d2cb84ff9d432c832f
7
+ data.tar.gz: 43e781b84bef704ad6db88aeddd5815d0437f463b69f5cf8096bb1bbad5a8d947ec395583028704c6952f1e43756b44c6fa49e9c8cad04ffefdde8defb23fd9b
data/Rakefile CHANGED
@@ -1,44 +1,29 @@
1
1
  begin
2
- require 'bundler/setup'
2
+ require "bundler/setup"
3
3
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
5
  end
6
6
 
7
- require 'rdoc/task'
7
+ require "rdoc/task"
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Restful'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "Restful"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.rdoc")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
15
  end
16
16
 
17
17
  Bundler::GemHelper.install_tasks
18
18
 
19
- require 'rake/testtask'
20
-
21
- desc 'Run rubocop checks'
22
- task :rubocop do
23
- sh 'rubocop lib test'
24
- end
25
-
26
- desc 'Run flay checks'
27
- task :flay do
28
- sh 'find lib -name \*.rb | xargs flog'
29
- end
30
-
31
- desc 'Run flog checks'
32
- task :flog do
33
- sh 'flay lib/*.rb'
34
- end
19
+ require "rake/testtask"
20
+ require "standard/rake"
35
21
 
36
22
  Rake::TestTask.new(:test) do |t|
37
- t.libs << 'lib'
38
- t.libs << 'test'
39
- t.pattern = 'test/**/*_test.rb'
23
+ t.libs << "lib"
24
+ t.libs << "test"
25
+ t.pattern = "test/**/*_test.rb"
40
26
  t.verbose = false
41
27
  end
42
28
 
43
-
44
29
  task default: :test
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  # Module that require all the libraries need it by Restful library.
3
3
  module Restful
4
- require 'restful/dummy_responder'
5
- require 'restful/actions'
6
- require 'restful/base'
4
+ require "restful/dummy_responder"
5
+ require "restful/actions"
6
+ require "restful/base"
7
7
  end
@@ -70,9 +70,9 @@ module Restful
70
70
  # The instance variable name is a pluralization of the model name defined
71
71
  # in the restful macro.
72
72
  def index(options = {}, &block)
73
- respond_with(collection, options, &block) if stale?(collection, last_modified: collection.maximum(:updated_at))
73
+ respond_with(collection, options, &block) if stale?(collection, last_modified: collection.maximum(:updated_at))
74
74
  end
75
- alias_method :index!, :index
75
+ alias index! index
76
76
 
77
77
  ##
78
78
  # new action, creates a new object and sets an instance variable which can
@@ -81,7 +81,7 @@ module Restful
81
81
  def new(options = {}, &block)
82
82
  respond_with(build_resource, options, &block)
83
83
  end
84
- alias_method :new!, :new
84
+ alias new! new
85
85
 
86
86
  ##
87
87
  # create action, creates a new object off the received params and sets an
@@ -99,7 +99,7 @@ module Restful
99
99
 
100
100
  respond_with_dual(object, options, &block)
101
101
  end
102
- alias_method :create!, :create
102
+ alias create! create
103
103
 
104
104
  ##
105
105
  # edit action, finds an object based on the passed id, if no object is
@@ -115,7 +115,7 @@ module Restful
115
115
 
116
116
  respond_with(object, options, &block)
117
117
  end
118
- alias_method :edit!, :edit
118
+ alias edit! edit
119
119
 
120
120
  ##
121
121
  # update action, finds an object based on the passed id, if no object is
@@ -135,7 +135,7 @@ module Restful
135
135
 
136
136
  respond_with_dual(object, options, &block)
137
137
  end
138
- alias_method :update!, :update
138
+ alias update! update
139
139
 
140
140
  ##
141
141
  # show action, finds an object based on the passed id, if no object is
@@ -147,7 +147,7 @@ module Restful
147
147
 
148
148
  respond_with(object, options, &block) if stale?(object)
149
149
  end
150
- alias_method :show!, :show
150
+ alias show! show
151
151
 
152
152
  ##
153
153
  # destroy action, finds an object based on the passed id, if no object is
@@ -161,7 +161,7 @@ module Restful
161
161
 
162
162
  respond_with(object, options, &block)
163
163
  end
164
- alias_method :destroy!, :destroy
164
+ alias destroy! destroy
165
165
 
166
166
  protected :index!, :new!, :create!, :edit!, :update!, :show!, :destroy!
167
167
  end
@@ -31,7 +31,7 @@ module Restful
31
31
  # restful macro.
32
32
  def collection
33
33
  get_collection_ivar || begin
34
- set_collection_ivar class_name.all
34
+ set_collection_ivar class_name.all
35
35
  end
36
36
  end
37
37
 
@@ -44,42 +44,43 @@ module Restful
44
44
  ##
45
45
  # Generic route path helper method to edit a model.
46
46
  def edit_resource_path(object)
47
- self.send route_prefix_to_method_name("edit_#{class_name.model_name.singular_route_key}_path"),
47
+ send route_prefix_to_method_name("edit_#{class_name.model_name.singular_route_key}_path"),
48
48
  object
49
49
  end
50
50
 
51
51
  ##
52
52
  # Generic route url helper method to edit a model.
53
53
  def edit_resource_url(object)
54
- self.send route_prefix_to_method_name("edit_#{class_name.model_name.singular_route_key}_url"),
54
+ send route_prefix_to_method_name("edit_#{class_name.model_name.singular_route_key}_url"),
55
55
  object
56
56
  end
57
57
 
58
58
  ##
59
59
  # Generic route path helper method for new model.
60
60
  def new_resource_path
61
- self.send route_prefix_to_method_name("new_#{class_name.model_name.singular_route_key}_path")
61
+ send route_prefix_to_method_name("new_#{class_name.model_name.singular_route_key}_path")
62
62
  end
63
63
 
64
64
  ##
65
65
  # Generic route url helper method for new model.
66
66
  def new_resource_url
67
- self.send route_prefix_to_method_name("new_#{class_name.model_name.singular_route_key}_url")
67
+ send route_prefix_to_method_name("new_#{class_name.model_name.singular_route_key}_url")
68
68
  end
69
69
 
70
70
  ##
71
71
  # This is a helper method to get the object collection path.
72
72
  def collection_path
73
- self.send route_prefix_to_method_name("#{class_name.model_name.route_key}_path")
73
+ send route_prefix_to_method_name("#{class_name.model_name.route_key}_path")
74
74
  end
75
75
 
76
76
  ##
77
77
  # This is a helper method to get the object collection url.
78
78
  def collection_url
79
- self.send route_prefix_to_method_name("#{class_name.model_name.route_key}_url")
79
+ send route_prefix_to_method_name("#{class_name.model_name.route_key}_url")
80
80
  end
81
81
 
82
82
  protected
83
+
83
84
  ##
84
85
  # Return a url helper method name with additional route prefix if set.
85
86
  # If route_prefix param is set to `admin` then the method name will be:
@@ -87,8 +88,9 @@ module Restful
87
88
  # edit_resource_path => admin_edit_resource_path
88
89
  #
89
90
  def route_prefix_to_method_name(method)
90
- "#{route_prefix + '_' if route_prefix}#{method}"
91
+ "#{route_prefix + "_" if route_prefix}#{method}"
91
92
  end
93
+
92
94
  ##
93
95
  # Return the instance variable name for a single object based on the model
94
96
  # name defined in the restful macro, example:
@@ -109,7 +111,7 @@ module Restful
109
111
 
110
112
  ##
111
113
  # Get the object from a single object instance variable.
112
- def get_resource_ivar
114
+ def get_resource_ivar # rubocop:disable Naming/AccessorMethodName
113
115
  instance_variable_get resource_ivar
114
116
  end
115
117
 
@@ -118,13 +120,13 @@ module Restful
118
120
  #
119
121
  # ==== Params
120
122
  # * object: The object to be stored in the instance variable.
121
- def set_resource_ivar(object)
123
+ def set_resource_ivar(object) # rubocop:disable Naming/AccessorMethodName
122
124
  instance_variable_set resource_ivar, object
123
125
  end
124
126
 
125
127
  ##
126
128
  # Get the collection of objects from an instance variable.
127
- def get_collection_ivar
129
+ def get_collection_ivar # rubocop:disable Naming/AccessorMethodName
128
130
  instance_variable_get collection_ivar
129
131
  end
130
132
 
@@ -134,7 +136,7 @@ module Restful
134
136
  # ==== Params
135
137
  # * objects: The objects collections to be stored in the instance
136
138
  # variable.
137
- def set_collection_ivar(objects)
139
+ def set_collection_ivar(objects) # rubocop:disable Naming/AccessorMethodName
138
140
  instance_variable_set collection_ivar, objects
139
141
  end
140
142
 
@@ -143,7 +145,7 @@ module Restful
143
145
  # a new object.
144
146
  def build_resource
145
147
  get_resource_ivar || begin
146
- set_resource_ivar class_name.new
148
+ set_resource_ivar class_name.new
147
149
  end
148
150
  end
149
151
 
@@ -167,16 +169,16 @@ module Restful
167
169
  #
168
170
  # If no template method is implemented in the controller then
169
171
  # a NotImplementedError exception is raised.
170
- def get_secure_params
172
+ def get_secure_params # rubocop:disable Naming/AccessorMethodName
171
173
  params_method = "#{action_name}_secure_params".to_sym
172
174
 
173
175
  filterd_params =
174
- (send(params_method) if self.respond_to?(params_method, true)) ||
175
- (send(:secure_params)if self.respond_to?(:secure_params, true))
176
+ (send(params_method) if respond_to?(params_method, true)) ||
177
+ (send(:secure_params) if respond_to?(:secure_params, true))
176
178
 
177
179
  unless filterd_params
178
180
  raise NotImplementedError,
179
- 'You need to define template methods for strong params'
181
+ "You need to define template methods for strong params"
180
182
  end
181
183
 
182
184
  filterd_params
@@ -201,10 +203,10 @@ module Restful
201
203
  end
202
204
  end
203
205
  when 1
204
- respond_with *args, &block
206
+ respond_with(*args, &block)
205
207
  else
206
208
  options[:location] = block.call if block
207
- respond_with *args
209
+ respond_with(*args)
208
210
  end
209
211
  end
210
212
 
@@ -212,10 +214,10 @@ module Restful
212
214
  # This method set the flash messages if they are passed within the action
213
215
  # ==== Params
214
216
  # * options: a hash with :notice or :alert messages
215
- def set_flash(options = {})
216
- if options.has_key?(:notice)
217
+ def set_flash(options = {}) # rubocop:disable Naming/AccessorMethodName
218
+ if options.key?(:notice)
217
219
  flash[:notice] = options[:notice]
218
- elsif options.has_key?(:alert)
220
+ elsif options.key?(:alert)
219
221
  flash[:alert] = options[:alert]
220
222
  end
221
223
  end
@@ -233,11 +235,10 @@ module Restful
233
235
  def find_and_update_resource
234
236
  model = class_name.find(params[:id])
235
237
  model.tap do |m|
236
- m.update_attributes get_secure_params
238
+ m.update get_secure_params
237
239
  set_resource_ivar m
238
240
  end
239
241
  end
240
-
241
242
  end
242
243
 
243
244
  ##
@@ -331,7 +332,7 @@ module Restful
331
332
  # controller to respond.
332
333
  #
333
334
  def restful(model: nil, route_prefix: nil, actions: :all)
334
- self.class_attribute :model_name, :class_name, :route_prefix,
335
+ class_attribute :model_name, :class_name, :route_prefix,
335
336
  instance_writer: false
336
337
 
337
338
  self.model_name = model
@@ -352,6 +353,7 @@ module Restful
352
353
  end
353
354
 
354
355
  protected
356
+
355
357
  ##
356
358
  # Method that calculates the actions to which our controller should
357
359
  # respond to.
@@ -364,7 +366,7 @@ module Restful
364
366
 
365
367
  options = actions.extract_options!
366
368
  except_actions = options[:except] || []
367
- keep_actions = keep_actions - except_actions
369
+ keep_actions -= except_actions
368
370
 
369
371
  (ACTIONS - keep_actions).uniq.each do |action|
370
372
  undef_method action.to_sym, "#{action.to_sym}!"
@@ -374,12 +376,12 @@ module Restful
374
376
  ##
375
377
  # Method that gets the model class name from the passed symbol.
376
378
  def class_from_name
377
- if model_name.to_s.include? '_'
378
- ns, *klass = model_name.to_s.split('_').collect(&:camelize)
379
+ if model_name.to_s.include? "_"
380
+ ns, *klass = model_name.to_s.split("_").collect(&:camelize)
379
381
  begin
380
- "#{ns}::#{klass.join('')}".constantize
382
+ "#{ns}::#{klass.join("")}".constantize
381
383
  rescue NameError
382
- "#{ns}#{klass.join('')}".constantize
384
+ "#{ns}#{klass.join("")}".constantize
383
385
  end
384
386
  else
385
387
  model_name.to_s.camelize.constantize
@@ -4,8 +4,14 @@ module Restful
4
4
  # Since there is no action need it from it, it just implements
5
5
  # a method_missing for responder that needs to be ignored.
6
6
  class DummyResponder
7
- def method_missing(args) #:nodoc:
7
+ # rubocop:disable Style/MethodMissingSuper
8
+ def method_missing(args) # :nodoc:
8
9
  nil
9
10
  end
11
+ # rubocop:enable Style/MethodMissingSuper
12
+
13
+ def respond_to_missing?(name, include_private) # :nodoc:
14
+ true
15
+ end
10
16
  end
11
17
  end
@@ -3,5 +3,5 @@
3
3
  module Restful
4
4
  ##
5
5
  # Sets the library version
6
- VERSION = '0.2.0'
6
+ VERSION = "0.3.0"
7
7
  end
@@ -1,124 +1,112 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
- describe 'Actions definition' do
4
- it 'have all REST actions when no action is defined' do
5
- ##
6
- # Controller class for tests
7
- class AllDefaultActionsController < BaseController
8
- respond_to :html
9
- restful model: :document
10
- end
3
+ class ActionsDefindefionTest < ActiveSupport::TestCase
4
+ class AllDefaultActionsController < BaseController
5
+ respond_to :html
6
+ restful model: :document
7
+ end
11
8
 
12
- subject = AllDefaultActionsController.new
9
+ class AllExplicdefActionsController < BaseController
10
+ respond_to :html
11
+ restful model: :document, actions: :all
12
+ end
13
+
14
+ class ExceptActionsController < BaseController
15
+ respond_to :html
16
+ restful model: :document,
17
+ actions: [:all,
18
+ except: [:eddef, :update, :destroy],]
19
+ end
13
20
 
14
- subject.must_respond_to :index
15
- subject.must_respond_to :show
16
- subject.must_respond_to :edit
17
- subject.must_respond_to :update
18
- subject.must_respond_to :new
19
- subject.must_respond_to :create
20
- subject.must_respond_to :destroy
21
+ class HandPickWdefhExceptionActionsController < BaseController
22
+ respond_to :html
23
+ restful model: :document,
24
+ actions: [:index, :show, :destroy,
25
+ except: [:eddef, :update, :destroy],]
21
26
  end
22
27
 
23
- it 'have all REST actions when all actions are defined' do
24
- ##
25
- # Controller class for tests
26
- class AllExplicitActionsController < BaseController
27
- respond_to :html
28
- restful model: :document, actions: :all
29
- end
30
-
31
- subject = AllExplicitActionsController.new
32
-
33
- subject.must_respond_to :index
34
- subject.must_respond_to :show
35
- subject.must_respond_to :edit
36
- subject.must_respond_to :update
37
- subject.must_respond_to :new
38
- subject.must_respond_to :create
39
- subject.must_respond_to :destroy
28
+ class HandPickActionsController < BaseController
29
+ respond_to :html
30
+ restful model: :document,
31
+ actions: [:index, :show, :destroy]
40
32
  end
41
33
 
42
- it 'have all but except actions' do
43
- ##
44
- # Controller class for tests
45
- class ExceptActionsController < BaseController
46
- respond_to :html
47
- restful model: :document,
48
- actions: [:all,
49
- except: [:edit, :update, :destroy]]
50
- end
34
+ class InvalidActionsController < BaseController
35
+ respond_to :html
36
+ restful model: :document,
37
+ actions: [:indice, :show, :eliminar,
38
+ except: [:eddef, :actualizar, :destroy],]
39
+ end
51
40
 
52
- subject = ExceptActionsController.new
41
+ def test_have_all_rest_actions_when_no_action_is_defined
42
+ subject = AllDefaultActionsController.new
53
43
 
54
- subject.must_respond_to :index
55
- subject.must_respond_to :show
56
- subject.wont_respond_to :edit
57
- subject.wont_respond_to :update
58
- subject.must_respond_to :new
59
- subject.must_respond_to :create
60
- subject.wont_respond_to :destroy
44
+ assert_respond_to subject, :index
45
+ assert_respond_to subject, :show
46
+ refute_respond_to subject, :eddef
47
+ assert_respond_to subject, :update
48
+ assert_respond_to subject, :new
49
+ assert_respond_to subject, :create
50
+ assert_respond_to subject, :destroy
61
51
  end
62
52
 
63
- it 'have listed actions but except actions' do
64
- ##
65
- # Controller class for tests
66
- class HandPickWithExceptionActionsController < BaseController
67
- respond_to :html
68
- restful model: :document,
69
- actions: [:index, :show, :destroy,
70
- except: [:edit, :update, :destroy]]
71
- end
72
-
73
- subject = HandPickWithExceptionActionsController.new
74
-
75
- subject.must_respond_to :index
76
- subject.must_respond_to :show
77
- subject.wont_respond_to :edit
78
- subject.wont_respond_to :update
79
- subject.wont_respond_to :new
80
- subject.wont_respond_to :create
81
- subject.wont_respond_to :destroy
53
+ def test_have_all_rest_actions_when_all_actions_are_defined
54
+ subject = AllExplicdefActionsController.new
55
+
56
+ assert_respond_to subject, :index
57
+ assert_respond_to subject, :show
58
+ refute_respond_to subject, :eddef
59
+ assert_respond_to subject, :update
60
+ assert_respond_to subject, :new
61
+ assert_respond_to subject, :create
62
+ assert_respond_to subject, :destroy
82
63
  end
83
64
 
84
- it 'have listed actions' do
85
- ##
86
- # Controller class for tests
87
- class HandPickActionsController < BaseController
88
- respond_to :html
89
- restful model: :document,
90
- actions: [:index, :show, :destroy]
91
- end
65
+ def test_have_all_but_except_actions
66
+ subject = ExceptActionsController.new
92
67
 
93
- subject = HandPickActionsController.new
68
+ assert_respond_to subject, :index
69
+ assert_respond_to subject, :show
70
+ refute_respond_to subject, :eddef
71
+ refute_respond_to subject, :update
72
+ assert_respond_to subject, :new
73
+ assert_respond_to subject, :create
74
+ refute_respond_to subject, :destroy
75
+ end
94
76
 
95
- subject.must_respond_to :index
96
- subject.must_respond_to :show
97
- subject.must_respond_to :destroy
98
- subject.wont_respond_to :edit
99
- subject.wont_respond_to :update
100
- subject.wont_respond_to :new
101
- subject.wont_respond_to :create
77
+ def test_have_listed_actions_but_except_actions
78
+ subject = HandPickWdefhExceptionActionsController.new
79
+
80
+ assert_respond_to subject, :index
81
+ assert_respond_to subject, :show
82
+ refute_respond_to subject, :eddef
83
+ refute_respond_to subject, :update
84
+ refute_respond_to subject, :new
85
+ refute_respond_to subject, :create
86
+ refute_respond_to subject, :destroy
102
87
  end
103
88
 
104
- it 'have invalid actions listed' do
105
- ##
106
- # Controller class for tests
107
- class InvalidActionsController < BaseController
108
- respond_to :html
109
- restful model: :document,
110
- actions: [:indice, :show, :eliminar,
111
- except: [:edit, :actualizar, :destroy]]
112
- end
89
+ def test_have_listed_actions
90
+ subject = HandPickActionsController.new
91
+
92
+ assert_respond_to subject, :index
93
+ assert_respond_to subject, :show
94
+ assert_respond_to subject, :destroy
95
+ refute_respond_to subject, :eddef
96
+ refute_respond_to subject, :update
97
+ refute_respond_to subject, :new
98
+ refute_respond_to subject, :create
99
+ end
113
100
 
101
+ def test_have_invalid_actions_listed
114
102
  subject = InvalidActionsController.new
115
103
 
116
- subject.wont_respond_to :index
117
- subject.must_respond_to :show
118
- subject.wont_respond_to :edit
119
- subject.wont_respond_to :update
120
- subject.wont_respond_to :new
121
- subject.wont_respond_to :create
122
- subject.wont_respond_to :destroy
104
+ refute_respond_to subject, :index
105
+ assert_respond_to subject, :show
106
+ refute_respond_to subject, :eddef
107
+ refute_respond_to subject, :update
108
+ refute_respond_to subject, :new
109
+ refute_respond_to subject, :create
110
+ refute_respond_to subject, :destroy
123
111
  end
124
112
  end