sferik-merb-admin 0.3.3 → 0.3.4
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.
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/app/controllers/main.rb +1 -1
- data/app/views/main/_has_one.html.erb +2 -1
- data/lib/merb-admin.rb +1 -1
- data/spec/requests/main_spec.rb +24 -38
- metadata +1 -1
data/README.markdown
CHANGED
@@ -14,7 +14,7 @@ At the command prompt, type:
|
|
14
14
|
|
15
15
|
In your app, add the following dependency to `config/dependencies.rb`:
|
16
16
|
|
17
|
-
dependency "sferik-merb-admin", "0.3.
|
17
|
+
dependency "sferik-merb-admin", "0.3.4", :require_as => "merb-admin"
|
18
18
|
dependency "dm-is-paginated", "0.0.1" # if you want pagination support
|
19
19
|
|
20
20
|
Add the following route to `config/router.rb`:
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
12
12
|
EMAIL = "sferik@gmail.com"
|
13
13
|
HOMEPAGE = "http://twitter.com/sferik"
|
14
14
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
15
|
-
GEM_VERSION = "0.3.
|
15
|
+
GEM_VERSION = "0.3.4"
|
16
16
|
|
17
17
|
spec = Gem::Specification.new do |s|
|
18
18
|
s.rubyforge_project = "merb"
|
data/app/controllers/main.rb
CHANGED
@@ -164,7 +164,7 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
164
164
|
def update_has_one_association(association, id)
|
165
165
|
model = MerbAdmin::AbstractModel.new(association[:child_model])
|
166
166
|
if object = model.find(id)
|
167
|
-
object.update_attributes(association[:child_key] => @object.id)
|
167
|
+
object.update_attributes(association[:child_key].first => @object.id)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
<%
|
2
|
+
selected = MerbAdmin::AbstractModel.new(association[:child_model]).find_all(association[:child_key].first => @object.id).first
|
2
3
|
required = false
|
3
4
|
@properties.each do |property|
|
4
5
|
next unless property[:name] == association[:child_key].first
|
@@ -16,7 +17,7 @@ end
|
|
16
17
|
</ul>
|
17
18
|
<% end %>
|
18
19
|
<div>
|
19
|
-
<%= select(:name => "associations[#{association[:name]}][]", :id => association[:name], :collection => MerbAdmin::AbstractModel.new(association[:child_model]).find_all.map{|o| [o.id, object_title(o)]}.sort_by{|o| o[1]}, :include_blank => true, :selected =>
|
20
|
+
<%= select(:name => "associations[#{association[:name]}][]", :id => association[:name], :collection => MerbAdmin::AbstractModel.new(association[:child_model]).find_all.map{|o| [o.id, object_title(o)]}.sort_by{|o| o[1]}, :include_blank => true, :selected => selected ? selected.id.to_s : nil, :label => association[:pretty_name].capitalize) %>
|
20
21
|
<p class="help">
|
21
22
|
<%= required ? "Required." : "Optional." %>
|
22
23
|
</p>
|
data/lib/merb-admin.rb
CHANGED
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
23
23
|
|
24
24
|
# Slice metadata
|
25
25
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
26
|
-
self.version = "0.3.
|
26
|
+
self.version = "0.3.4"
|
27
27
|
self.author = "Erik Michaels-Ober"
|
28
28
|
|
29
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
data/spec/requests/main_spec.rb
CHANGED
@@ -4,11 +4,8 @@ given "a player exists" do
|
|
4
4
|
@player = Player.gen
|
5
5
|
end
|
6
6
|
|
7
|
-
given "
|
8
|
-
@
|
9
|
-
2.times do
|
10
|
-
@drafts << Draft.gen
|
11
|
-
end
|
7
|
+
given "a draft exists" do
|
8
|
+
@draft = Draft.gen
|
12
9
|
end
|
13
10
|
|
14
11
|
given "two players exist" do
|
@@ -25,12 +22,9 @@ given "three teams exist" do
|
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
given "a player exists and
|
25
|
+
given "a player exists and a draft exists" do
|
29
26
|
@player = Player.gen
|
30
|
-
@
|
31
|
-
2.times do
|
32
|
-
@drafts << Draft.gen
|
33
|
-
end
|
27
|
+
@draft = Draft.gen
|
34
28
|
end
|
35
29
|
|
36
30
|
given "a player exists and three teams exist" do
|
@@ -109,11 +103,11 @@ describe "MerbAdmin" do
|
|
109
103
|
@response.should be_successful
|
110
104
|
end
|
111
105
|
|
112
|
-
it "should contain correct
|
106
|
+
it "should contain a correct result" do
|
113
107
|
@response.body.should contain("Jackie Robinson")
|
114
108
|
end
|
115
109
|
|
116
|
-
it "should not contain incorrect
|
110
|
+
it "should not contain an incorrect result" do
|
117
111
|
@response.body.should_not contain("Sandy Koufax")
|
118
112
|
end
|
119
113
|
end
|
@@ -161,11 +155,11 @@ describe "MerbAdmin" do
|
|
161
155
|
@response.should be_successful
|
162
156
|
end
|
163
157
|
|
164
|
-
it "should contain correct
|
158
|
+
it "should contain a correct result" do
|
165
159
|
@response.body.should contain("Jackie Robinson")
|
166
160
|
end
|
167
161
|
|
168
|
-
it "should not contain incorrect
|
162
|
+
it "should not contain an incorrect result" do
|
169
163
|
@response.body.should_not contain("David Wright")
|
170
164
|
end
|
171
165
|
end
|
@@ -181,11 +175,11 @@ describe "MerbAdmin" do
|
|
181
175
|
@response.should be_successful
|
182
176
|
end
|
183
177
|
|
184
|
-
it "should contain correct
|
178
|
+
it "should contain a correct result" do
|
185
179
|
@response.body.should contain("Jackie Robinson")
|
186
180
|
end
|
187
181
|
|
188
|
-
it "should not contain incorrect
|
182
|
+
it "should not contain an incorrect result" do
|
189
183
|
@response.body.should_not contain("Dottie Hinson")
|
190
184
|
end
|
191
185
|
end
|
@@ -280,7 +274,7 @@ describe "MerbAdmin" do
|
|
280
274
|
end
|
281
275
|
end
|
282
276
|
|
283
|
-
describe "new with has-one association", :given => "
|
277
|
+
describe "new with has-one association", :given => "a draft exists" do
|
284
278
|
before(:each) do
|
285
279
|
@response = request(url(:admin_new, :model_name => "player"))
|
286
280
|
end
|
@@ -314,7 +308,7 @@ describe "MerbAdmin" do
|
|
314
308
|
end
|
315
309
|
end
|
316
310
|
|
317
|
-
describe "edit with has-one association", :given => "a player exists and
|
311
|
+
describe "edit with has-one association", :given => "a player exists and a draft exists" do
|
318
312
|
before(:each) do
|
319
313
|
@response = request(url(:admin_edit, :model_name => "player", :id => @player.id))
|
320
314
|
end
|
@@ -387,21 +381,17 @@ describe "MerbAdmin" do
|
|
387
381
|
end
|
388
382
|
end
|
389
383
|
|
390
|
-
describe "create with has-one association", :given => "
|
384
|
+
describe "create with has-one association", :given => "a draft exists" do
|
391
385
|
before(:each) do
|
392
|
-
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => :second, :sex => :male}, :associations => {:draft => @
|
386
|
+
@response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => :second, :sex => :male}, :associations => {:draft => @draft.id}})
|
393
387
|
end
|
394
388
|
|
395
389
|
it "should create a new object" do
|
396
390
|
Player.first.should_not be_nil
|
397
391
|
end
|
398
392
|
|
399
|
-
it "should
|
400
|
-
Player.first.draft.should == @
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should not include incorrect associations" do
|
404
|
-
Player.first.draft.should_not == @drafts[1]
|
393
|
+
it "should be associated with the correct object" do
|
394
|
+
Player.first.draft.should == @draft
|
405
395
|
end
|
406
396
|
end
|
407
397
|
|
@@ -414,12 +404,12 @@ describe "MerbAdmin" do
|
|
414
404
|
League.first.should_not be_nil
|
415
405
|
end
|
416
406
|
|
417
|
-
it "should
|
407
|
+
it "should be associated with the correct objects" do
|
418
408
|
League.first.teams.should include(@teams[0])
|
419
409
|
League.first.teams.should include(@teams[1])
|
420
410
|
end
|
421
411
|
|
422
|
-
it "should not
|
412
|
+
it "should be not associated with an incorrect object" do
|
423
413
|
League.first.teams.should_not include(@teams[2])
|
424
414
|
end
|
425
415
|
end
|
@@ -476,21 +466,17 @@ describe "MerbAdmin" do
|
|
476
466
|
end
|
477
467
|
end
|
478
468
|
|
479
|
-
describe "update with has-one association", :given => "a player exists and
|
469
|
+
describe "update with has-one association", :given => "a player exists and a draft exists" do
|
480
470
|
before(:each) do
|
481
|
-
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => :second, :sex => :male}, :associations => {:draft => @
|
471
|
+
@response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => :second, :sex => :male}, :associations => {:draft => @draft.id}})
|
482
472
|
end
|
483
473
|
|
484
474
|
it "should update an object that already exists" do
|
485
475
|
Player.first(:id => @player.id).name.should eql("Jackie Robinson")
|
486
476
|
end
|
487
477
|
|
488
|
-
it "should
|
489
|
-
Player.first.draft.should == @
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should not include incorrect associations" do
|
493
|
-
Player.first.draft.should_not == @drafts[1]
|
478
|
+
it "should be associated with the correct object" do
|
479
|
+
Player.first.draft.should == @draft
|
494
480
|
end
|
495
481
|
end
|
496
482
|
|
@@ -503,12 +489,12 @@ describe "MerbAdmin" do
|
|
503
489
|
League.first(:id => @league.id).name.should eql("National League")
|
504
490
|
end
|
505
491
|
|
506
|
-
it "should
|
492
|
+
it "should be associated with the correct objects" do
|
507
493
|
League.first.teams.should include(@teams[0])
|
508
494
|
League.first.teams.should include(@teams[1])
|
509
495
|
end
|
510
496
|
|
511
|
-
it "should not
|
497
|
+
it "should not be associated with an incorrect object" do
|
512
498
|
League.first.teams.should_not include(@teams[2])
|
513
499
|
end
|
514
500
|
end
|