merb-admin 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/app/controllers/main.rb +4 -4
- data/lib/activerecord_support.rb +1 -1
- data/lib/merb-admin/slicetasks.rb +4 -3
- data/lib/merb-admin.rb +1 -1
- data/merb-admin.gemspec +2 -2
- data/spec/requests/main_spec.rb +214 -148
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
|
|
11
11
|
== Installation
|
12
12
|
$ gem install merb-admin -s http://gemcutter.org
|
13
13
|
In your app, add the following dependency to <tt>config/dependencies.rb</tt>:
|
14
|
-
dependency "merb-admin", "0.
|
14
|
+
dependency "merb-admin", "0.7.0"
|
15
15
|
Add the following route to <tt>config/router.rb</tt>:
|
16
16
|
add_slice(:merb_admin, :path_prefix => "admin")
|
17
17
|
Then, run the following rake task:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/app/controllers/main.rb
CHANGED
@@ -40,10 +40,6 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
40
40
|
render(:layout => 'form')
|
41
41
|
end
|
42
42
|
|
43
|
-
def edit
|
44
|
-
render(:layout => 'form')
|
45
|
-
end
|
46
|
-
|
47
43
|
def create
|
48
44
|
@object = @abstract_model.new(@attributes)
|
49
45
|
if @object.save && update_all_associations
|
@@ -53,6 +49,10 @@ class MerbAdmin::Main < MerbAdmin::Application
|
|
53
49
|
end
|
54
50
|
end
|
55
51
|
|
52
|
+
def edit
|
53
|
+
render(:layout => 'form')
|
54
|
+
end
|
55
|
+
|
56
56
|
def update
|
57
57
|
if @object.update_attributes(@attributes) && update_all_associations
|
58
58
|
redirect_on_success
|
data/lib/activerecord_support.rb
CHANGED
@@ -91,6 +91,8 @@ def load_data
|
|
91
91
|
return
|
92
92
|
end
|
93
93
|
|
94
|
+
require_models
|
95
|
+
|
94
96
|
puts "Loading current MLB leagues, divisions, teams, and players"
|
95
97
|
MLB::Team.all.each do |mlb_team|
|
96
98
|
unless league = MerbAdmin::AbstractModel.new("League").first(:conditions => ["name = ?", mlb_team.league])
|
@@ -136,9 +138,8 @@ def copy_migrations(orm = nil)
|
|
136
138
|
duplicated.each { |f| puts "! duplicated override as #{f}" }
|
137
139
|
end
|
138
140
|
|
139
|
-
def require_models
|
140
|
-
|
141
|
-
Dir.glob(File.dirname(__FILE__) / "models" / orm.to_s.downcase / Merb.glob_for(:model)).each do |model_filename|
|
141
|
+
def require_models
|
142
|
+
Dir.glob(Merb.dir_for(:model) / Merb.glob_for(:model)).each do |model_filename|
|
142
143
|
require model_filename
|
143
144
|
end
|
144
145
|
end
|
data/lib/merb-admin.rb
CHANGED
@@ -24,7 +24,7 @@ if defined?(Merb::Plugins)
|
|
24
24
|
|
25
25
|
# Slice metadata
|
26
26
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
27
|
-
self.version = "0.
|
27
|
+
self.version = "0.7.0"
|
28
28
|
self.author = "Erik Michaels-Ober"
|
29
29
|
|
30
30
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
data/merb-admin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{merb-admin}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Erik Michaels-Ober"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-28}
|
13
13
|
s.description = %q{MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.}
|
14
14
|
s.email = %q{sferik@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/requests/main_spec.rb
CHANGED
@@ -70,7 +70,7 @@ describe "MerbAdmin" do
|
|
70
70
|
|
71
71
|
describe "dashboard" do
|
72
72
|
before(:each) do
|
73
|
-
@response =
|
73
|
+
@response = visit(url(:merb_admin_dashboard))
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should respond sucessfully" do
|
@@ -85,7 +85,7 @@ describe "MerbAdmin" do
|
|
85
85
|
describe "dashboard with excluded models" do
|
86
86
|
before(:each) do
|
87
87
|
MerbAdmin[:excluded_models] = ["Player"]
|
88
|
-
@response =
|
88
|
+
@response = visit(url(:merb_admin_dashboard))
|
89
89
|
MerbAdmin[:excluded_models] = []
|
90
90
|
end
|
91
91
|
|
@@ -100,7 +100,7 @@ describe "MerbAdmin" do
|
|
100
100
|
|
101
101
|
describe "list" do
|
102
102
|
before(:each) do
|
103
|
-
@response =
|
103
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"))
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should respond sucessfully" do
|
@@ -124,7 +124,7 @@ describe "MerbAdmin" do
|
|
124
124
|
before(:each) do
|
125
125
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
126
126
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
127
|
-
@response =
|
127
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name")
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should respond sucessfully" do
|
@@ -140,7 +140,7 @@ describe "MerbAdmin" do
|
|
140
140
|
before(:each) do
|
141
141
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
142
142
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
143
|
-
@response =
|
143
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name", :sort_reverse => "true")
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should respond sucessfully" do
|
@@ -156,7 +156,7 @@ describe "MerbAdmin" do
|
|
156
156
|
before(:each) do
|
157
157
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
|
158
158
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
|
159
|
-
@response =
|
159
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Jackie Robinson")
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should respond sucessfully" do
|
@@ -178,7 +178,7 @@ describe "MerbAdmin" do
|
|
178
178
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
|
179
179
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
|
180
180
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
|
181
|
-
@response =
|
181
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Sandy Koufax", :filter => {:injured => "true"})
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should respond sucessfully" do
|
@@ -201,7 +201,7 @@ describe "MerbAdmin" do
|
|
201
201
|
before(:each) do
|
202
202
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :injured => true)
|
203
203
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :injured => false)
|
204
|
-
@response =
|
204
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:injured => "true"})
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should respond sucessfully" do
|
@@ -223,7 +223,7 @@ describe "MerbAdmin" do
|
|
223
223
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
|
224
224
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
|
225
225
|
MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
|
226
|
-
@response =
|
226
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:retired => "true", :injured => "true"})
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should respond sucessfully" do
|
@@ -243,7 +243,7 @@ describe "MerbAdmin" do
|
|
243
243
|
describe "list with 2 objects", :given => "two players exist" do
|
244
244
|
before(:each) do
|
245
245
|
MerbAdmin[:per_page] = 1
|
246
|
-
@response =
|
246
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"))
|
247
247
|
MerbAdmin[:per_page] = 100
|
248
248
|
end
|
249
249
|
|
@@ -259,7 +259,7 @@ describe "MerbAdmin" do
|
|
259
259
|
describe "list with 20 objects", :given => "twenty players exist" do
|
260
260
|
before(:each) do
|
261
261
|
MerbAdmin[:per_page] = 1
|
262
|
-
@response =
|
262
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"))
|
263
263
|
MerbAdmin[:per_page] = 100
|
264
264
|
end
|
265
265
|
|
@@ -275,7 +275,7 @@ describe "MerbAdmin" do
|
|
275
275
|
describe "list with 20 objects, page 8", :given => "twenty players exist" do
|
276
276
|
before(:each) do
|
277
277
|
MerbAdmin[:per_page] = 1
|
278
|
-
@response =
|
278
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 8)
|
279
279
|
MerbAdmin[:per_page] = 100
|
280
280
|
end
|
281
281
|
|
@@ -291,7 +291,7 @@ describe "MerbAdmin" do
|
|
291
291
|
describe "list with 20 objects, page 17", :given => "twenty players exist" do
|
292
292
|
before(:each) do
|
293
293
|
MerbAdmin[:per_page] = 1
|
294
|
-
@response =
|
294
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 17)
|
295
295
|
MerbAdmin[:per_page] = 100
|
296
296
|
end
|
297
297
|
|
@@ -307,7 +307,7 @@ describe "MerbAdmin" do
|
|
307
307
|
describe "list show all", :given => "two players exist" do
|
308
308
|
before(:each) do
|
309
309
|
MerbAdmin[:per_page] = 1
|
310
|
-
@response =
|
310
|
+
@response = visit(url(:merb_admin_list, :model_name => "player"), :get, :all => true)
|
311
311
|
MerbAdmin[:per_page] = 100
|
312
312
|
end
|
313
313
|
|
@@ -318,7 +318,7 @@ describe "MerbAdmin" do
|
|
318
318
|
|
319
319
|
describe "new" do
|
320
320
|
before(:each) do
|
321
|
-
@response =
|
321
|
+
@response = visit(url(:merb_admin_new, :model_name => "player"))
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should respond sucessfully" do
|
@@ -345,7 +345,7 @@ describe "MerbAdmin" do
|
|
345
345
|
|
346
346
|
describe "new with has-one association", :given => "a draft exists" do
|
347
347
|
before(:each) do
|
348
|
-
@response =
|
348
|
+
@response = visit(url(:merb_admin_new, :model_name => "player"))
|
349
349
|
end
|
350
350
|
|
351
351
|
it "should respond sucessfully" do
|
@@ -359,7 +359,7 @@ describe "MerbAdmin" do
|
|
359
359
|
|
360
360
|
describe "new with has-many association", :given => "three teams exist" do
|
361
361
|
before(:each) do
|
362
|
-
@response =
|
362
|
+
@response = visit(url(:merb_admin_new, :model_name => "player"))
|
363
363
|
end
|
364
364
|
|
365
365
|
it "should respond sucessfully" do
|
@@ -373,7 +373,7 @@ describe "MerbAdmin" do
|
|
373
373
|
|
374
374
|
describe "new with missing label", :given => "a player exists and three teams with no name exist" do
|
375
375
|
before(:each) do
|
376
|
-
@response =
|
376
|
+
@response = visit(url(:merb_admin_new, :model_name => "player"))
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should respond sucessfully" do
|
@@ -381,271 +381,335 @@ describe "MerbAdmin" do
|
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
384
|
-
describe "
|
384
|
+
describe "create" do
|
385
385
|
before(:each) do
|
386
|
-
|
386
|
+
visit(url(:merb_admin_new, :model_name => "player"))
|
387
|
+
fill_in "Name", :with => "Jackie Robinson"
|
388
|
+
fill_in "Number", :with => "42"
|
389
|
+
fill_in "Position", :with => "Second baseman"
|
390
|
+
@response = click_button "Save"
|
391
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
387
392
|
end
|
388
393
|
|
389
|
-
it "should
|
394
|
+
it "should be successful" do
|
390
395
|
@response.should be_successful
|
391
396
|
end
|
392
397
|
|
393
|
-
it "should
|
394
|
-
@
|
395
|
-
|
396
|
-
|
397
|
-
it "should show required fields as \"Required\"" do
|
398
|
-
@response.body.should contain(/Name\n\s*Required/)
|
399
|
-
@response.body.should contain(/Number\n\s*Required/)
|
400
|
-
end
|
401
|
-
|
402
|
-
it "should show non-required fields as \"Optional\"" do
|
403
|
-
@response.body.should contain(/Position\n\s*Optional/)
|
404
|
-
@response.body.should contain(/Born on\n\s*Optional/)
|
405
|
-
@response.body.should contain(/Notes\n\s*Optional/)
|
406
|
-
@response.body.should contain(/Draft\n\s*Optional/)
|
407
|
-
@response.body.should contain(/Team\n\s*Optional/)
|
398
|
+
it "should create an object with correct attributes" do
|
399
|
+
@player.name.should eql("Jackie Robinson")
|
400
|
+
@player.number.should eql(42)
|
401
|
+
@player.position.should eql("Second baseman")
|
408
402
|
end
|
409
403
|
end
|
410
404
|
|
411
|
-
describe "
|
405
|
+
describe "create and edit" do
|
412
406
|
before(:each) do
|
413
|
-
|
407
|
+
visit(url(:merb_admin_new, :model_name => "player"))
|
408
|
+
fill_in "Name", :with => "Jackie Robinson"
|
409
|
+
fill_in "Number", :with => "42"
|
410
|
+
fill_in "Position", :with => "Second baseman"
|
411
|
+
@response = click_button "Save and continue editing"
|
412
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
414
413
|
end
|
415
414
|
|
416
|
-
it "should
|
415
|
+
it "should be successful" do
|
417
416
|
@response.should be_successful
|
418
417
|
end
|
419
418
|
|
420
|
-
it "should
|
421
|
-
@
|
419
|
+
it "should create an object with correct attributes" do
|
420
|
+
@player.name.should eql("Jackie Robinson")
|
421
|
+
@player.number.should eql(42)
|
422
|
+
@player.position.should eql("Second baseman")
|
422
423
|
end
|
423
424
|
end
|
424
425
|
|
425
|
-
describe "
|
426
|
+
describe "create and add another" do
|
426
427
|
before(:each) do
|
427
|
-
|
428
|
+
visit(url(:merb_admin_new, :model_name => "player"))
|
429
|
+
fill_in "Name", :with => "Jackie Robinson"
|
430
|
+
fill_in "Number", :with => "42"
|
431
|
+
fill_in "Position", :with => "Second baseman"
|
432
|
+
@response = click_button "Save and add another"
|
433
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
428
434
|
end
|
429
435
|
|
430
|
-
it "should
|
436
|
+
it "should be successful" do
|
431
437
|
@response.should be_successful
|
432
438
|
end
|
433
439
|
|
434
|
-
it "should
|
435
|
-
@
|
440
|
+
it "should create an object with correct attributes" do
|
441
|
+
@player.name.should eql("Jackie Robinson")
|
442
|
+
@player.number.should eql(42)
|
443
|
+
@player.position.should eql("Second baseman")
|
436
444
|
end
|
437
445
|
end
|
438
446
|
|
439
|
-
describe "
|
447
|
+
describe "create with has-one association", :given => "a draft exists" do
|
440
448
|
before(:each) do
|
441
|
-
|
449
|
+
visit(url(:merb_admin_new, :model_name => "player"))
|
450
|
+
fill_in "Name", :with => "Jackie Robinson"
|
451
|
+
fill_in "Number", :with => 42
|
452
|
+
fill_in "Position", :with => "Second baseman"
|
453
|
+
fill_in "Draft", :with => @draft.id.to_s
|
454
|
+
@response = click_button "Save"
|
455
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
442
456
|
end
|
443
457
|
|
444
|
-
it "should
|
445
|
-
@
|
458
|
+
it "should create an object with correct associations" do
|
459
|
+
@draft.reload
|
460
|
+
@player.draft.should eql(@draft)
|
446
461
|
end
|
447
462
|
end
|
448
463
|
|
449
|
-
describe "
|
464
|
+
describe "create with has-many association", :given => "three teams exist" do
|
450
465
|
before(:each) do
|
451
|
-
|
466
|
+
visit(url(:merb_admin_new, :model_name => "league"))
|
467
|
+
fill_in "Name", :with => "National League"
|
468
|
+
fill_in "Teams", :with => @teams[0].id.to_s
|
469
|
+
@response = click_button "Save"
|
470
|
+
@league = MerbAdmin::AbstractModel.new("League").first
|
452
471
|
end
|
453
472
|
|
454
|
-
it "should
|
455
|
-
@
|
473
|
+
it "should create an object with correct associations" do
|
474
|
+
@teams[0].reload
|
475
|
+
@league.teams.should include(@teams[0])
|
456
476
|
end
|
457
|
-
end
|
458
477
|
|
459
|
-
|
460
|
-
|
461
|
-
@
|
478
|
+
it "should not create an object with incorrect associations" do
|
479
|
+
@league.teams.should_not include(@teams[1])
|
480
|
+
@league.teams.should_not include(@teams[2])
|
462
481
|
end
|
482
|
+
end
|
463
483
|
|
464
|
-
|
465
|
-
|
484
|
+
describe "create with uniqueness constraint violated", :given => "a player exists" do
|
485
|
+
before(:each) do
|
486
|
+
visit(url(:merb_admin_new, :model_name => "player"))
|
487
|
+
fill_in "Name", :with => @player.name
|
488
|
+
fill_in "Number", :with => @player.number.to_s
|
489
|
+
fill_in "Position", :with => @player.position
|
490
|
+
fill_in "Team", :with => @player.team_id.to_s
|
491
|
+
@response = click_button "Save"
|
466
492
|
end
|
467
493
|
|
468
|
-
it "should
|
469
|
-
|
494
|
+
it "should show an error message" do
|
495
|
+
@response.body.should contain("There is already a player with that number on this team")
|
470
496
|
end
|
471
497
|
end
|
472
498
|
|
473
|
-
describe "create
|
499
|
+
describe "create with invalid object" do
|
474
500
|
before(:each) do
|
475
|
-
@response =
|
476
|
-
end
|
477
|
-
|
478
|
-
it "should redirect to edit" do
|
479
|
-
@response.should redirect_to(url(:merb_admin_edit, :model_name => "player", :id => MerbAdmin::AbstractModel.new("Player").first.id))
|
501
|
+
@response = visit(url(:merb_admin_create, :model_name => "player"), :post, :params => {:player => {}})
|
480
502
|
end
|
481
503
|
|
482
|
-
it "should
|
483
|
-
|
504
|
+
it "should show an error message" do
|
505
|
+
@response.body.should contain("Player failed to be created")
|
484
506
|
end
|
485
507
|
end
|
486
508
|
|
487
|
-
describe "
|
509
|
+
describe "edit", :given => "a player exists" do
|
488
510
|
before(:each) do
|
489
|
-
@response =
|
511
|
+
@response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
490
512
|
end
|
491
513
|
|
492
|
-
it "should
|
493
|
-
@response.should
|
514
|
+
it "should respond sucessfully" do
|
515
|
+
@response.should be_successful
|
516
|
+
end
|
517
|
+
|
518
|
+
it "should show \"Edit model\"" do
|
519
|
+
@response.body.should contain("Edit player")
|
494
520
|
end
|
495
521
|
|
496
|
-
it "should
|
497
|
-
|
522
|
+
it "should show required fields as \"Required\"" do
|
523
|
+
@response.body.should contain(/Name\n\s*Required/)
|
524
|
+
@response.body.should contain(/Number\n\s*Required/)
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should show non-required fields as \"Optional\"" do
|
528
|
+
@response.body.should contain(/Position\n\s*Optional/)
|
529
|
+
@response.body.should contain(/Born on\n\s*Optional/)
|
530
|
+
@response.body.should contain(/Notes\n\s*Optional/)
|
531
|
+
@response.body.should contain(/Draft\n\s*Optional/)
|
532
|
+
@response.body.should contain(/Team\n\s*Optional/)
|
498
533
|
end
|
499
534
|
end
|
500
535
|
|
501
|
-
describe "
|
536
|
+
describe "edit with has-one association", :given => "a player exists and a draft exists" do
|
502
537
|
before(:each) do
|
503
|
-
@response =
|
538
|
+
@response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
504
539
|
end
|
505
540
|
|
506
|
-
it "should
|
507
|
-
|
541
|
+
it "should respond sucessfully" do
|
542
|
+
@response.should be_successful
|
508
543
|
end
|
509
544
|
|
510
|
-
it "should
|
511
|
-
@
|
512
|
-
MerbAdmin::AbstractModel.new("Player").first.draft.should == @draft
|
545
|
+
it "should show associated objects" do
|
546
|
+
@response.body.should contain(/DraftDraft #\d+/)
|
513
547
|
end
|
514
548
|
end
|
515
549
|
|
516
|
-
describe "
|
550
|
+
describe "edit with has-many association", :given => "a player exists and three teams exist" do
|
517
551
|
before(:each) do
|
518
|
-
@response =
|
519
|
-
end
|
520
|
-
|
521
|
-
it "should create a new object" do
|
522
|
-
MerbAdmin::AbstractModel.new("League").first.should_not be_nil
|
552
|
+
@response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
523
553
|
end
|
524
554
|
|
525
|
-
it "should
|
526
|
-
@
|
527
|
-
MerbAdmin::AbstractModel.new("League").first.teams.should include(@teams[0])
|
528
|
-
@teams[1].reload
|
529
|
-
MerbAdmin::AbstractModel.new("League").first.teams.should include(@teams[1])
|
555
|
+
it "should respond sucessfully" do
|
556
|
+
@response.should be_successful
|
530
557
|
end
|
531
558
|
|
532
|
-
it "should
|
533
|
-
|
559
|
+
it "should show associated objects" do
|
560
|
+
@response.body.should contain(/TeamTeam 1Team 2Team 3/)
|
534
561
|
end
|
535
562
|
end
|
536
563
|
|
537
|
-
describe "
|
564
|
+
describe "edit with missing object" do
|
538
565
|
before(:each) do
|
539
|
-
@response =
|
566
|
+
@response = visit(url(:merb_admin_edit, :model_name => "player", :id => 1))
|
540
567
|
end
|
541
568
|
|
542
|
-
it "should
|
543
|
-
@response.
|
569
|
+
it "should raise NotFound" do
|
570
|
+
@response.status.should equal(404)
|
544
571
|
end
|
545
572
|
end
|
546
573
|
|
547
|
-
describe "
|
574
|
+
describe "edit with missing label", :given => "a player exists and three teams with no name exist" do
|
548
575
|
before(:each) do
|
549
|
-
@response =
|
576
|
+
@response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
550
577
|
end
|
551
578
|
|
552
|
-
it "should
|
553
|
-
@response.
|
579
|
+
it "should respond sucessfully" do
|
580
|
+
@response.should be_successful
|
554
581
|
end
|
555
582
|
end
|
556
583
|
|
557
584
|
describe "update", :given => "a player exists" do
|
558
585
|
before(:each) do
|
559
|
-
|
586
|
+
visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
587
|
+
fill_in "Name", :with => "Jackie Robinson"
|
588
|
+
fill_in "Number", :with => "42"
|
589
|
+
fill_in "Position", :with => "Second baseman"
|
590
|
+
@response = click_button "Save"
|
591
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
560
592
|
end
|
561
593
|
|
562
|
-
it "should
|
563
|
-
@response.should
|
594
|
+
it "should be successful" do
|
595
|
+
@response.should be_successful
|
564
596
|
end
|
565
597
|
|
566
|
-
it "should update an object
|
567
|
-
|
598
|
+
it "should update an object with correct attributes" do
|
599
|
+
@player.name.should eql("Jackie Robinson")
|
600
|
+
@player.number.should eql(42)
|
601
|
+
@player.position.should eql("Second baseman")
|
568
602
|
end
|
569
603
|
end
|
570
604
|
|
571
605
|
describe "update and edit", :given => "a player exists" do
|
572
606
|
before(:each) do
|
573
|
-
|
607
|
+
visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
608
|
+
fill_in "Name", :with => "Jackie Robinson"
|
609
|
+
fill_in "Number", :with => "42"
|
610
|
+
fill_in "Position", :with => "Second baseman"
|
611
|
+
@response = click_button "Save and continue"
|
612
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
574
613
|
end
|
575
614
|
|
576
|
-
it "should
|
577
|
-
@response.should
|
615
|
+
it "should be successful" do
|
616
|
+
@response.should be_successful
|
578
617
|
end
|
579
618
|
|
580
|
-
it "should update an object
|
581
|
-
|
619
|
+
it "should update an object with correct attributes" do
|
620
|
+
@player.name.should eql("Jackie Robinson")
|
621
|
+
@player.number.should eql(42)
|
622
|
+
@player.position.should eql("Second baseman")
|
582
623
|
end
|
583
624
|
end
|
584
625
|
|
585
626
|
describe "update and add another", :given => "a player exists" do
|
586
627
|
before(:each) do
|
587
|
-
|
628
|
+
visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
629
|
+
fill_in "Name", :with => "Jackie Robinson"
|
630
|
+
fill_in "Number", :with => "42"
|
631
|
+
fill_in "Position", :with => "Second baseman"
|
632
|
+
@response = click_button "Save and add another"
|
633
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
588
634
|
end
|
589
635
|
|
590
|
-
it "should
|
591
|
-
@response.should
|
636
|
+
it "should be successful" do
|
637
|
+
@response.should be_successful
|
592
638
|
end
|
593
639
|
|
594
|
-
it "should update an object
|
595
|
-
|
640
|
+
it "should update an object with correct attributes" do
|
641
|
+
@player.name.should eql("Jackie Robinson")
|
642
|
+
@player.number.should eql(42)
|
643
|
+
@player.position.should eql("Second baseman")
|
596
644
|
end
|
597
645
|
end
|
598
646
|
|
599
647
|
describe "update with has-one association", :given => "a player exists and a draft exists" do
|
600
648
|
before(:each) do
|
601
|
-
|
649
|
+
visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
650
|
+
fill_in "Name", :with => "Jackie Robinson"
|
651
|
+
fill_in "Number", :with => "42"
|
652
|
+
fill_in "Position", :with => "Second baseman"
|
653
|
+
fill_in "Draft", :with => @draft.id.to_s
|
654
|
+
@response = click_button "Save"
|
655
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
656
|
+
# @response = visit(url(:merb_admin_update, :model_name => "player", :id => @player.id), :put, :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}, :associations => {:draft => @draft.id}})
|
602
657
|
end
|
603
658
|
|
604
|
-
it "should update an object
|
605
|
-
|
659
|
+
it "should update an object with correct attributes" do
|
660
|
+
@player.name.should eql("Jackie Robinson")
|
661
|
+
@player.number.should eql(42)
|
662
|
+
@player.position.should eql("Second baseman")
|
606
663
|
end
|
607
664
|
|
608
|
-
it "should
|
665
|
+
it "should update an object with correct associations" do
|
609
666
|
@draft.reload
|
610
|
-
|
667
|
+
@player.draft.should eql(@draft)
|
611
668
|
end
|
612
669
|
end
|
613
670
|
|
614
671
|
describe "update with has-many association", :given => "a league exists and three teams exist" do
|
615
672
|
before(:each) do
|
616
|
-
|
617
|
-
|
673
|
+
visit(url(:merb_admin_edit, :model_name => "league", :id => @league.id))
|
674
|
+
fill_in "Name", :with => "National League"
|
675
|
+
fill_in "Teams", :with => @teams[0].id.to_s
|
676
|
+
@response = click_button "Save"
|
677
|
+
@league = MerbAdmin::AbstractModel.new("League").first
|
618
678
|
end
|
619
679
|
|
620
|
-
it "should update an object
|
621
|
-
|
680
|
+
it "should update an object with correct attributes" do
|
681
|
+
@league.name.should eql("National League")
|
622
682
|
end
|
623
683
|
|
624
|
-
it "should
|
625
|
-
@teams[
|
626
|
-
|
684
|
+
it "should update an object with correct associations" do
|
685
|
+
@teams[0].reload
|
686
|
+
@league.teams.should include(@teams[0])
|
627
687
|
end
|
628
688
|
|
629
|
-
it "should not
|
630
|
-
@teams[
|
631
|
-
|
632
|
-
MerbAdmin::AbstractModel.new("League").first.teams.should_not include(@teams[2])
|
689
|
+
it "should not update an object with incorrect associations" do
|
690
|
+
@league.teams.should_not include(@teams[1])
|
691
|
+
@league.teams.should_not include(@teams[2])
|
633
692
|
end
|
634
693
|
end
|
635
694
|
|
636
695
|
describe "update with missing object" do
|
637
696
|
before(:each) do
|
638
|
-
@response =
|
697
|
+
@response = visit(url(:merb_admin_update, :model_name => "player", :id => 1), :put, {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
|
639
698
|
end
|
640
699
|
|
641
700
|
it "should raise NotFound" do
|
642
|
-
@response.status.should
|
701
|
+
@response.status.should equal(404)
|
643
702
|
end
|
644
703
|
end
|
645
704
|
|
646
705
|
describe "update with invalid object", :given => "a player exists" do
|
647
706
|
before(:each) do
|
648
|
-
|
707
|
+
visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
|
708
|
+
fill_in "Name", :with => "Jackie Robinson"
|
709
|
+
fill_in "Number", :with => "a"
|
710
|
+
fill_in "Position", :with => "Second baseman"
|
711
|
+
@response = click_button "Save"
|
712
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
649
713
|
end
|
650
714
|
|
651
715
|
it "should show an error message" do
|
@@ -655,7 +719,7 @@ describe "MerbAdmin" do
|
|
655
719
|
|
656
720
|
describe "delete", :given => "a player exists" do
|
657
721
|
before(:each) do
|
658
|
-
@response =
|
722
|
+
@response = visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
|
659
723
|
end
|
660
724
|
|
661
725
|
it "should respond sucessfully" do
|
@@ -669,11 +733,11 @@ describe "MerbAdmin" do
|
|
669
733
|
|
670
734
|
describe "delete with missing object" do
|
671
735
|
before(:each) do
|
672
|
-
@response =
|
736
|
+
@response = visit(url(:merb_admin_delete, :model_name => "player", :id => 1))
|
673
737
|
end
|
674
738
|
|
675
739
|
it "should raise NotFound" do
|
676
|
-
@response.status.should
|
740
|
+
@response.status.should equal(404)
|
677
741
|
end
|
678
742
|
end
|
679
743
|
|
@@ -681,7 +745,7 @@ describe "MerbAdmin" do
|
|
681
745
|
before(:each) do
|
682
746
|
@league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
|
683
747
|
@team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => rand(99999), :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
|
684
|
-
@response =
|
748
|
+
@response = visit(url(:merb_admin_delete, :model_name => "league", :id => @league.id))
|
685
749
|
end
|
686
750
|
|
687
751
|
it "should respond sucessfully" do
|
@@ -691,25 +755,27 @@ describe "MerbAdmin" do
|
|
691
755
|
|
692
756
|
describe "destroy", :given => "a player exists" do
|
693
757
|
before(:each) do
|
694
|
-
|
758
|
+
visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
|
759
|
+
@response = click_button "Yes, I'm sure"
|
760
|
+
@player = MerbAdmin::AbstractModel.new("Player").first
|
695
761
|
end
|
696
762
|
|
697
|
-
it "should
|
698
|
-
@response.should
|
763
|
+
it "should be successful" do
|
764
|
+
@response.should be_successful
|
699
765
|
end
|
700
766
|
|
701
767
|
it "should destroy an object" do
|
702
|
-
|
768
|
+
@player.should be_nil
|
703
769
|
end
|
704
770
|
end
|
705
771
|
|
706
772
|
describe "destroy with missing object" do
|
707
773
|
before(:each) do
|
708
|
-
@response =
|
774
|
+
@response = visit(url(:merb_admin_destroy, :model_name => "player", :id => 1), :delete)
|
709
775
|
end
|
710
776
|
|
711
777
|
it "should raise NotFound" do
|
712
|
-
@response.status.should
|
778
|
+
@response.status.should equal(404)
|
713
779
|
end
|
714
780
|
end
|
715
781
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Michaels-Ober
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-28 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|