exposure 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/exposure/behaviors/building.rb +6 -0
- data/lib/exposure/behaviors/finding.rb +25 -0
- data/lib/exposure/options.rb +0 -31
- data/lib/exposure/patterns/resources.rb +1 -1
- data/spec/builders/builder_spec.rb +2 -2
- data/spec/builders/nested_builder_spec.rb +11 -6
- data/spec/factories/pirate_factory.rb +1 -1
- data/spec/factories/ship_factory.rb +4 -0
- data/spec/finders/nested_resources_finder_spec.rb +4 -4
- data/spec/resources_spec.rb +39 -34
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -11,6 +11,12 @@ module Exposure
|
|
11
11
|
self.const_get(:Builders)[name] = options[:with]
|
12
12
|
end
|
13
13
|
|
14
|
+
def build_default_builders!
|
15
|
+
nesting = @_exposed_resource_options[:nested] || []
|
16
|
+
nesting = nesting.clone
|
17
|
+
build_default_builder(self.resources_name, nesting)
|
18
|
+
end
|
19
|
+
|
14
20
|
def build_default_builder(member, nesting)
|
15
21
|
if nesting.any?
|
16
22
|
builders = self::const_set(:DefaultBuilders, {
|
@@ -22,6 +22,31 @@ module Exposure
|
|
22
22
|
self.const_get(:Finders)[name] = options[:with]
|
23
23
|
end
|
24
24
|
|
25
|
+
def build_default_finders!
|
26
|
+
if nesting = @_exposed_resource_options[:nested]
|
27
|
+
self.build_nested_default_finders!(nesting)
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
self.parent_model = self.resource_name.camelize.constantize
|
32
|
+
build_default_finders(self.resource_name, [])
|
33
|
+
self.member_nesting = [ [self.resource_name.to_sym] ]
|
34
|
+
self.collection_nesting = [ [self.resources_name.to_sym] ]
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_nested_default_finders!(nesting)
|
38
|
+
nesting = nesting.clone
|
39
|
+
self.parent_model = nesting.first.to_s.singularize.camelize.constantize
|
40
|
+
|
41
|
+
build_default_finders(self.resources_name, nesting)
|
42
|
+
|
43
|
+
nesting.collect! {|sym| [sym.to_s.singularize.to_sym, sym]}
|
44
|
+
|
45
|
+
|
46
|
+
self.member_nesting = nesting + [ [self.resource_name.to_sym, self.resources_name.to_sym] ]
|
47
|
+
self.collection_nesting = nesting + [ [self.resources_name.to_sym, self.resources_name.to_sym] ]
|
48
|
+
end
|
49
|
+
|
25
50
|
def build_default_finders(member, nesting) #:nodoc:
|
26
51
|
finders = self::const_set(:DefaultFinders, {
|
27
52
|
self.resource_name.intern => Proc.new { [:find, params[:id] ] },
|
data/lib/exposure/options.rb
CHANGED
@@ -21,37 +21,6 @@ module Exposure
|
|
21
21
|
self.resource_name = @_exposed_resource_name.to_s.singularize
|
22
22
|
self.resources_name = @_exposed_resource_name.to_s
|
23
23
|
end
|
24
|
-
|
25
|
-
def build_default_finders!
|
26
|
-
if nesting = @_exposed_resource_options[:nested]
|
27
|
-
self.build_nested_default_finders!(nesting)
|
28
|
-
return
|
29
|
-
end
|
30
|
-
|
31
|
-
self.parent_model = self.resource_name.camelize.constantize
|
32
|
-
build_default_finders(self.resource_name, [])
|
33
|
-
self.member_nesting = [ [self.resource_name.to_sym] ]
|
34
|
-
self.collection_nesting = [ [self.resources_name.to_sym] ]
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_default_builders!
|
38
|
-
nesting = @_exposed_resource_options[:nested] || []
|
39
|
-
nesting = nesting.clone
|
40
|
-
nesting.shift
|
41
|
-
build_default_builder(self.resources_name, nesting)
|
42
|
-
end
|
43
|
-
|
44
|
-
def build_nested_default_finders!(nesting)
|
45
|
-
nesting = nesting.clone
|
46
|
-
self.parent_model = nesting.shift.to_s.singularize.camelize.constantize
|
47
|
-
|
48
|
-
build_default_finders(self.resources_name, nesting)
|
49
|
-
|
50
|
-
nesting = nesting.collect! {|sym| [sym.to_s.singularize.to_sym, sym]}
|
51
|
-
|
52
|
-
self.member_nesting = nesting + [ [self.resource_name.to_sym] ]
|
53
|
-
self.collection_nesting = nesting + [ [self.resources_name.to_sym] ]
|
54
|
-
end
|
55
24
|
end
|
56
25
|
end
|
57
26
|
end
|
@@ -216,7 +216,7 @@ module Exposure
|
|
216
216
|
@resource = instance_variable_set("@#{resource_name}", call_finder_chain(parent_model, self.class.member_nesting, false))
|
217
217
|
end
|
218
218
|
|
219
|
-
def find_records
|
219
|
+
def find_records
|
220
220
|
@resources = instance_variable_set("@#{resources_name}", call_finder_chain(parent_model, self.class.collection_nesting, false))
|
221
221
|
end
|
222
222
|
|
@@ -40,14 +40,14 @@ describe "builders", :type => :controller do
|
|
40
40
|
should assign_to(:pirate).with(@pirate)
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "builds with a method name as symbol" do
|
44
44
|
PiratesController.build :pirate, :with => :build_pirate
|
45
45
|
post(:create, {:pirate => {}})
|
46
46
|
|
47
47
|
should assign_to(:pirate).with(@pirate)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "builds with a block" do
|
51
51
|
PiratesController.build :pirate do
|
52
52
|
Pirate.new(params[:pirate])
|
53
53
|
end
|
@@ -16,24 +16,29 @@ describe "nested builders", :type => :controller do
|
|
16
16
|
setup.call
|
17
17
|
controller_name :ships
|
18
18
|
Object.remove_class(ShipsController)
|
19
|
-
|
19
|
+
|
20
20
|
before(:each) do
|
21
21
|
setup.call
|
22
22
|
@controller = ShipsController.new
|
23
23
|
@request = ActionController::TestRequest.new
|
24
24
|
@response = ActionController::TestResponse.new
|
25
25
|
|
26
|
-
@pirate = Factory.create(:
|
27
|
-
|
26
|
+
@pirate = Factory.create(:pirate)
|
27
|
+
@ship = Factory.build(:ship)
|
28
|
+
Pirate.stub!(:find).and_return(@pirate)
|
29
|
+
@pirate.ships.stub!(:build).and_return(@ship)
|
30
|
+
|
31
|
+
|
32
|
+
params = {:pirate_id => @pirate.id, :ship => Factory.attributes_for(:ship)}
|
28
33
|
|
29
|
-
get(:new,
|
34
|
+
get(:new, params)
|
30
35
|
end
|
31
36
|
|
32
37
|
after(:each) do
|
33
38
|
Object.remove_class(ShipsController)
|
34
39
|
end
|
35
40
|
|
36
|
-
it { should assign_to(:ship) }
|
37
|
-
it { should assign_to(:resource) }
|
41
|
+
it { should assign_to(:ship).with(@ship) }
|
42
|
+
it { should assign_to(:resource).with(@ship) }
|
38
43
|
|
39
44
|
end
|
@@ -24,16 +24,16 @@ describe "nested finders", :type => :controller do
|
|
24
24
|
@response = ActionController::TestResponse.new
|
25
25
|
|
26
26
|
@pirate = Factory.create(:pirate_with_ships)
|
27
|
-
|
27
|
+
@ships = @pirate.ships
|
28
28
|
|
29
|
-
get(:index, {:pirate_id =>
|
29
|
+
get(:index, {:pirate_id => @pirate.id})
|
30
30
|
end
|
31
31
|
|
32
32
|
after(:each) do
|
33
33
|
Object.remove_class(ShipsController)
|
34
34
|
end
|
35
35
|
|
36
|
-
it { should assign_to(:ships)
|
37
|
-
it { should assign_to(:resources) }
|
36
|
+
it { should assign_to(:ships).with(@ships)}
|
37
|
+
it { should assign_to(:resources).with(@ships) }
|
38
38
|
|
39
39
|
end
|
data/spec/resources_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe "a REST patterned resource
|
3
|
+
describe "a REST patterned resource", :type => :controller do
|
4
4
|
setup = lambda {
|
5
5
|
class PiratesController < ActionController::Base
|
6
6
|
expose_many(:pirates)
|
@@ -28,7 +28,7 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'configuration' do
|
31
|
-
it "has a resource name of '
|
31
|
+
it "has a resource name of 'pirate'" do
|
32
32
|
@controller.send(:resource_name).should == 'pirate'
|
33
33
|
end
|
34
34
|
|
@@ -41,11 +41,13 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
41
41
|
|
42
42
|
describe 'index' do
|
43
43
|
before do
|
44
|
+
@pirates = [Factory.stub(:pirate)]
|
45
|
+
Pirate.should_receive(:find).with(:all).and_return(@pirates)
|
44
46
|
get :index
|
45
47
|
end
|
46
48
|
|
47
|
-
it { should assign_to(:pirates) }
|
48
|
-
it { should assign_to(:resources) }
|
49
|
+
it { should assign_to(:pirates).with(@pirates) }
|
50
|
+
it { should assign_to(:resources).with(@pirates) }
|
49
51
|
it { should respond_with(:success) }
|
50
52
|
it { should render_template(:index) }
|
51
53
|
it { should_not set_the_flash }
|
@@ -58,8 +60,8 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
58
60
|
get :show, {:id => 1}
|
59
61
|
end
|
60
62
|
|
61
|
-
it { should assign_to(:pirate) }
|
62
|
-
it { should assign_to(:resource) }
|
63
|
+
it { should assign_to(:pirate).with(@pirate) }
|
64
|
+
it { should assign_to(:resource).with(@pirate) }
|
63
65
|
it { should respond_with(:success) }
|
64
66
|
it { should render_template(:show) }
|
65
67
|
it { should_not set_the_flash }
|
@@ -82,11 +84,13 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
82
84
|
|
83
85
|
describe 'new' do
|
84
86
|
before(:each) do
|
87
|
+
@pirate = Factory.stub(:pirate)
|
88
|
+
Pirate.should_receive(:new).and_return(@pirate)
|
85
89
|
get :new
|
86
90
|
end
|
87
91
|
|
88
|
-
it { should assign_to(:pirate) }
|
89
|
-
it { should assign_to(:resource) }
|
92
|
+
it { should assign_to(:pirate).with(@pirate) }
|
93
|
+
it { should assign_to(:resource).with(@pirate) }
|
90
94
|
it { should respond_with(:success) }
|
91
95
|
it { should render_template(:new) }
|
92
96
|
it { should_not set_the_flash }
|
@@ -99,14 +103,14 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
99
103
|
params = {
|
100
104
|
:pirate => {}
|
101
105
|
}
|
102
|
-
|
103
|
-
Pirate.should_receive(:new).with(params[:pirate]).and_return(
|
104
|
-
|
106
|
+
@pirate = Factory.build(:pirate)
|
107
|
+
Pirate.should_receive(:new).with(params[:pirate]).and_return(@pirate)
|
108
|
+
@pirate.should_receive(:save).and_return(true)
|
105
109
|
post(:create, params)
|
106
110
|
end
|
107
111
|
|
108
|
-
it { should assign_to(:pirate) }
|
109
|
-
it { should assign_to(:resource) }
|
112
|
+
it { should assign_to(:pirate).with(@pirate) }
|
113
|
+
it { should assign_to(:resource).with(@pirate) }
|
110
114
|
it { should respond_with(:redirect).to(:index) }
|
111
115
|
it { should set_the_flash.to('Pirate successfully created') }
|
112
116
|
end
|
@@ -116,14 +120,14 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
116
120
|
params = {
|
117
121
|
:pirate => {}
|
118
122
|
}
|
119
|
-
|
120
|
-
Pirate.should_receive(:new).with(params[:pirate]).and_return(
|
121
|
-
|
123
|
+
@pirate = Factory.build(:pirate)
|
124
|
+
Pirate.should_receive(:new).with(params[:pirate]).and_return(@pirate)
|
125
|
+
@pirate.should_receive(:save).and_return(false)
|
122
126
|
post(:create, params)
|
123
127
|
end
|
124
128
|
|
125
|
-
it { should assign_to(:pirate) }
|
126
|
-
it { should assign_to(:resource) }
|
129
|
+
it { should assign_to(:pirate).with(@pirate) }
|
130
|
+
it { should assign_to(:resource).with(@pirate) }
|
127
131
|
it { should respond_with(:success) }
|
128
132
|
it { should render_template(:new) }
|
129
133
|
it { should_not set_the_flash }
|
@@ -133,12 +137,13 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
133
137
|
describe 'edit' do
|
134
138
|
describe 'with found resource' do
|
135
139
|
before(:each) do
|
136
|
-
|
140
|
+
@pirate = Factory.stub(:pirate)
|
141
|
+
Pirate.should_receive(:find).with('1').and_return(@pirate)
|
137
142
|
get :edit, {:id => 1}
|
138
143
|
end
|
139
144
|
|
140
|
-
it { should assign_to(:pirate) }
|
141
|
-
it { should assign_to(:resource) }
|
145
|
+
it { should assign_to(:pirate).with(@pirate) }
|
146
|
+
it { should assign_to(:resource).with(@pirate) }
|
142
147
|
it { should respond_with(:success) }
|
143
148
|
it { should render_template(:edit) }
|
144
149
|
it { should_not set_the_flash }
|
@@ -166,14 +171,14 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
166
171
|
:id => 1,
|
167
172
|
:pirate => {}
|
168
173
|
}
|
169
|
-
|
170
|
-
Pirate.should_receive(:find).with("1").and_return(
|
171
|
-
|
174
|
+
@pirate = Factory.build(:pirate)
|
175
|
+
Pirate.should_receive(:find).with("1").and_return(@pirate)
|
176
|
+
@pirate.should_receive(:update_attributes).with(params[:pirate]).and_return(true)
|
172
177
|
put(:update, params)
|
173
178
|
end
|
174
179
|
|
175
|
-
it { should assign_to(:pirate) }
|
176
|
-
it { should assign_to(:resource) }
|
180
|
+
it { should assign_to(:pirate).with(@pirate) }
|
181
|
+
it { should assign_to(:resource).with(@pirate) }
|
177
182
|
it { should respond_with(:redirect).to(:show) }
|
178
183
|
it { should set_the_flash.to('Pirate successfully updated') }
|
179
184
|
|
@@ -185,14 +190,14 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
185
190
|
:id => 1,
|
186
191
|
:pirate => {}
|
187
192
|
}
|
188
|
-
|
189
|
-
Pirate.should_receive(:find).with("1").and_return(
|
190
|
-
|
193
|
+
@pirate = Factory.build(:pirate)
|
194
|
+
Pirate.should_receive(:find).with("1").and_return(@pirate)
|
195
|
+
@pirate.should_receive(:update_attributes).with(params[:pirate]).and_return(false)
|
191
196
|
put(:update, params)
|
192
197
|
end
|
193
198
|
|
194
|
-
it { should assign_to(:pirate) }
|
195
|
-
it { should assign_to(:resource) }
|
199
|
+
it { should assign_to(:pirate).with(@pirate) }
|
200
|
+
it { should assign_to(:resource).with(@pirate) }
|
196
201
|
it { should respond_with(:success) }
|
197
202
|
it { should render_template(:edit) }
|
198
203
|
it { should_not set_the_flash }
|
@@ -204,9 +209,9 @@ describe "a REST patterned resource of 'pirates'", :type => :controller do
|
|
204
209
|
params = {
|
205
210
|
:id => 1,
|
206
211
|
}
|
207
|
-
|
208
|
-
Pirate.should_receive(:find).with("1").and_return(
|
209
|
-
|
212
|
+
@pirate = Factory.build(:pirate)
|
213
|
+
Pirate.should_receive(:find).with("1").and_return(@pirate)
|
214
|
+
@pirate.should_receive(:destroy).and_return(true)
|
210
215
|
delete(:destroy, params)
|
211
216
|
end
|
212
217
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exposure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trek Glowacki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|