basic_assumption 0.3.11 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +7 -0
- data/README.rdoc +61 -18
- data/lib/basic_assumption/default_assumption/base.rb +1 -1
- data/lib/basic_assumption/default_assumption/cautious_rails.rb +9 -0
- data/lib/basic_assumption/default_assumption/rails.rb +19 -6
- data/lib/basic_assumption/default_assumption/restful_rails.rb +10 -1
- data/lib/basic_assumption/rspec.rb +13 -0
- data/lib/basic_assumption/version.rb +1 -1
- data/lib/basic_assumption.rb +3 -3
- data/spec/lib/basic_assumption/default_assumption/cautious_rails_spec.rb +10 -3
- data/spec/lib/basic_assumption/default_assumption/rails_spec.rb +9 -2
- data/spec/lib/basic_assumption/default_assumption/restful_rails_spec.rb +21 -21
- data/spec/lib/basic_assumption_spec.rb +12 -2
- data/spec/spec_helper.rb +2 -0
- metadata +26 -37
data/HISTORY.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.4.0 / 2010-07-16
|
2
|
+
* Feature Addition
|
3
|
+
* Add simple rspec matcher
|
4
|
+
* Default assumptions can now be passed a context hash from #assume
|
5
|
+
* Rails defaults support an :as option in the context that will specify a model name different from the name passed to #assume
|
6
|
+
* Test Enhancement
|
7
|
+
* Development dependencies now managed with Bundler
|
1
8
|
== 0.3.11 / 2010-06-28
|
2
9
|
* Test Enhancement
|
3
10
|
* Cucumber features covering most of the basic functionality within a Rails 2.3 app (not included in gem)
|
data/README.rdoc
CHANGED
@@ -116,6 +116,20 @@ In this case, the +show_mine+ action overrides the value of widget so that it
|
|
116
116
|
may reuse the view template for the regular +show+ action. Overriding the
|
117
117
|
assumed resource should be the exception, not the rule.
|
118
118
|
|
119
|
+
==== Using an alternative model name
|
120
|
+
|
121
|
+
BasicAssumption tends to assume a lot of things, including the name of the model
|
122
|
+
class a default +assume+ call should try to load. If you want the name given to
|
123
|
+
+assume+ to differ from the name of the model, use the optional context hash to
|
124
|
+
pass an +as+ option:
|
125
|
+
|
126
|
+
class WidgetController < ApplicationController
|
127
|
+
assume :sprocket, :as => :widget
|
128
|
+
end
|
129
|
+
|
130
|
+
This will create a +sprocket+ method in your actions and views that will use the
|
131
|
+
Widget model for its lookup.
|
132
|
+
|
119
133
|
For more details on how BasicAssumption is wired into your Rails
|
120
134
|
app, please see the BasicAssumption::Railtie documentation.
|
121
135
|
|
@@ -207,6 +221,29 @@ calls as well.
|
|
207
221
|
|
208
222
|
assume :luigi, :using => :luigi_strategy
|
209
223
|
|
224
|
+
=== Passing context to defaults
|
225
|
+
|
226
|
+
BasicAssumption supports passing a hash of arbitrary context information when
|
227
|
+
+assume+ is called without a block. This allows configuration or optional data
|
228
|
+
to be made available in default blocks. The built-in Rails defaults use this
|
229
|
+
to override the name of the model that is being worked with via the :as option.
|
230
|
+
|
231
|
+
Here is an example:
|
232
|
+
|
233
|
+
class Widget < ActiveRecord::Base
|
234
|
+
named_scope :shiny, :conditions => {:glossy => true}
|
235
|
+
end
|
236
|
+
|
237
|
+
class WidgetController < ActionController::Base
|
238
|
+
default_assumption do |name, context|
|
239
|
+
name.to_s.classify.constantize.send(context[:type]).find(params[:id])
|
240
|
+
end
|
241
|
+
|
242
|
+
assume :widget, :type => :shiny
|
243
|
+
end
|
244
|
+
|
245
|
+
In this case, the lookups for +widget+ are scoped to ones that are shiny.
|
246
|
+
|
210
247
|
=== In Rails
|
211
248
|
|
212
249
|
In Rails, a useful default is already active out of the box. It attempts to
|
@@ -216,7 +253,7 @@ following two constructs would be equivalent in your controllers:
|
|
216
253
|
|
217
254
|
assume(:film) { Film.find(params[:film_id] || params[:id]) }
|
218
255
|
# The above line is exactly the same as:
|
219
|
-
assume
|
256
|
+
assume :film
|
220
257
|
|
221
258
|
Please see +Rails+ for implementation details . Because finding on :id
|
222
259
|
could be considered dangerous, there is another default available for use,
|
@@ -259,7 +296,7 @@ that is active by default within Rails.
|
|
259
296
|
|
260
297
|
def block
|
261
298
|
klass = self.class
|
262
|
-
Proc.new do |name|
|
299
|
+
Proc.new do |name, context|
|
263
300
|
klass.new(name, params).result
|
264
301
|
end
|
265
302
|
end
|
@@ -277,10 +314,11 @@ that is active by default within Rails.
|
|
277
314
|
end
|
278
315
|
|
279
316
|
The only method that BasicAssumption depends on in the interface of custom
|
280
|
-
default classes is the +block+ method.
|
317
|
+
default classes is the +block+ method. It should return a Proc that accepts a
|
318
|
+
a symbol/string name and a context hash. Note the hoops that have to be jumped
|
281
319
|
through inside the implementation of +block+ in this example. Keep in mind the
|
282
320
|
implications of evaluating the +Proc+ returned by +block+ using +instance_eval+
|
283
|
-
(or +instance_exec+).
|
321
|
+
(or +instance_exec+), and enclose any data the block may need at runtime.
|
284
322
|
|
285
323
|
== Configuration
|
286
324
|
|
@@ -320,24 +358,29 @@ If you're unfamiliar with why this is being done, take a look
|
|
320
358
|
{here for a start}[http://tomayko.com/writings/require-rubygems-antipattern].
|
321
359
|
|
322
360
|
There is also a Cucumber suite that can be run to check BasicAssumption against
|
323
|
-
an actual Rails app.
|
324
|
-
dependencies for the development environment, you will need to ensure at least
|
325
|
-
the following gems are installed:
|
326
|
-
|
327
|
-
* aruba (0.1.9)
|
328
|
-
* capybara (0.3.8)
|
329
|
-
* cucumber (0.8.3)
|
330
|
-
* cucumber-rails (0.3.2)
|
331
|
-
* database_cleaner (0.5.2)
|
332
|
-
* rails (2.3.5)
|
333
|
-
* rake (0.8.7)
|
334
|
-
* sqlite3-ruby (1.3.0)
|
335
|
-
* will_paginate (2.3.14)
|
361
|
+
an actual Rails app.
|
336
362
|
|
337
363
|
There is an .rvmrc file in the repository that will require a basic_assumption
|
338
364
|
gemset if you're using RVM, which will help to manage the gem dependencies.
|
339
365
|
|
340
|
-
|
366
|
+
The test suites are dependent on the Bundler gem. Ensure that it is installed
|
367
|
+
with:
|
368
|
+
|
369
|
+
gem install bundler
|
370
|
+
|
371
|
+
To run the Cucumber and spec suites for the first time, use these Rake tasks:
|
372
|
+
|
373
|
+
rake init
|
374
|
+
rake
|
375
|
+
|
376
|
+
Note that the +init+ task will +bundle+ +install+ the development dependencies,
|
377
|
+
which includes +basic_assumption+ itself. Using the RVM gemset is recommended.
|
378
|
+
|
379
|
+
This will create an example Rails app in ./tmp and run the suites against it.
|
380
|
+
Use +rake+ +spec+ to run BasicAssumption's specs, +rake+ +cucumber+ to run the
|
381
|
+
cukes, or +rake+ to run specs and cukes.
|
382
|
+
|
383
|
+
Feel free to fork away and send back pull requests, including specs! Thanks.
|
341
384
|
|
342
385
|
== But should I use it?
|
343
386
|
|
@@ -17,6 +17,15 @@ module BasicAssumption
|
|
17
17
|
# class WidgetController < ActionController::Base
|
18
18
|
# assume(:widget) { Widget.find(params[:widget_id]) }
|
19
19
|
# end
|
20
|
+
#
|
21
|
+
# It is possible to specify an alternative model name:
|
22
|
+
#
|
23
|
+
# class WidgetController < ApplicationController
|
24
|
+
# assume :sprocket, :as => :widget
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# This will create a +sprocket+ method in your actions and view
|
28
|
+
# that will use the Widget model for its lookup.
|
20
29
|
def block
|
21
30
|
super
|
22
31
|
end
|
@@ -2,10 +2,10 @@ module BasicAssumption
|
|
2
2
|
module DefaultAssumption
|
3
3
|
# Custom default behavior in the context of Rails.
|
4
4
|
class Rails < BasicAssumption::DefaultAssumption::Base
|
5
|
-
attr_reader :name, :params #:nodoc:
|
5
|
+
attr_reader :name, :context, :params #:nodoc:
|
6
6
|
|
7
|
-
def initialize(name=nil, params={}) #:nodoc:
|
8
|
-
@name, @params = name.to_s, params
|
7
|
+
def initialize(name=nil, context={}, params={}) #:nodoc:
|
8
|
+
@name, @context, @params = name.to_s, context, params
|
9
9
|
end
|
10
10
|
# Returns a block that will attempt to find an instance of
|
11
11
|
# an ActiveRecord model based on the name that was given to
|
@@ -19,10 +19,19 @@ module BasicAssumption
|
|
19
19
|
# class WidgetController < ActionController::Base
|
20
20
|
# assume(:widget) { Widget.find(params[:widget_id] || params[:id]) }
|
21
21
|
# end
|
22
|
+
#
|
23
|
+
# It is possible to specify an alternative model name:
|
24
|
+
#
|
25
|
+
# class WidgetController < ApplicationController
|
26
|
+
# assume :sprocket, :as => :widget
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# This will create a +sprocket+ method in your actions and view
|
30
|
+
# that will use the Widget model for its lookup.
|
22
31
|
def block
|
23
32
|
klass = self.class
|
24
|
-
Proc.new do |name|
|
25
|
-
klass.new(name, params).result
|
33
|
+
Proc.new do |name, context|
|
34
|
+
klass.new(name, context, params).result
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
@@ -36,7 +45,11 @@ module BasicAssumption
|
|
36
45
|
end
|
37
46
|
|
38
47
|
def model_class #:nodoc:
|
39
|
-
@model_class ||=
|
48
|
+
@model_class ||= model_name.classify.constantize
|
49
|
+
end
|
50
|
+
|
51
|
+
def model_name #:nodoc:
|
52
|
+
context[:as] ? context[:as].to_s : name
|
40
53
|
end
|
41
54
|
end
|
42
55
|
end
|
@@ -9,7 +9,7 @@ module BasicAssumption
|
|
9
9
|
:per_page,
|
10
10
|
:resource_attributes #:nodoc:
|
11
11
|
|
12
|
-
def initialize(name = nil, params = {}) #:nodoc:
|
12
|
+
def initialize(name = nil, context={}, params = {}) #:nodoc:
|
13
13
|
super
|
14
14
|
@action = params['action']
|
15
15
|
@resource_attributes = params[singular_name]
|
@@ -47,6 +47,15 @@ module BasicAssumption
|
|
47
47
|
# find all records of the model type paginated based on the +page+
|
48
48
|
# value in params and also a +per_page+ value. Otherwise, it returns all
|
49
49
|
# # records for the model.
|
50
|
+
#
|
51
|
+
# It is possible to specify an alternative model name:
|
52
|
+
#
|
53
|
+
# class WidgetController < ApplicationController
|
54
|
+
# assume :sprocket, :as => :widget
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# This will create a +sprocket+ method in your actions and view
|
58
|
+
# that will use the Widget model for its lookup.
|
50
59
|
def block
|
51
60
|
super
|
52
61
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Spec::Matchers.define :assume do |assumption|
|
2
|
+
match do |controller|
|
3
|
+
controller.respond_to?(assumption) && controller.respond_to?(:"#{assumption}=")
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message_for_should do |controller|
|
7
|
+
"expected #{controller.class.name} to assume '#{assumption}'"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should_not do |controller|
|
11
|
+
"expected #{controller.class.name} not to assume '#{assumption}'"
|
12
|
+
end
|
13
|
+
end
|
data/lib/basic_assumption.rb
CHANGED
@@ -61,15 +61,15 @@ module BasicAssumption
|
|
61
61
|
# +assume+ will also create an attribute writer method that will allow the
|
62
62
|
# value returned by the instance method (the reader, from this point of view)
|
63
63
|
# to be overriden.
|
64
|
-
def assume(name,
|
64
|
+
def assume(name, context={}, &block)
|
65
65
|
define_method(name) do
|
66
66
|
@basic_assumptions ||= {}
|
67
67
|
@basic_assumptions[name] ||= if block_given?
|
68
68
|
instance_eval(&block)
|
69
69
|
else
|
70
|
-
which =
|
70
|
+
which = context.delete(:using) || self.class
|
71
71
|
block = DefaultAssumption.resolve(which)
|
72
|
-
instance_exec(name, &block)
|
72
|
+
instance_exec(name, context, &block)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
define_method("#{name}=") do |value|
|
@@ -17,17 +17,24 @@ describe BasicAssumption::DefaultAssumption::CautiousRails do
|
|
17
17
|
|
18
18
|
it "looks for a params[model_id] in its calling context" do
|
19
19
|
params.should_receive(:[]).with('model_id').and_return(nil)
|
20
|
-
default.block.call(:model)
|
20
|
+
default.block.call(:model, {})
|
21
21
|
end
|
22
22
|
|
23
23
|
it "does not look for params[id] in its calling context" do
|
24
24
|
params.should_receive(:[]).with('id').never
|
25
|
-
default.block.call(:model)
|
25
|
+
default.block.call(:model, {})
|
26
26
|
end
|
27
27
|
|
28
28
|
it "attempts to find a model instance based off the given name" do
|
29
29
|
Model.should_receive(:find).with(42).and_return(:model)
|
30
|
-
default.block.call(:model).should eql(:model)
|
30
|
+
default.block.call(:model, {}).should eql(:model)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when passed an alternative model name" do
|
34
|
+
it "finds a model instance based off the alternative name" do
|
35
|
+
Model.should_receive(:find).with(42).and_return(:model)
|
36
|
+
default.block.call(:my_model, {:as => :model}).should eql(:model)
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
@@ -18,12 +18,19 @@ describe BasicAssumption::DefaultAssumption::Rails do
|
|
18
18
|
it "looks for a params[model_id] and params[id] in its calling context" do
|
19
19
|
params.should_receive(:[]).with('model_id').and_return(nil)
|
20
20
|
params.should_receive(:[]).with('id')
|
21
|
-
default.block.call(:model)
|
21
|
+
default.block.call(:model, {})
|
22
22
|
end
|
23
23
|
|
24
24
|
it "attempts to find a model instance based off the given name" do
|
25
25
|
Model.should_receive(:find).with(42).and_return(:model)
|
26
|
-
default.block.call(:model).should eql(:model)
|
26
|
+
default.block.call(:model, {}).should eql(:model)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when passed an alternative model name" do
|
30
|
+
it "finds a model instance based off the alternative name" do
|
31
|
+
Model.should_receive(:find).with(42).and_return(:model)
|
32
|
+
default.block.call(:my_model, {:as => :model}).should eql(:model)
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
describe BasicAssumption::DefaultAssumption::RestfulRails do
|
15
15
|
|
16
16
|
context "#block" do
|
17
|
-
let(:default) { BasicAssumption::DefaultAssumption::RestfulRails.new(:model, params) }
|
17
|
+
let(:default) { BasicAssumption::DefaultAssumption::RestfulRails.new(:model, {}, params) }
|
18
18
|
|
19
19
|
before(:each) do
|
20
20
|
Model.stub!(:find)
|
@@ -35,12 +35,12 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
35
35
|
context "when :page exists in the request params" do
|
36
36
|
before { params[:page] = '5' }
|
37
37
|
it "finds all the records of the model class" do
|
38
|
-
default.block.call(name)
|
38
|
+
default.block.call(name, {})
|
39
39
|
end
|
40
40
|
end
|
41
41
|
context "when :page does not exist in the request params" do
|
42
42
|
it "finds all the records of the model class" do
|
43
|
-
default.block.call(name)
|
43
|
+
default.block.call(name, {})
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -52,12 +52,12 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
52
52
|
context "when :page exists in the request params" do
|
53
53
|
before { params[:page] = '5' }
|
54
54
|
it "finds all the records of the model class" do
|
55
|
-
default.block.call(name)
|
55
|
+
default.block.call(name, {})
|
56
56
|
end
|
57
57
|
end
|
58
58
|
context "when :page does not exist in the request params" do
|
59
59
|
it "finds all the records of the model class" do
|
60
|
-
default.block.call(name)
|
60
|
+
default.block.call(name, {})
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -77,26 +77,26 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
77
77
|
before { params[:page] = '5' }
|
78
78
|
it "paginates the records of the model class" do
|
79
79
|
Model.should_receive(:paginate)
|
80
|
-
default.block.call(name)
|
80
|
+
default.block.call(name, {})
|
81
81
|
end
|
82
82
|
context "when :per_page exists in the request params" do
|
83
83
|
it "paginates using :page and :per_page from the params" do
|
84
84
|
params[:per_page] = '10'
|
85
85
|
Model.should_receive(:paginate).with(:page => '5', :per_page => '10')
|
86
|
-
default.block.call(name)
|
86
|
+
default.block.call(name, {})
|
87
87
|
end
|
88
88
|
end
|
89
89
|
context "when :per_page does not exist in the request params" do
|
90
90
|
it "paginates using :page from the params" do
|
91
91
|
Model.should_receive(:paginate).with(:page => '5', :per_page => nil)
|
92
|
-
default.block.call(name)
|
92
|
+
default.block.call(name, {})
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
context "when :page does not exist in the request params" do
|
97
97
|
it "finds all the records of the model class" do
|
98
98
|
Model.should_receive(:all)
|
99
|
-
default.block.call(name)
|
99
|
+
default.block.call(name, {})
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -109,26 +109,26 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
109
109
|
before { params[:page] = '5' }
|
110
110
|
it "paginates the records of the model class" do
|
111
111
|
Model.should_receive(:paginate)
|
112
|
-
default.block.call(name)
|
112
|
+
default.block.call(name, {})
|
113
113
|
end
|
114
114
|
context "when :per_page exists in the request params" do
|
115
115
|
it "paginates using :page and :per_page from the params" do
|
116
116
|
params[:per_page] = '10'
|
117
117
|
Model.should_receive(:paginate).with(:page => '5', :per_page => '10')
|
118
|
-
default.block.call(name)
|
118
|
+
default.block.call(name, {})
|
119
119
|
end
|
120
120
|
end
|
121
121
|
context "when :per_page does not exist in the request params" do
|
122
122
|
it "paginates using :page from the params" do
|
123
123
|
Model.should_receive(:paginate).with(:page => '5', :per_page => nil)
|
124
|
-
default.block.call(name)
|
124
|
+
default.block.call(name, {})
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
128
128
|
context "when :page does not exist in the request params" do
|
129
129
|
it "finds all the records of the model class" do
|
130
130
|
Model.should_receive(:all)
|
131
|
-
default.block.call(name)
|
131
|
+
default.block.call(name, {})
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
@@ -145,14 +145,14 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
145
145
|
before { params['id'] = 1 }
|
146
146
|
it "attempts to find a model instance based off the given name" do
|
147
147
|
Model.should_receive(:find).with(1).and_return(name)
|
148
|
-
default.block.call(name).should eql(name)
|
148
|
+
default.block.call(name, {}).should eql(name)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
context "and there is no id in params" do
|
152
152
|
before { params['model'] = :initializers }
|
153
153
|
it "creates a new model instance and passes in appropriate params" do
|
154
154
|
Model.should_receive(:new).with(:initializers).and_return(name)
|
155
|
-
default.block.call(name).should eql(name)
|
155
|
+
default.block.call(name, {}).should eql(name)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -162,7 +162,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
162
162
|
|
163
163
|
it "attempts to find a model instance based off the given name" do
|
164
164
|
Model.should_receive(:find).with(42).and_return(name)
|
165
|
-
default.block.call(name).should eql(:model)
|
165
|
+
default.block.call(name, {}).should eql(:model)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -171,7 +171,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
171
171
|
|
172
172
|
it "attempts to find a model instance based off the given name" do
|
173
173
|
Model.should_receive(:find).with(42).and_return(name)
|
174
|
-
default.block.call(name).should eql(:model)
|
174
|
+
default.block.call(name, {}).should eql(:model)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -182,7 +182,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
182
182
|
|
183
183
|
it "attempts to find a model instance based off the given name" do
|
184
184
|
Model.should_receive(:find).with(42).and_return(name)
|
185
|
-
default.block.call(name).should eql(:model)
|
185
|
+
default.block.call(name, {}).should eql(:model)
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -191,7 +191,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
191
191
|
|
192
192
|
it "attempts to find a model instance based off the given name" do
|
193
193
|
Model.should_receive(:find).with(42).and_return(name)
|
194
|
-
default.block.call(name).should eql(:model)
|
194
|
+
default.block.call(name, {}).should eql(:model)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -204,7 +204,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
context "the model instance" do
|
207
|
-
subject { default.block.call(name) }
|
207
|
+
subject { default.block.call(name, {}) }
|
208
208
|
its(:age) { should be(27) }
|
209
209
|
its(:color) { should eql('blue') }
|
210
210
|
end
|
@@ -219,7 +219,7 @@ describe BasicAssumption::DefaultAssumption::RestfulRails do
|
|
219
219
|
end
|
220
220
|
|
221
221
|
context "the model instance" do
|
222
|
-
subject { default.block.call(name) }
|
222
|
+
subject { default.block.call(name, {}) }
|
223
223
|
its(:age) { should be(27) }
|
224
224
|
its(:color) { should eql('blue') }
|
225
225
|
end
|
@@ -51,6 +51,16 @@ describe BasicAssumption do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
context "when an arbitrary context hash is passed to #assume" do
|
55
|
+
it "passes the hash to the evaluated block" do
|
56
|
+
extender_class.class_eval do
|
57
|
+
default_assumption { |name, context| context}
|
58
|
+
assume :has_context, :with => :foo, :and => :bar
|
59
|
+
end
|
60
|
+
extender_instance.has_context.should == {:with => :foo, :and => :bar}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
54
64
|
context "when the default is overridden" do
|
55
65
|
it "returns the result of the overriding block" do
|
56
66
|
extender_class.class_eval do
|
@@ -70,7 +80,7 @@ describe BasicAssumption do
|
|
70
80
|
|
71
81
|
it "passes the name into the default block" do
|
72
82
|
extender_class.class_eval do
|
73
|
-
default_assumption { |name| name }
|
83
|
+
default_assumption { |name, context| name }
|
74
84
|
assume(:given_name)
|
75
85
|
end
|
76
86
|
extender_instance.given_name.should eql(:given_name)
|
@@ -152,7 +162,7 @@ describe BasicAssumption do
|
|
152
162
|
|
153
163
|
before(:all) do
|
154
164
|
application_controller.class_eval do
|
155
|
-
default_assumption { |name| "#{name}#{name}" }
|
165
|
+
default_assumption { |name, context| "#{name}#{name}" }
|
156
166
|
end
|
157
167
|
end
|
158
168
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_assumption
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Matt Yoho
|
@@ -14,51 +15,25 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-16 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
+
name: bundler
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
27
30
|
segments:
|
28
|
-
- 1
|
29
|
-
- 3
|
30
31
|
- 0
|
31
|
-
|
32
|
+
- 9
|
33
|
+
- 26
|
34
|
+
version: 0.9.26
|
32
35
|
type: :development
|
33
36
|
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: actionpack
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 2
|
43
|
-
- 3
|
44
|
-
- 5
|
45
|
-
version: 2.3.5
|
46
|
-
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: activesupport
|
50
|
-
prerelease: false
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 2
|
57
|
-
- 3
|
58
|
-
- 5
|
59
|
-
version: 2.3.5
|
60
|
-
type: :development
|
61
|
-
version_requirements: *id003
|
62
37
|
description: "\n Allows a simple declarative idiom for accessing resources in controllers and views\n via a well-defined interface that increases testability and reduces shared state.\n "
|
63
38
|
email: mby@mattyoho.com
|
64
39
|
executables: []
|
@@ -82,8 +57,18 @@ files:
|
|
82
57
|
- lib/basic_assumption/default_assumption/rails.rb
|
83
58
|
- lib/basic_assumption/default_assumption/restful_rails.rb
|
84
59
|
- lib/basic_assumption/rails.rb
|
60
|
+
- lib/basic_assumption/rspec.rb
|
85
61
|
- lib/basic_assumption/version.rb
|
86
62
|
- rails/init.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/lib/basic_assumption_spec.rb
|
65
|
+
- spec/lib/basic_assumption/configuration_spec.rb
|
66
|
+
- spec/lib/basic_assumption/default_assumption_spec.rb
|
67
|
+
- spec/lib/basic_assumption/default_assumption/base_spec.rb
|
68
|
+
- spec/lib/basic_assumption/default_assumption/cautious_rails_spec.rb
|
69
|
+
- spec/lib/basic_assumption/default_assumption/class_resolver_spec.rb
|
70
|
+
- spec/lib/basic_assumption/default_assumption/rails_spec.rb
|
71
|
+
- spec/lib/basic_assumption/default_assumption/restful_rails_spec.rb
|
87
72
|
has_rdoc: true
|
88
73
|
homepage: http://github.com/mattyoho/basic_assumption
|
89
74
|
licenses: []
|
@@ -94,23 +79,27 @@ rdoc_options:
|
|
94
79
|
require_paths:
|
95
80
|
- lib
|
96
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
97
83
|
requirements:
|
98
84
|
- - ">="
|
99
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
100
87
|
segments:
|
101
88
|
- 0
|
102
89
|
version: "0"
|
103
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
104
92
|
requirements:
|
105
93
|
- - ">="
|
106
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
107
96
|
segments:
|
108
97
|
- 0
|
109
98
|
version: "0"
|
110
99
|
requirements: []
|
111
100
|
|
112
101
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.7
|
114
103
|
signing_key:
|
115
104
|
specification_version: 3
|
116
105
|
summary: Allows a simple declarative idiom for accessing resources in controllers and views, cleaning up controller code and removing the need to explicitly reference instance variables inside views. Custom default behavior can be defined in a pluggable manner.
|