merb-admin 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/Gemfile +21 -23
  2. data/Gemfile.lock +107 -89
  3. data/LICENSE +20 -20
  4. data/README.rdoc +54 -54
  5. data/Rakefile +11 -11
  6. data/app/controllers/application.rb +6 -6
  7. data/app/controllers/main.rb +191 -191
  8. data/app/helpers/application_helper.rb +64 -64
  9. data/app/helpers/main_helper.rb +167 -167
  10. data/app/views/layout/_message.html.erb +10 -10
  11. data/app/views/layout/dashboard.html.erb +34 -34
  12. data/app/views/layout/form.html.erb +48 -48
  13. data/app/views/layout/list.html.erb +42 -42
  14. data/app/views/main/_belongs_to.html.erb +29 -29
  15. data/app/views/main/_big_decimal.html.erb +12 -12
  16. data/app/views/main/_boolean.html.erb +7 -7
  17. data/app/views/main/_date.html.erb +12 -12
  18. data/app/views/main/_datetime.html.erb +12 -12
  19. data/app/views/main/_float.html.erb +12 -12
  20. data/app/views/main/_has_many.html.erb +16 -16
  21. data/app/views/main/_has_one.html.erb +30 -30
  22. data/app/views/main/_integer.html.erb +12 -12
  23. data/app/views/main/_properties.html.erb +18 -18
  24. data/app/views/main/_string.html.erb +15 -15
  25. data/app/views/main/_text.html.erb +11 -11
  26. data/app/views/main/_time.html.erb +12 -12
  27. data/app/views/main/_timestamp.html.erb +12 -12
  28. data/app/views/main/delete.html.erb +28 -28
  29. data/app/views/main/edit.html.erb +19 -19
  30. data/app/views/main/index.html.erb +22 -22
  31. data/app/views/main/list.html.erb +93 -93
  32. data/app/views/main/new.html.erb +16 -16
  33. data/config/init.rb +31 -30
  34. data/config/router.rb +4 -4
  35. data/lib/abstract_model.rb +84 -84
  36. data/lib/active_record_support.rb +151 -147
  37. data/lib/datamapper_support.rb +145 -141
  38. data/lib/generic_support.rb +13 -13
  39. data/lib/merb-admin.rb +100 -100
  40. data/lib/merb-admin/merbtasks.rb +103 -103
  41. data/lib/merb-admin/slicetasks.rb +168 -174
  42. data/lib/merb-admin/spectasks.rb +55 -55
  43. data/lib/merb-admin/version.rb +3 -3
  44. data/lib/sequel_support.rb +282 -275
  45. data/merb-admin.gemspec +42 -41
  46. data/public/javascripts/CollapsedFieldsets.js +85 -85
  47. data/public/javascripts/DateTimeShortcuts.js +255 -255
  48. data/public/javascripts/RelatedObjectLookups.js +96 -96
  49. data/public/javascripts/SelectBox.js +111 -111
  50. data/public/javascripts/SelectFilter2.js +113 -113
  51. data/public/javascripts/actions.js +39 -39
  52. data/public/javascripts/calendar.js +143 -143
  53. data/public/javascripts/core.js +176 -176
  54. data/public/javascripts/dateparse.js +233 -233
  55. data/public/javascripts/getElementsBySelector.js +167 -167
  56. data/public/javascripts/i18n.js +33 -33
  57. data/public/javascripts/ordering.js +137 -137
  58. data/public/javascripts/timeparse.js +94 -94
  59. data/public/javascripts/urlify.js +140 -140
  60. data/public/stylesheets/base.css +746 -746
  61. data/public/stylesheets/changelists.css +269 -269
  62. data/public/stylesheets/dashboard.css +24 -24
  63. data/public/stylesheets/forms.css +327 -327
  64. data/public/stylesheets/global.css +142 -142
  65. data/public/stylesheets/ie.css +50 -50
  66. data/public/stylesheets/layout.css +29 -29
  67. data/public/stylesheets/login.css +54 -54
  68. data/public/stylesheets/master.css +1 -1
  69. data/public/stylesheets/patch-iewin.css +7 -7
  70. data/public/stylesheets/rtl.css +206 -206
  71. data/public/stylesheets/widgets.css +506 -506
  72. data/spec/controllers/main_spec.rb +25 -25
  73. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  74. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  75. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  76. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -19
  77. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  78. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  79. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  80. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  81. data/spec/migrations/sequel/004_create_players_migration.rb +21 -21
  82. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  83. data/spec/models/activerecord/division.rb +7 -7
  84. data/spec/models/activerecord/draft.rb +11 -11
  85. data/spec/models/activerecord/league.rb +6 -6
  86. data/spec/models/activerecord/player.rb +8 -8
  87. data/spec/models/activerecord/team.rb +13 -13
  88. data/spec/models/datamapper/division.rb +12 -12
  89. data/spec/models/datamapper/draft.rb +18 -18
  90. data/spec/models/datamapper/league.rb +11 -11
  91. data/spec/models/datamapper/player.rb +20 -20
  92. data/spec/models/datamapper/team.rb +22 -22
  93. data/spec/models/sequel/division.rb +15 -15
  94. data/spec/models/sequel/draft.rb +19 -19
  95. data/spec/models/sequel/league.rb +14 -14
  96. data/spec/models/sequel/player.rb +18 -18
  97. data/spec/models/sequel/team.rb +21 -21
  98. data/spec/requests/main_spec.rb +873 -763
  99. data/spec/spec_helper.rb +111 -113
  100. metadata +40 -26
@@ -1,6 +1,6 @@
1
- class League < ActiveRecord::Base
2
- validates_presence_of(:name)
3
-
4
- has_many(:divisions)
5
- has_many(:teams)
6
- end
1
+ class League < ActiveRecord::Base
2
+ validates_presence_of(:name)
3
+
4
+ has_many(:divisions)
5
+ has_many(:teams)
6
+ end
@@ -1,8 +1,8 @@
1
- class Player < ActiveRecord::Base
2
- validates_presence_of(:name)
3
- validates_numericality_of(:number, :only_integer => true)
4
- validates_uniqueness_of(:number, :scope => :team_id, :message => "There is already a player with that number on this team")
5
-
6
- belongs_to(:team)
7
- has_one(:draft)
8
- end
1
+ class Player < ActiveRecord::Base
2
+ validates_presence_of(:name)
3
+ validates_numericality_of(:number, :only_integer => true)
4
+ validates_uniqueness_of(:number, :scope => :team_id, :message => "There is already a player with that number on this team")
5
+
6
+ belongs_to(:team)
7
+ has_one(:draft)
8
+ end
@@ -1,13 +1,13 @@
1
- class Team < ActiveRecord::Base
2
- validates_numericality_of(:league_id, :only_integer => true)
3
- validates_numericality_of(:division_id, :only_integer => true)
4
- validates_presence_of(:manager)
5
- validates_numericality_of(:founded, :only_integer => true)
6
- validates_numericality_of(:wins, :only_integer => true)
7
- validates_numericality_of(:losses, :only_integer => true)
8
- validates_numericality_of(:win_percentage)
9
-
10
- belongs_to(:league)
11
- belongs_to(:division)
12
- has_many(:players)
13
- end
1
+ class Team < ActiveRecord::Base
2
+ validates_numericality_of(:league_id, :only_integer => true)
3
+ validates_numericality_of(:division_id, :only_integer => true)
4
+ validates_presence_of(:manager)
5
+ validates_numericality_of(:founded, :only_integer => true)
6
+ validates_numericality_of(:wins, :only_integer => true)
7
+ validates_numericality_of(:losses, :only_integer => true)
8
+ validates_numericality_of(:win_percentage)
9
+
10
+ belongs_to(:league)
11
+ belongs_to(:division)
12
+ has_many(:players)
13
+ end
@@ -1,12 +1,12 @@
1
- class Division
2
- include DataMapper::Resource
3
-
4
- property(:id, Serial)
5
- property(:created_at, DateTime)
6
- property(:updated_at, DateTime)
7
- property(:league_id, Integer, :required => true, :index => true)
8
- property(:name, String, :required => true, :index => true)
9
-
10
- belongs_to(:league)
11
- has(n, :teams)
12
- end
1
+ class Division
2
+ include DataMapper::Resource
3
+
4
+ property(:id, Serial)
5
+ property(:created_at, DateTime)
6
+ property(:updated_at, DateTime)
7
+ property(:league_id, Integer, :required => true, :index => true)
8
+ property(:name, String, :required => true, :index => true)
9
+
10
+ belongs_to(:league)
11
+ has(n, :teams)
12
+ end
@@ -1,18 +1,18 @@
1
- class Draft
2
- include DataMapper::Resource
3
-
4
- property(:id, Serial)
5
- property(:created_at, DateTime)
6
- property(:updated_at, DateTime)
7
- property(:player_id, Integer, :required => true, :index => true)
8
- property(:team_id, Integer, :required => true, :index => true)
9
- property(:date, Date, :required => true)
10
- property(:round, Integer, :required => true)
11
- property(:pick, Integer, :required => true)
12
- property(:overall, Integer, :required => true)
13
- property(:college, String, :length => 100, :index => true)
14
- property(:notes, Text)
15
-
16
- belongs_to(:team)
17
- belongs_to(:player)
18
- end
1
+ class Draft
2
+ include DataMapper::Resource
3
+
4
+ property(:id, Serial)
5
+ property(:created_at, DateTime)
6
+ property(:updated_at, DateTime)
7
+ property(:player_id, Integer, :required => true, :index => true)
8
+ property(:team_id, Integer, :required => true, :index => true)
9
+ property(:date, Date, :required => true)
10
+ property(:round, Integer, :required => true)
11
+ property(:pick, Integer, :required => true)
12
+ property(:overall, Integer, :required => true)
13
+ property(:college, String, :length => 100, :index => true)
14
+ property(:notes, Text)
15
+
16
+ belongs_to(:team)
17
+ belongs_to(:player)
18
+ end
@@ -1,11 +1,11 @@
1
- class League
2
- include DataMapper::Resource
3
-
4
- property(:id, Serial)
5
- property(:created_at, DateTime)
6
- property(:updated_at, DateTime)
7
- property(:name, String, :required => true, :index => true)
8
-
9
- has(n, :divisions)
10
- has(n, :teams)
11
- end
1
+ class League
2
+ include DataMapper::Resource
3
+
4
+ property(:id, Serial)
5
+ property(:created_at, DateTime)
6
+ property(:updated_at, DateTime)
7
+ property(:name, String, :required => true, :index => true)
8
+
9
+ has(n, :divisions)
10
+ has(n, :teams)
11
+ end
@@ -1,20 +1,20 @@
1
- class Player
2
- include DataMapper::Resource
3
-
4
- property(:id, Serial)
5
- property(:created_at, DateTime)
6
- property(:updated_at, DateTime)
7
- property(:team_id, Integer, :index => true)
8
- property(:name, String, :length => 100, :required => true, :index => true)
9
- property(:position, String, :index => true)
10
- property(:number, Integer, :required => true)
11
- property(:retired, Boolean, :default => false)
12
- property(:injured, Boolean, :default => false)
13
- property(:born_on, Date)
14
- property(:notes, Text)
15
-
16
- validates_uniqueness_of(:number, :scope => :team_id, :message => "There is already a player with that number on this team")
17
-
18
- belongs_to(:team)
19
- has(1, :draft)
20
- end
1
+ class Player
2
+ include DataMapper::Resource
3
+
4
+ property(:id, Serial)
5
+ property(:created_at, DateTime)
6
+ property(:updated_at, DateTime)
7
+ property(:team_id, Integer, :index => true)
8
+ property(:name, String, :length => 100, :required => true, :index => true)
9
+ property(:position, String, :index => true)
10
+ property(:number, Integer, :required => true)
11
+ property(:retired, Boolean, :default => false)
12
+ property(:injured, Boolean, :default => false)
13
+ property(:born_on, Date)
14
+ property(:notes, Text)
15
+
16
+ validates_uniqueness_of(:number, :scope => :team_id, :message => "There is already a player with that number on this team")
17
+
18
+ belongs_to(:team)
19
+ has(1, :draft)
20
+ end
@@ -1,22 +1,22 @@
1
- class Team
2
- include DataMapper::Resource
3
-
4
- property(:id, Serial)
5
- property(:created_at, DateTime)
6
- property(:updated_at, DateTime)
7
- property(:league_id, Integer, :required => true, :index => true)
8
- property(:division_id, Integer, :required => true, :index => true)
9
- property(:name, String, :index => true)
10
- property(:logo_url, String, :length => 255)
11
- property(:manager, String, :length => 100, :required => true, :index => true)
12
- property(:ballpark, String, :length => 100, :index => true)
13
- property(:mascot, String, :length => 100, :index => true)
14
- property(:founded, Integer, :required => true)
15
- property(:wins, Integer, :required => true)
16
- property(:losses, Integer, :required => true)
17
- property(:win_percentage, Float, :required => true, :precision => 4, :scale => 3)
18
-
19
- belongs_to(:league)
20
- belongs_to(:division)
21
- has(n, :players)
22
- end
1
+ class Team
2
+ include DataMapper::Resource
3
+
4
+ property(:id, Serial)
5
+ property(:created_at, DateTime)
6
+ property(:updated_at, DateTime)
7
+ property(:league_id, Integer, :required => true, :index => true)
8
+ property(:division_id, Integer, :required => true, :index => true)
9
+ property(:name, String, :index => true)
10
+ property(:logo_url, String, :length => 255)
11
+ property(:manager, String, :length => 100, :required => true, :index => true)
12
+ property(:ballpark, String, :length => 100, :index => true)
13
+ property(:mascot, String, :length => 100, :index => true)
14
+ property(:founded, Integer, :required => true)
15
+ property(:wins, Integer, :required => true)
16
+ property(:losses, Integer, :required => true)
17
+ property(:win_percentage, Float, :required => true, :precision => 4, :scale => 3)
18
+
19
+ belongs_to(:league)
20
+ belongs_to(:division)
21
+ has(n, :players)
22
+ end
@@ -1,15 +1,15 @@
1
- class Division < Sequel::Model
2
- set_primary_key(:id)
3
- plugin(:timestamps, :update_on_create => true)
4
- plugin(:validation_helpers)
5
-
6
- many_to_one(:league)
7
- one_to_many(:teams)
8
-
9
- self.raise_on_save_failure = false
10
- self.raise_on_typecast_failure = false
11
- def validate
12
- validates_numeric(:league_id, :only_integer => true)
13
- validates_presence(:name)
14
- end
15
- end
1
+ class Division < Sequel::Model
2
+ set_primary_key(:id)
3
+ plugin(:timestamps, :update_on_create => true)
4
+ plugin(:validation_helpers)
5
+
6
+ many_to_one(:league)
7
+ one_to_many(:teams)
8
+
9
+ self.raise_on_save_failure = false
10
+ self.raise_on_typecast_failure = false
11
+ def validate
12
+ validates_numeric(:league_id, :only_integer => true)
13
+ validates_presence(:name)
14
+ end
15
+ end
@@ -1,19 +1,19 @@
1
- class Draft < Sequel::Model
2
- set_primary_key(:id)
3
- plugin(:timestamps, :update_on_create => true)
4
- plugin(:validation_helpers)
5
-
6
- many_to_one(:team)
7
- many_to_one(:player)
8
-
9
- self.raise_on_save_failure = false
10
- self.raise_on_typecast_failure = false
11
- def validate
12
- validates_numeric(:player_id, :only_integer => true, :allow_blank => true)
13
- validates_numeric(:team_id, :only_integer => true, :allow_blank => true)
14
- validates_presence(:date)
15
- validates_numeric(:round, :only_integer => true)
16
- validates_numeric(:pick, :only_integer => true)
17
- validates_numeric(:overall, :only_integer => true)
18
- end
19
- end
1
+ class Draft < Sequel::Model
2
+ set_primary_key(:id)
3
+ plugin(:timestamps, :update_on_create => true)
4
+ plugin(:validation_helpers)
5
+
6
+ many_to_one(:team)
7
+ many_to_one(:player)
8
+
9
+ self.raise_on_save_failure = false
10
+ self.raise_on_typecast_failure = false
11
+ def validate
12
+ validates_numeric(:player_id, :only_integer => true, :allow_blank => true)
13
+ validates_numeric(:team_id, :only_integer => true, :allow_blank => true)
14
+ validates_presence(:date)
15
+ validates_numeric(:round, :only_integer => true)
16
+ validates_numeric(:pick, :only_integer => true)
17
+ validates_numeric(:overall, :only_integer => true)
18
+ end
19
+ end
@@ -1,14 +1,14 @@
1
- class League < Sequel::Model
2
- set_primary_key(:id)
3
- plugin(:timestamps, :update_on_create => true)
4
- plugin(:validation_helpers)
5
-
6
- one_to_many(:divisions)
7
- one_to_many(:teams)
8
-
9
- self.raise_on_save_failure = false
10
- self.raise_on_typecast_failure = false
11
- def validate
12
- validates_presence(:name)
13
- end
14
- end
1
+ class League < Sequel::Model
2
+ set_primary_key(:id)
3
+ plugin(:timestamps, :update_on_create => true)
4
+ plugin(:validation_helpers)
5
+
6
+ one_to_many(:divisions)
7
+ one_to_many(:teams)
8
+
9
+ self.raise_on_save_failure = false
10
+ self.raise_on_typecast_failure = false
11
+ def validate
12
+ validates_presence(:name)
13
+ end
14
+ end
@@ -1,18 +1,18 @@
1
- class Player < Sequel::Model
2
- set_primary_key(:id)
3
- plugin(:timestamps, :update_on_create => true)
4
- plugin(:validation_helpers)
5
-
6
- many_to_one(:team)
7
- one_to_many(:drafts, :one_to_one => true)
8
-
9
- self.raise_on_save_failure = false
10
- self.raise_on_typecast_failure = false
11
- def validate
12
- validates_numeric(:number, :only_integer => true)
13
- validates_unique(:number, :message => "There is already a player with that number on this team") do |dataset|
14
- dataset.where("team_id = ?", team_id)
15
- end
16
- end
17
- end
18
-
1
+ class Player < Sequel::Model
2
+ set_primary_key(:id)
3
+ plugin(:timestamps, :update_on_create => true)
4
+ plugin(:validation_helpers)
5
+
6
+ many_to_one(:team)
7
+ one_to_one(:draft)
8
+
9
+ self.raise_on_save_failure = false
10
+ self.raise_on_typecast_failure = false
11
+ def validate
12
+ validates_numeric(:number, :only_integer => true)
13
+ validates_unique(:number, :message => "There is already a player with that number on this team") do |dataset|
14
+ dataset.where("team_id = ?", team_id)
15
+ end
16
+ end
17
+ end
18
+
@@ -1,21 +1,21 @@
1
- class Team < Sequel::Model
2
- set_primary_key(:id)
3
- plugin(:timestamps, :update_on_create => true)
4
- plugin(:validation_helpers)
5
-
6
- many_to_one(:league)
7
- many_to_one(:division)
8
- one_to_many(:players)
9
-
10
- self.raise_on_save_failure = false
11
- self.raise_on_typecast_failure = false
12
- def validate
13
- validates_numeric(:league_id, :only_integer => true)
14
- validates_numeric(:division_id, :only_integer => true)
15
- validates_presence(:manager)
16
- validates_numeric(:founded, :only_integer => true)
17
- validates_numeric(:wins, :only_integer => true)
18
- validates_numeric(:losses, :only_integer => true)
19
- validates_numeric(:win_percentage)
20
- end
21
- end
1
+ class Team < Sequel::Model
2
+ set_primary_key(:id)
3
+ plugin(:timestamps, :update_on_create => true)
4
+ plugin(:validation_helpers)
5
+
6
+ many_to_one(:league)
7
+ many_to_one(:division)
8
+ one_to_many(:players)
9
+
10
+ self.raise_on_save_failure = false
11
+ self.raise_on_typecast_failure = false
12
+ def validate
13
+ validates_numeric(:league_id, :only_integer => true)
14
+ validates_numeric(:division_id, :only_integer => true)
15
+ validates_presence(:manager)
16
+ validates_numeric(:founded, :only_integer => true)
17
+ validates_numeric(:wins, :only_integer => true)
18
+ validates_numeric(:losses, :only_integer => true)
19
+ validates_numeric(:win_percentage)
20
+ end
21
+ end
@@ -1,763 +1,873 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
-
3
- given "a player exists" do
4
- @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
5
- end
6
-
7
- given "a draft exists" do
8
- @draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => rand(99999), :team_id => rand(99999), :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
9
- end
10
-
11
- given "a league exists" do
12
- @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
13
- end
14
-
15
- given "two players exist" do
16
- @players = []
17
- (1..2).each do |number|
18
- @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
19
- end
20
- end
21
-
22
- given "three teams exist" do
23
- @teams = []
24
- (1..3).each do |number|
25
- @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
26
- end
27
- end
28
-
29
- given "three teams with no name exist" do
30
- @teams = []
31
- (1..3).each do |number|
32
- @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
33
- end
34
- end
35
-
36
- given "twenty players exist" do
37
- @players = []
38
- (1..20).each do |number|
39
- @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
40
- end
41
- end
42
-
43
- describe "MerbAdmin" do
44
- before(:each) do
45
- mount_slice
46
- MerbAdmin::AbstractModel.new("Division").destroy_all!
47
- MerbAdmin::AbstractModel.new("Draft").destroy_all!
48
- MerbAdmin::AbstractModel.new("League").destroy_all!
49
- MerbAdmin::AbstractModel.new("Player").destroy_all!
50
- MerbAdmin::AbstractModel.new("Team").destroy_all!
51
- end
52
-
53
- describe "dashboard" do
54
- before(:each) do
55
- @response = visit(url(:merb_admin_dashboard))
56
- end
57
-
58
- it "should respond sucessfully" do
59
- @response.should be_successful
60
- end
61
-
62
- it "should show \"Site administration\"" do
63
- @response.body.should contain("Site administration")
64
- end
65
- end
66
-
67
- describe "dashboard with excluded models" do
68
- before(:each) do
69
- MerbAdmin[:excluded_models] = ["Player"]
70
- @response = visit(url(:merb_admin_dashboard))
71
- MerbAdmin[:excluded_models] = []
72
- end
73
-
74
- it "should respond sucessfully" do
75
- @response.should be_successful
76
- end
77
-
78
- it "should not contain excluded models" do
79
- @response.body.should_not contain(/Player/)
80
- end
81
- end
82
-
83
- describe "list" do
84
- before(:each) do
85
- @response = visit(url(:merb_admin_list, :model_name => "player"))
86
- end
87
-
88
- it "should respond sucessfully" do
89
- @response.should be_successful
90
- end
91
-
92
- it "should show \"Select model to edit\"" do
93
- @response.body.should contain("Select player to edit")
94
- end
95
-
96
- it "should show filters" do
97
- @response.body.should contain(/Filter\n\s*By Retired\n\s*All\n\s*Yes\n\s*No\n\s*By Injured\n\s*All\n\s*Yes\n\s*No/)
98
- end
99
-
100
- it "should show column headers" do
101
- @response.body.should contain(/Id\n\s*Created at\n\s*Updated at\n\s*Team\n\s*Name\n\s*Position\n\s*Number\n\s*Retired\n\s*Injured\n\s*Born on\n\s*Notes/)
102
- end
103
- end
104
-
105
- describe "list with sort" do
106
- before(:each) do
107
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
108
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
109
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name")
110
- end
111
-
112
- it "should respond sucessfully" do
113
- @response.should be_successful
114
- end
115
-
116
- it "should be sorted correctly" do
117
- @response.body.should contain(/Jackie Robinson.*Sandy Koufax/m)
118
- end
119
- end
120
-
121
- describe "list with reverse sort" do
122
- before(:each) do
123
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
124
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
125
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name", :sort_reverse => "true")
126
- end
127
-
128
- it "should respond sucessfully" do
129
- @response.should be_successful
130
- end
131
-
132
- it "should be sorted correctly" do
133
- @response.body.should contain(/Sandy Koufax.*Jackie Robinson/m)
134
- end
135
- end
136
-
137
- describe "list with query" do
138
- before(:each) do
139
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher")
140
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
141
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Jackie Robinson")
142
- end
143
-
144
- it "should respond sucessfully" do
145
- @response.should be_successful
146
- end
147
-
148
- it "should show a correct result" do
149
- @response.body.should contain("Jackie Robinson")
150
- end
151
-
152
- it "should not contain an incorrect result" do
153
- @response.body.should_not contain("Sandy Koufax")
154
- end
155
- end
156
-
157
- describe "list with query and boolean filter" do
158
- before(:each) do
159
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher", :retired => true, :injured => true)
160
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
161
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
162
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
163
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Sandy Koufax", :filter => {:injured => "true"})
164
- end
165
-
166
- it "should respond sucessfully" do
167
- @response.should be_successful
168
- end
169
-
170
- it "should show a correct result" do
171
- @response.body.should contain("Sandy Koufax")
172
- end
173
-
174
- it "should not contain an incorrect result" do
175
- @response.body.should_not contain("Jackie Robinson")
176
- @response.body.should_not contain("Moises Alou")
177
- @response.body.should_not contain("David Wright")
178
- end
179
- end
180
-
181
-
182
- describe "list with boolean filter" do
183
- before(:each) do
184
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :injured => true)
185
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :injured => false)
186
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:injured => "true"})
187
- end
188
-
189
- it "should respond sucessfully" do
190
- @response.should be_successful
191
- end
192
-
193
- it "should show a correct result" do
194
- @response.body.should contain("Moises Alou")
195
- end
196
-
197
- it "should not contain an incorrect result" do
198
- @response.body.should_not contain("David Wright")
199
- end
200
- end
201
-
202
- describe "list with boolean filters" do
203
- before(:each) do
204
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 32, :name => "Sandy Koufax", :position => "Starting patcher", :retired => true, :injured => true)
205
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 42, :name => "Jackie Robinson", :position => "Second baseman", :retired => true, :injured => false)
206
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 18, :name => "Moises Alou", :position => "Left fielder", :retired => false, :injured => true)
207
- MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
208
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:retired => "true", :injured => "true"})
209
- end
210
-
211
- it "should respond sucessfully" do
212
- @response.should be_successful
213
- end
214
-
215
- it "should show a correct result" do
216
- end
217
-
218
- it "should not contain an incorrect result" do
219
- @response.body.should_not contain("Jackie Robinson")
220
- @response.body.should_not contain("Moises Alou")
221
- @response.body.should_not contain("David Wright")
222
- end
223
- end
224
-
225
- describe "list with 2 objects", :given => "two players exist" do
226
- before(:each) do
227
- MerbAdmin[:per_page] = 1
228
- @response = visit(url(:merb_admin_list, :model_name => "player"))
229
- MerbAdmin[:per_page] = 100
230
- end
231
-
232
- it "should respond sucessfully" do
233
- @response.should be_successful
234
- end
235
-
236
- it "should show \"2 results\"" do
237
- @response.body.should contain("2 players")
238
- end
239
- end
240
-
241
- describe "list with 20 objects", :given => "twenty players exist" do
242
- before(:each) do
243
- MerbAdmin[:per_page] = 1
244
- @response = visit(url(:merb_admin_list, :model_name => "player"))
245
- MerbAdmin[:per_page] = 100
246
- end
247
-
248
- it "should respond sucessfully" do
249
- @response.should be_successful
250
- end
251
-
252
- it "should show \"20 results\"" do
253
- @response.body.should contain("20 players")
254
- end
255
- end
256
-
257
- describe "list with 20 objects, page 8", :given => "twenty players exist" do
258
- before(:each) do
259
- MerbAdmin[:per_page] = 1
260
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 8)
261
- MerbAdmin[:per_page] = 100
262
- end
263
-
264
- it "should respond sucessfully" do
265
- @response.should be_successful
266
- end
267
-
268
- it "should paginate correctly" do
269
- @response.body.should contain(/1 2[^0-9]*5 6 7 8 9 10 11[^0-9]*19 20/)
270
- end
271
- end
272
-
273
- describe "list with 20 objects, page 17", :given => "twenty players exist" do
274
- before(:each) do
275
- MerbAdmin[:per_page] = 1
276
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 17)
277
- MerbAdmin[:per_page] = 100
278
- end
279
-
280
- it "should respond sucessfully" do
281
- @response.should be_successful
282
- end
283
-
284
- it "should paginate correctly" do
285
- @response.body.should contain(/1 2[^0-9]*12 13 14 15 16 17 18 19 20/)
286
- end
287
- end
288
-
289
- describe "list show all", :given => "two players exist" do
290
- before(:each) do
291
- MerbAdmin[:per_page] = 1
292
- @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :all => true)
293
- MerbAdmin[:per_page] = 100
294
- end
295
-
296
- it "should respond sucessfully" do
297
- @response.should be_successful
298
- end
299
- end
300
-
301
- describe "new" do
302
- before(:each) do
303
- @response = visit(url(:merb_admin_new, :model_name => "player"))
304
- end
305
-
306
- it "should respond sucessfully" do
307
- @response.should be_successful
308
- end
309
-
310
- it "should show \"New model\"" do
311
- @response.body.should contain("New player")
312
- end
313
-
314
- it "should show required fields as \"Required\"" do
315
- @response.body.should contain(/Name\n\s*Required/)
316
- @response.body.should contain(/Number\n\s*Required/)
317
- end
318
-
319
- it "should show non-required fields as \"Optional\"" do
320
- @response.body.should contain(/Position\n\s*Optional/)
321
- @response.body.should contain(/Born on\n\s*Optional/)
322
- @response.body.should contain(/Notes\n\s*Optional/)
323
- @response.body.should contain(/Draft\n\s*Optional/)
324
- @response.body.should contain(/Team\n\s*Optional/)
325
- end
326
- end
327
-
328
- describe "new with has-one association", :given => "a draft exists" do
329
- before(:each) do
330
- @response = visit(url(:merb_admin_new, :model_name => "player"))
331
- end
332
-
333
- it "should respond sucessfully" do
334
- @response.should be_successful
335
- end
336
-
337
- it "should show associated objects" do
338
- @response.body.should contain(/DraftDraft #\d+/)
339
- end
340
- end
341
-
342
- describe "new with has-many association", :given => "three teams exist" do
343
- before(:each) do
344
- @response = visit(url(:merb_admin_new, :model_name => "player"))
345
- end
346
-
347
- it "should respond sucessfully" do
348
- @response.should be_successful
349
- end
350
-
351
- it "should show associated objects" do
352
- @response.body.should contain(/TeamTeam 1Team 2Team 3/)
353
- end
354
- end
355
-
356
- describe "new with missing label", :given => ["a player exists", "three teams with no name exist"] do
357
- before(:each) do
358
- @response = visit(url(:merb_admin_new, :model_name => "player"))
359
- end
360
-
361
- it "should respond sucessfully" do
362
- @response.should be_successful
363
- end
364
- end
365
-
366
- describe "create" do
367
- before(:each) do
368
- visit(url(:merb_admin_new, :model_name => "player"))
369
- fill_in "Name", :with => "Jackie Robinson"
370
- fill_in "Number", :with => "42"
371
- fill_in "Position", :with => "Second baseman"
372
- @response = click_button "Save"
373
- @player = MerbAdmin::AbstractModel.new("Player").first
374
- end
375
-
376
- it "should be successful" do
377
- @response.should be_successful
378
- end
379
-
380
- it "should create an object with correct attributes" do
381
- @player.name.should eql("Jackie Robinson")
382
- @player.number.should eql(42)
383
- @player.position.should eql("Second baseman")
384
- end
385
- end
386
-
387
- describe "create and edit" do
388
- before(:each) do
389
- visit(url(:merb_admin_new, :model_name => "player"))
390
- fill_in "Name", :with => "Jackie Robinson"
391
- fill_in "Number", :with => "42"
392
- fill_in "Position", :with => "Second baseman"
393
- @response = click_button "Save and continue editing"
394
- @player = MerbAdmin::AbstractModel.new("Player").first
395
- end
396
-
397
- it "should be successful" do
398
- @response.should be_successful
399
- end
400
-
401
- it "should create an object with correct attributes" do
402
- @player.name.should eql("Jackie Robinson")
403
- @player.number.should eql(42)
404
- @player.position.should eql("Second baseman")
405
- end
406
- end
407
-
408
- describe "create and add another" do
409
- before(:each) do
410
- visit(url(:merb_admin_new, :model_name => "player"))
411
- fill_in "Name", :with => "Jackie Robinson"
412
- fill_in "Number", :with => "42"
413
- fill_in "Position", :with => "Second baseman"
414
- @response = click_button "Save and add another"
415
- @player = MerbAdmin::AbstractModel.new("Player").first
416
- end
417
-
418
- it "should be successful" do
419
- @response.should be_successful
420
- end
421
-
422
- it "should create an object with correct attributes" do
423
- @player.name.should eql("Jackie Robinson")
424
- @player.number.should eql(42)
425
- @player.position.should eql("Second baseman")
426
- end
427
- end
428
-
429
- describe "create with has-one association", :given => "a draft exists" do
430
- before(:each) do
431
- visit(url(:merb_admin_new, :model_name => "player"))
432
- fill_in "Name", :with => "Jackie Robinson"
433
- fill_in "Number", :with => 42
434
- fill_in "Position", :with => "Second baseman"
435
- fill_in "Draft", :with => @draft.id.to_s
436
- @response = click_button "Save"
437
- @player = MerbAdmin::AbstractModel.new("Player").first
438
- end
439
-
440
- it "should create an object with correct associations" do
441
- @draft.reload
442
- @player.draft.should eql(@draft)
443
- end
444
- end
445
-
446
- describe "create with has-many association", :given => "three teams exist" do
447
- before(:each) do
448
- visit(url(:merb_admin_new, :model_name => "league"))
449
- fill_in "Name", :with => "National League"
450
- fill_in "Teams", :with => @teams[0].id.to_s
451
- @response = click_button "Save"
452
- @league = MerbAdmin::AbstractModel.new("League").first
453
- end
454
-
455
- it "should create an object with correct associations" do
456
- @teams[0].reload
457
- @league.teams.should include(@teams[0])
458
- end
459
-
460
- it "should not create an object with incorrect associations" do
461
- @league.teams.should_not include(@teams[1])
462
- @league.teams.should_not include(@teams[2])
463
- end
464
- end
465
-
466
- describe "create with uniqueness constraint violated", :given => "a player exists" do
467
- before(:each) do
468
- visit(url(:merb_admin_new, :model_name => "player"))
469
- fill_in "Name", :with => @player.name
470
- fill_in "Number", :with => @player.number.to_s
471
- fill_in "Position", :with => @player.position
472
- fill_in "Team", :with => @player.team_id.to_s
473
- @response = click_button "Save"
474
- end
475
-
476
- it "should show an error message" do
477
- @response.body.should contain("There is already a player with that number on this team")
478
- end
479
- end
480
-
481
- describe "create with invalid object" do
482
- before(:each) do
483
- @response = visit(url(:merb_admin_create, :model_name => "player"), :post, :params => {:player => {}})
484
- end
485
-
486
- it "should show an error message" do
487
- @response.body.should contain("Player failed to be created")
488
- end
489
- end
490
-
491
- describe "edit", :given => "a player exists" do
492
- before(:each) do
493
- @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
494
- end
495
-
496
- it "should respond sucessfully" do
497
- @response.should be_successful
498
- end
499
-
500
- it "should show \"Edit model\"" do
501
- @response.body.should contain("Edit player")
502
- end
503
-
504
- it "should show required fields as \"Required\"" do
505
- @response.body.should contain(/Name\n\s*Required/)
506
- @response.body.should contain(/Number\n\s*Required/)
507
- end
508
-
509
- it "should show non-required fields as \"Optional\"" do
510
- @response.body.should contain(/Position\n\s*Optional/)
511
- @response.body.should contain(/Born on\n\s*Optional/)
512
- @response.body.should contain(/Notes\n\s*Optional/)
513
- @response.body.should contain(/Draft\n\s*Optional/)
514
- @response.body.should contain(/Team\n\s*Optional/)
515
- end
516
- end
517
-
518
- describe "edit with has-one association", :given => ["a player exists", "a draft exists"] do
519
- before(:each) do
520
- @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
521
- end
522
-
523
- it "should respond sucessfully" do
524
- @response.should be_successful
525
- end
526
-
527
- it "should show associated objects" do
528
- @response.body.should contain(/DraftDraft #\d+/)
529
- end
530
- end
531
-
532
- describe "edit with has-many association", :given => ["a player exists", "three teams exist"] do
533
- before(:each) do
534
- @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
535
- end
536
-
537
- it "should respond sucessfully" do
538
- @response.should be_successful
539
- end
540
-
541
- it "should show associated objects" do
542
- @response.body.should contain(/TeamTeam 1Team 2Team 3/)
543
- end
544
- end
545
-
546
- describe "edit with missing object" do
547
- before(:each) do
548
- @response = visit(url(:merb_admin_edit, :model_name => "player", :id => 1))
549
- end
550
-
551
- it "should raise NotFound" do
552
- @response.status.should equal(404)
553
- end
554
- end
555
-
556
- describe "edit with missing label", :given => ["a player exists", "three teams with no name exist"] do
557
- before(:each) do
558
- @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
559
- end
560
-
561
- it "should respond sucessfully" do
562
- @response.should be_successful
563
- end
564
- end
565
-
566
- describe "update", :given => "a player exists" do
567
- before(:each) do
568
- visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
569
- fill_in "Name", :with => "Jackie Robinson"
570
- fill_in "Number", :with => "42"
571
- fill_in "Position", :with => "Second baseman"
572
- @response = click_button "Save"
573
- @player = MerbAdmin::AbstractModel.new("Player").first
574
- end
575
-
576
- it "should be successful" do
577
- @response.should be_successful
578
- end
579
-
580
- it "should update an object with correct attributes" do
581
- @player.name.should eql("Jackie Robinson")
582
- @player.number.should eql(42)
583
- @player.position.should eql("Second baseman")
584
- end
585
- end
586
-
587
- describe "update and edit", :given => "a player exists" do
588
- before(:each) do
589
- visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
590
- fill_in "Name", :with => "Jackie Robinson"
591
- fill_in "Number", :with => "42"
592
- fill_in "Position", :with => "Second baseman"
593
- @response = click_button "Save and continue"
594
- @player = MerbAdmin::AbstractModel.new("Player").first
595
- end
596
-
597
- it "should be successful" do
598
- @response.should be_successful
599
- end
600
-
601
- it "should update an object with correct attributes" do
602
- @player.name.should eql("Jackie Robinson")
603
- @player.number.should eql(42)
604
- @player.position.should eql("Second baseman")
605
- end
606
- end
607
-
608
- describe "update and add another", :given => "a player exists" do
609
- before(:each) do
610
- visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
611
- fill_in "Name", :with => "Jackie Robinson"
612
- fill_in "Number", :with => "42"
613
- fill_in "Position", :with => "Second baseman"
614
- @response = click_button "Save and add another"
615
- @player = MerbAdmin::AbstractModel.new("Player").first
616
- end
617
-
618
- it "should be successful" do
619
- @response.should be_successful
620
- end
621
-
622
- it "should update an object with correct attributes" do
623
- @player.name.should eql("Jackie Robinson")
624
- @player.number.should eql(42)
625
- @player.position.should eql("Second baseman")
626
- end
627
- end
628
-
629
- describe "update with has-one association", :given => ["a player exists", "a draft exists"] do
630
- before(:each) do
631
- visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
632
- fill_in "Name", :with => "Jackie Robinson"
633
- fill_in "Number", :with => "42"
634
- fill_in "Position", :with => "Second baseman"
635
- fill_in "Draft", :with => @draft.id.to_s
636
- @response = click_button "Save"
637
- @player = MerbAdmin::AbstractModel.new("Player").first
638
- # @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}})
639
- end
640
-
641
- it "should update an object with correct attributes" do
642
- @player.name.should eql("Jackie Robinson")
643
- @player.number.should eql(42)
644
- @player.position.should eql("Second baseman")
645
- end
646
-
647
- it "should update an object with correct associations" do
648
- @draft.reload
649
- @player.draft.should eql(@draft)
650
- end
651
- end
652
-
653
- describe "update with has-many association", :given => ["a league exists", "three teams exist"] do
654
- before(:each) do
655
- visit(url(:merb_admin_edit, :model_name => "league", :id => @league.id))
656
- fill_in "Name", :with => "National League"
657
- fill_in "Teams", :with => @teams[0].id.to_s
658
- @response = click_button "Save"
659
- @league = MerbAdmin::AbstractModel.new("League").first
660
- end
661
-
662
- it "should update an object with correct attributes" do
663
- @league.name.should eql("National League")
664
- end
665
-
666
- it "should update an object with correct associations" do
667
- @teams[0].reload
668
- @league.teams.should include(@teams[0])
669
- end
670
-
671
- it "should not update an object with incorrect associations" do
672
- @league.teams.should_not include(@teams[1])
673
- @league.teams.should_not include(@teams[2])
674
- end
675
- end
676
-
677
- describe "update with missing object" do
678
- before(:each) do
679
- @response = visit(url(:merb_admin_update, :model_name => "player", :id => 1), :put, {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
680
- end
681
-
682
- it "should raise NotFound" do
683
- @response.status.should equal(404)
684
- end
685
- end
686
-
687
- describe "update with invalid object", :given => "a player exists" do
688
- before(:each) do
689
- visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
690
- fill_in "Name", :with => "Jackie Robinson"
691
- fill_in "Number", :with => "a"
692
- fill_in "Position", :with => "Second baseman"
693
- @response = click_button "Save"
694
- @player = MerbAdmin::AbstractModel.new("Player").first
695
- end
696
-
697
- it "should show an error message" do
698
- @response.body.should contain("Player failed to be updated")
699
- end
700
- end
701
-
702
- describe "delete", :given => "a player exists" do
703
- before(:each) do
704
- @response = visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
705
- end
706
-
707
- it "should respond sucessfully" do
708
- @response.should be_successful
709
- end
710
-
711
- it "should show \"Delete model\"" do
712
- @response.body.should contain("Delete player")
713
- end
714
- end
715
-
716
- describe "delete with missing object" do
717
- before(:each) do
718
- @response = visit(url(:merb_admin_delete, :model_name => "player", :id => 1))
719
- end
720
-
721
- it "should raise NotFound" do
722
- @response.status.should equal(404)
723
- end
724
- end
725
-
726
- describe "delete with missing label" do
727
- before(:each) do
728
- @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
729
- @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)
730
- @response = visit(url(:merb_admin_delete, :model_name => "league", :id => @league.id))
731
- end
732
-
733
- it "should respond sucessfully" do
734
- @response.should be_successful
735
- end
736
- end
737
-
738
- describe "destroy", :given => "a player exists" do
739
- before(:each) do
740
- visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
741
- @response = click_button "Yes, I'm sure"
742
- @player = MerbAdmin::AbstractModel.new("Player").first
743
- end
744
-
745
- it "should be successful" do
746
- @response.should be_successful
747
- end
748
-
749
- it "should destroy an object" do
750
- @player.should be_nil
751
- end
752
- end
753
-
754
- describe "destroy with missing object" do
755
- before(:each) do
756
- @response = visit(url(:merb_admin_destroy, :model_name => "player", :id => 1), :delete)
757
- end
758
-
759
- it "should raise NotFound" do
760
- @response.status.should equal(404)
761
- end
762
- end
763
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
3
+
4
+ describe "MerbAdmin" do
5
+ before(:each) do
6
+ mount_slice
7
+ MerbAdmin::AbstractModel.new("Draft").destroy_all!
8
+ MerbAdmin::AbstractModel.new("Player").destroy_all!
9
+ MerbAdmin::AbstractModel.new("Team").destroy_all!
10
+ MerbAdmin::AbstractModel.new("Division").destroy_all!
11
+ MerbAdmin::AbstractModel.new("League").destroy_all!
12
+ end
13
+
14
+ describe "dashboard" do
15
+ before(:each) do
16
+ @response = visit(url(:merb_admin_dashboard))
17
+ end
18
+
19
+ it "should respond sucessfully" do
20
+ @response.should be_successful
21
+ end
22
+
23
+ it "should show \"Site administration\"" do
24
+ @response.body.should contain("Site administration")
25
+ end
26
+ end
27
+
28
+ describe "dashboard with excluded models" do
29
+ before(:each) do
30
+ MerbAdmin[:excluded_models] = ["Player"]
31
+ @response = visit(url(:merb_admin_dashboard))
32
+ MerbAdmin[:excluded_models] = []
33
+ end
34
+
35
+ it "should respond sucessfully" do
36
+ @response.should be_successful
37
+ end
38
+
39
+ it "should not contain excluded models" do
40
+ @response.body.should_not contain(/Player/)
41
+ end
42
+ end
43
+
44
+ describe "list" do
45
+ before(:each) do
46
+ @response = visit(url(:merb_admin_list, :model_name => "player"))
47
+ end
48
+
49
+ it "should respond sucessfully" do
50
+ @response.should be_successful
51
+ end
52
+
53
+ it "should show \"Select model to edit\"" do
54
+ @response.body.should contain("Select player to edit")
55
+ end
56
+
57
+ it "should show filters" do
58
+ @response.body.should contain(/Filter\n\s*By Retired\n\s*All\n\s*Yes\n\s*No\n\s*By Injured\n\s*All\n\s*Yes\n\s*No/)
59
+ end
60
+
61
+ it "should show column headers" do
62
+ @response.body.should contain(/Id\n\s*Created at\n\s*Updated at\n\s*Team\n\s*Name\n\s*Position\n\s*Number\n\s*Retired\n\s*Injured\n\s*Born on\n\s*Notes/)
63
+ end
64
+ end
65
+
66
+ describe "list with sort" do
67
+ before(:each) do
68
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
69
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
70
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Brooklyn Dodgers", :manager => "Walter Alston", :founded => 1883, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
71
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 32, :name => "Sandy Koufax", :position => "Starting pitcher")
72
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
73
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name")
74
+ end
75
+
76
+ it "should respond sucessfully" do
77
+ @response.should be_successful
78
+ end
79
+
80
+ it "should be sorted correctly" do
81
+ @response.body.should contain(/Jackie Robinson.*Sandy Koufax/m)
82
+ end
83
+ end
84
+
85
+ describe "list with reverse sort" do
86
+ before(:each) do
87
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
88
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
89
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Brooklyn Dodgers", :manager => "Walter Alston", :founded => 1883, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
90
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 32, :name => "Sandy Koufax", :position => "Starting pitcher")
91
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
92
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :sort => "name", :sort_reverse => "true")
93
+ end
94
+
95
+ it "should respond sucessfully" do
96
+ @response.should be_successful
97
+ end
98
+
99
+ it "should be sorted correctly" do
100
+ @response.body.should contain(/Sandy Koufax.*Jackie Robinson/m)
101
+ end
102
+ end
103
+
104
+ describe "list with query" do
105
+ before(:each) do
106
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
107
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
108
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Brooklyn Dodgers", :manager => "Walter Alston", :founded => 1883, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
109
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 32, :name => "Sandy Koufax", :position => "Starting pitcher")
110
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 42, :name => "Jackie Robinson", :position => "Second baseman")
111
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Jackie Robinson")
112
+ end
113
+
114
+ it "should respond sucessfully" do
115
+ @response.should be_successful
116
+ end
117
+
118
+ it "should show a correct result" do
119
+ @response.body.should contain("Jackie Robinson")
120
+ end
121
+
122
+ it "should not contain an incorrect result" do
123
+ @response.body.should_not contain("Sandy Koufax")
124
+ end
125
+ end
126
+
127
+ describe "list with query and boolean filter" do
128
+ before(:each) do
129
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
130
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
131
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "New York Mets", :manager => "Jerry Manuel", :founded => 1962, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
132
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 41, :name => "Tom Seaver", :position => "Starting pitcher", :retired => true, :injured => true)
133
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 14, :name => "Gil Hodges", :position => "First baseman", :retired => true, :injured => false)
134
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 7, :name => "José Reyes", :position => "Shortstop", :retired => false, :injured => true)
135
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
136
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :query => "Tom Seaver", :filter => {:injured => "true"})
137
+ end
138
+
139
+ it "should respond sucessfully" do
140
+ @response.should be_successful
141
+ end
142
+
143
+ it "should show a correct result" do
144
+ @response.body.should contain("Tom Seaver")
145
+ end
146
+
147
+ it "should not contain an incorrect result" do
148
+ @response.body.should_not contain("Gil Hodges")
149
+ @response.body.should_not contain("José Reyes")
150
+ @response.body.should_not contain("David Wright")
151
+ end
152
+ end
153
+
154
+
155
+ describe "list with boolean filter" do
156
+ before(:each) do
157
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
158
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
159
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "New York Mets", :manager => "Jerry Manuel", :founded => 1962, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
160
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 7, :name => "José Reyes", :position => "Shortstop", :retired => false, :injured => true)
161
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
162
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:injured => "true"})
163
+ end
164
+
165
+ it "should respond sucessfully" do
166
+ @response.should be_successful
167
+ end
168
+
169
+ it "should show a correct result" do
170
+ @response.body.should contain("José Reyes")
171
+ end
172
+
173
+ it "should not contain an incorrect result" do
174
+ @response.body.should_not contain("David Wright")
175
+ end
176
+ end
177
+
178
+ describe "list with boolean filters" do
179
+ before(:each) do
180
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "National League")
181
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "National League East")
182
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "New York Mets", :manager => "Jerry Manuel", :founded => 1962, :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
183
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 41, :name => "Tom Seaver", :position => "Starting pitcher", :retired => true, :injured => true)
184
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 14, :name => "Gil Hodges", :position => "First baseman", :retired => true, :injured => false)
185
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 7, :name => "José Reyes", :position => "Shortstop", :retired => false, :injured => true)
186
+ MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 5, :name => "David Wright", :position => "Third baseman", :retired => false, :injured => false)
187
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :filter => {:retired => "true", :injured => "true"})
188
+ end
189
+
190
+ it "should respond sucessfully" do
191
+ @response.should be_successful
192
+ end
193
+
194
+ it "should show a correct result" do
195
+ @response.body.should contain("Tom Seaver")
196
+ end
197
+
198
+ it "should not contain an incorrect result" do
199
+ @response.body.should_not contain("Gil Hodges")
200
+ @response.body.should_not contain("José Reyes")
201
+ @response.body.should_not contain("David Wright")
202
+ end
203
+ end
204
+
205
+ describe "list with 2 objects" do
206
+ before(:each) do
207
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
208
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
209
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
210
+ @players = []
211
+ (1..2).each do |number|
212
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => number, :name => "Player #{number}")
213
+ end
214
+ MerbAdmin[:per_page] = 1
215
+ @response = visit(url(:merb_admin_list, :model_name => "player"))
216
+ MerbAdmin[:per_page] = 100
217
+ end
218
+
219
+ it "should respond sucessfully" do
220
+ @response.should be_successful
221
+ end
222
+
223
+ it "should show \"2 results\"" do
224
+ @response.body.should contain("2 players")
225
+ end
226
+ end
227
+
228
+ describe "list with 20 objects" do
229
+ before(:each) do
230
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
231
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
232
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
233
+ @players = []
234
+ (1..20).each do |number|
235
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => number, :name => "Player #{number}")
236
+ end
237
+ MerbAdmin[:per_page] = 1
238
+ @response = visit(url(:merb_admin_list, :model_name => "player"))
239
+ MerbAdmin[:per_page] = 100
240
+ end
241
+
242
+ it "should respond sucessfully" do
243
+ @response.should be_successful
244
+ end
245
+
246
+ it "should show \"20 results\"" do
247
+ @response.body.should contain("20 players")
248
+ end
249
+ end
250
+
251
+ describe "list with 20 objects, page 8" do
252
+ before(:each) do
253
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
254
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
255
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
256
+ @players = []
257
+ (1..20).each do |number|
258
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => number, :name => "Player #{number}")
259
+ end
260
+ MerbAdmin[:per_page] = 1
261
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 8)
262
+ MerbAdmin[:per_page] = 100
263
+ end
264
+
265
+ it "should respond sucessfully" do
266
+ @response.should be_successful
267
+ end
268
+
269
+ it "should paginate correctly" do
270
+ @response.body.should contain(/1 2[^0-9]*5 6 7 8 9 10 11[^0-9]*19 20/)
271
+ end
272
+ end
273
+
274
+ describe "list with 20 objects, page 17" do
275
+ before(:each) do
276
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
277
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
278
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
279
+ @players = []
280
+ (1..20).each do |number|
281
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => number, :name => "Player #{number}")
282
+ end
283
+ MerbAdmin[:per_page] = 1
284
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :page => 17)
285
+ MerbAdmin[:per_page] = 100
286
+ end
287
+
288
+ it "should respond sucessfully" do
289
+ @response.should be_successful
290
+ end
291
+
292
+ it "should paginate correctly" do
293
+ @response.body.should contain(/1 2[^0-9]*12 13 14 15 16 17 18 19 20/)
294
+ end
295
+ end
296
+
297
+ describe "list show all" do
298
+ before(:each) do
299
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
300
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
301
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
302
+ @players = []
303
+ (1..2).each do |number|
304
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => number, :name => "Player #{number}")
305
+ end
306
+ MerbAdmin[:per_page] = 1
307
+ @response = visit(url(:merb_admin_list, :model_name => "player"), :get, :all => true)
308
+ MerbAdmin[:per_page] = 100
309
+ end
310
+
311
+ it "should respond sucessfully" do
312
+ @response.should be_successful
313
+ end
314
+ end
315
+
316
+ describe "new" do
317
+ before(:each) do
318
+ @response = visit(url(:merb_admin_new, :model_name => "player"))
319
+ end
320
+
321
+ it "should respond sucessfully" do
322
+ @response.should be_successful
323
+ end
324
+
325
+ it "should show \"New model\"" do
326
+ @response.body.should contain("New player")
327
+ end
328
+
329
+ it "should show required fields as \"Required\"" do
330
+ @response.body.should contain(/Name\n\s*Required/)
331
+ @response.body.should contain(/Number\n\s*Required/)
332
+ end
333
+
334
+ it "should show non-required fields as \"Optional\"" do
335
+ @response.body.should contain(/Position\n\s*Optional/)
336
+ @response.body.should contain(/Born on\n\s*Optional/)
337
+ @response.body.should contain(/Notes\n\s*Optional/)
338
+ @response.body.should contain(/Draft\n\s*Optional/)
339
+ @response.body.should contain(/Team\n\s*Optional/)
340
+ end
341
+ end
342
+
343
+ describe "new with has-one association" do
344
+ before(:each) do
345
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
346
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
347
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
348
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
349
+ @draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => @player.id, :team_id => @team.id, :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
350
+ @response = visit(url(:merb_admin_new, :model_name => "player"))
351
+ end
352
+
353
+ it "should respond sucessfully" do
354
+ @response.should be_successful
355
+ end
356
+
357
+ it "should show associated objects" do
358
+ @response.body.should contain(/DraftDraft #\d+/)
359
+ end
360
+ end
361
+
362
+ describe "new with has-many association" do
363
+ before(:each) do
364
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
365
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
366
+ @teams = []
367
+ (1..3).each do |number|
368
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
369
+ end
370
+ @response = visit(url(:merb_admin_new, :model_name => "player"))
371
+ end
372
+
373
+ it "should respond sucessfully" do
374
+ @response.should be_successful
375
+ end
376
+
377
+ it "should show associated objects" do
378
+ @response.body.should contain(/TeamTeam 1Team 2Team 3/)
379
+ end
380
+ end
381
+
382
+ describe "new with missing label" do
383
+ before(:each) do
384
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
385
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
386
+ @teams = []
387
+ (1..3).each do |number|
388
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
389
+ end
390
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @teams[0].id, :number => 1, :name => "Player 1")
391
+ @response = visit(url(:merb_admin_new, :model_name => "player"))
392
+ end
393
+
394
+ it "should respond sucessfully" do
395
+ @response.should be_successful
396
+ end
397
+ end
398
+
399
+ describe "create" do
400
+ before(:each) do
401
+ visit(url(:merb_admin_new, :model_name => "player"))
402
+ fill_in "Name", :with => "Jackie Robinson"
403
+ fill_in "Number", :with => "42"
404
+ fill_in "Position", :with => "Second baseman"
405
+ @response = click_button "Save"
406
+ @player = MerbAdmin::AbstractModel.new("Player").last
407
+ end
408
+
409
+ it "should be successful" do
410
+ @response.should be_successful
411
+ end
412
+
413
+ it "should create an object with correct attributes" do
414
+ @player.name.should eql("Jackie Robinson")
415
+ @player.number.should eql(42)
416
+ @player.position.should eql("Second baseman")
417
+ end
418
+ end
419
+
420
+ describe "create and edit" do
421
+ before(:each) do
422
+ visit(url(:merb_admin_new, :model_name => "player"))
423
+ fill_in "Name", :with => "Jackie Robinson"
424
+ fill_in "Number", :with => "42"
425
+ fill_in "Position", :with => "Second baseman"
426
+ @response = click_button "Save and continue editing"
427
+ @player = MerbAdmin::AbstractModel.new("Player").last
428
+ end
429
+
430
+ it "should be successful" do
431
+ @response.should be_successful
432
+ end
433
+
434
+ it "should create an object with correct attributes" do
435
+ @player.name.should eql("Jackie Robinson")
436
+ @player.number.should eql(42)
437
+ @player.position.should eql("Second baseman")
438
+ end
439
+ end
440
+
441
+ describe "create and add another" do
442
+ before(:each) do
443
+ visit(url(:merb_admin_new, :model_name => "player"))
444
+ fill_in "Name", :with => "Jackie Robinson"
445
+ fill_in "Number", :with => "42"
446
+ fill_in "Position", :with => "Second baseman"
447
+ @response = click_button "Save and add another"
448
+ @player = MerbAdmin::AbstractModel.new("Player").last
449
+ end
450
+
451
+ it "should be successful" do
452
+ @response.should be_successful
453
+ end
454
+
455
+ it "should create an object with correct attributes" do
456
+ @player.name.should eql("Jackie Robinson")
457
+ @player.number.should eql(42)
458
+ @player.position.should eql("Second baseman")
459
+ end
460
+ end
461
+
462
+ describe "create with has-one association" do
463
+ before(:each) do
464
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
465
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
466
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
467
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
468
+ @draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => @player.id, :team_id => @team.id, :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
469
+ visit(url(:merb_admin_new, :model_name => "player"))
470
+ fill_in "Name", :with => "Jackie Robinson"
471
+ fill_in "Number", :with => 42
472
+ fill_in "Position", :with => "Second baseman"
473
+ fill_in "Draft", :with => @draft.id.to_s
474
+ @response = click_button "Save"
475
+ @player = MerbAdmin::AbstractModel.new("Player").last
476
+ @draft.reload
477
+ end
478
+
479
+ it "should create an object with correct associations" do
480
+ @player.draft.should eql(@draft)
481
+ end
482
+ end
483
+
484
+ describe "create with has-many association" do
485
+ before(:each) do
486
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
487
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
488
+ @teams = []
489
+ (1..3).each do |number|
490
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
491
+ end
492
+ visit(url(:merb_admin_new, :model_name => "league"))
493
+ fill_in "Name", :with => "National League"
494
+ fill_in "Teams", :with => @teams[0].id.to_s
495
+ @response = click_button "Save"
496
+ @league = MerbAdmin::AbstractModel.new("League").last
497
+ @teams.each do |team|
498
+ team.reload
499
+ end
500
+ end
501
+
502
+ it "should create an object with correct associations" do
503
+ @league.teams.should include(@teams[0])
504
+ end
505
+
506
+ it "should not create an object with incorrect associations" do
507
+ @league.teams.should_not include(@teams[1])
508
+ @league.teams.should_not include(@teams[2])
509
+ end
510
+ end
511
+
512
+ describe "create with uniqueness constraint violated" do
513
+ before(:each) do
514
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
515
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
516
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
517
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
518
+ visit(url(:merb_admin_new, :model_name => "player"))
519
+ fill_in "Name", :with => @player.name
520
+ fill_in "Number", :with => @player.number.to_s
521
+ fill_in "Position", :with => @player.position
522
+ fill_in "Team", :with => @player.team_id.to_s
523
+ @response = click_button "Save"
524
+ end
525
+
526
+ it "should show an error message" do
527
+ @response.body.should contain("There is already a player with that number on this team")
528
+ end
529
+ end
530
+
531
+ describe "create with invalid object" do
532
+ before(:each) do
533
+ @response = visit(url(:merb_admin_create, :model_name => "player"), :post, :params => {:player => {}})
534
+ end
535
+
536
+ it "should show an error message" do
537
+ @response.body.should contain("Player failed to be created")
538
+ end
539
+ end
540
+
541
+ describe "edit" do
542
+ before(:each) do
543
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
544
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
545
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
546
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
547
+ @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
548
+ end
549
+
550
+ it "should respond sucessfully" do
551
+ @response.should be_successful
552
+ end
553
+
554
+ it "should show \"Edit model\"" do
555
+ @response.body.should contain("Edit player")
556
+ end
557
+
558
+ it "should show required fields as \"Required\"" do
559
+ @response.body.should contain(/Name\n\s*Required/)
560
+ @response.body.should contain(/Number\n\s*Required/)
561
+ end
562
+
563
+ it "should show non-required fields as \"Optional\"" do
564
+ @response.body.should contain(/Position\n\s*Optional/)
565
+ @response.body.should contain(/Born on\n\s*Optional/)
566
+ @response.body.should contain(/Notes\n\s*Optional/)
567
+ @response.body.should contain(/TeamTeam 1\n\s*Optional/)
568
+ @response.body.should contain(/Draft\n\s*Optional/)
569
+ end
570
+ end
571
+
572
+ describe "edit with has-one association" do
573
+ before(:each) do
574
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
575
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
576
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
577
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
578
+ @draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => @player.id, :team_id => @team.id, :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
579
+ @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
580
+ end
581
+
582
+ it "should respond sucessfully" do
583
+ @response.should be_successful
584
+ end
585
+
586
+ it "should show associated objects" do
587
+ @response.body.should contain(/DraftDraft #\d+/)
588
+ end
589
+ end
590
+
591
+ describe "edit with has-many association" do
592
+ before(:each) do
593
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
594
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
595
+ @teams = []
596
+ (1..3).each do |number|
597
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
598
+ end
599
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @teams[0].id, :number => 1, :name => "Player 1")
600
+ @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
601
+ end
602
+
603
+ it "should respond sucessfully" do
604
+ @response.should be_successful
605
+ end
606
+
607
+ it "should show associated objects" do
608
+ @response.body.should contain(/TeamTeam 1Team 2Team 3/)
609
+ end
610
+ end
611
+
612
+ describe "edit with missing object" do
613
+ before(:each) do
614
+ @response = visit(url(:merb_admin_edit, :model_name => "player", :id => 1))
615
+ end
616
+
617
+ it "should raise NotFound" do
618
+ @response.status.should equal(404)
619
+ end
620
+ end
621
+
622
+ describe "edit with missing label" do
623
+ before(:each) do
624
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
625
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
626
+ @teams = []
627
+ (1..3).each do |number|
628
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
629
+ end
630
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @teams[0].id, :number => 1, :name => "Player 1")
631
+ @response = visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
632
+ end
633
+
634
+ it "should respond sucessfully" do
635
+ @response.should be_successful
636
+ end
637
+ end
638
+
639
+ describe "update" do
640
+ before(:each) do
641
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
642
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
643
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
644
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
645
+ visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
646
+ fill_in "Name", :with => "Jackie Robinson"
647
+ fill_in "Number", :with => "42"
648
+ fill_in "Position", :with => "Second baseman"
649
+ @response = click_button "Save"
650
+ @player.reload
651
+ end
652
+
653
+ it "should be successful" do
654
+ @response.should be_successful
655
+ end
656
+
657
+ it "should update an object with correct attributes" do
658
+ @player.name.should eql("Jackie Robinson")
659
+ @player.number.should eql(42)
660
+ @player.position.should eql("Second baseman")
661
+ end
662
+ end
663
+
664
+ describe "update and edit" do
665
+ before(:each) do
666
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
667
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
668
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
669
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
670
+ visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
671
+ fill_in "Name", :with => "Jackie Robinson"
672
+ fill_in "Number", :with => "42"
673
+ fill_in "Position", :with => "Second baseman"
674
+ @response = click_button "Save and continue"
675
+ @player.reload
676
+ end
677
+
678
+ it "should be successful" do
679
+ @response.should be_successful
680
+ end
681
+
682
+ it "should update an object with correct attributes" do
683
+ @player.name.should eql("Jackie Robinson")
684
+ @player.number.should eql(42)
685
+ @player.position.should eql("Second baseman")
686
+ end
687
+ end
688
+
689
+ describe "update and add another" do
690
+ before(:each) do
691
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
692
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
693
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
694
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
695
+ visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
696
+ fill_in "Name", :with => "Jackie Robinson"
697
+ fill_in "Number", :with => "42"
698
+ fill_in "Position", :with => "Second baseman"
699
+ @response = click_button "Save and add another"
700
+ @player.reload
701
+ end
702
+
703
+ it "should be successful" do
704
+ @response.should be_successful
705
+ end
706
+
707
+ it "should update an object with correct attributes" do
708
+ @player.name.should eql("Jackie Robinson")
709
+ @player.number.should eql(42)
710
+ @player.position.should eql("Second baseman")
711
+ end
712
+ end
713
+
714
+ describe "update with has-one association" do
715
+ before(:each) do
716
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
717
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
718
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
719
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
720
+ @draft = MerbAdmin::AbstractModel.new("Draft").create(:player_id => @player.id, :team_id => @team.id, :date => Date.today, :round => rand(50), :pick => rand(30), :overall => rand(1500))
721
+ visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
722
+ fill_in "Name", :with => "Jackie Robinson"
723
+ fill_in "Number", :with => "42"
724
+ fill_in "Position", :with => "Second baseman"
725
+ fill_in "Draft", :with => @draft.id.to_s
726
+ @response = click_button "Save"
727
+ @player.reload
728
+ @draft.reload
729
+ end
730
+
731
+ it "should update an object with correct attributes" do
732
+ @player.name.should eql("Jackie Robinson")
733
+ @player.number.should eql(42)
734
+ @player.position.should eql("Second baseman")
735
+ end
736
+
737
+ it "should update an object with correct associations" do
738
+ @player.draft.should eql(@draft)
739
+ end
740
+ end
741
+
742
+ describe "update with has-many association" do
743
+ before(:each) do
744
+ @leagues = []
745
+ (1..2).each do |number|
746
+ @leagues << MerbAdmin::AbstractModel.new("League").create(:name => "League #{number}")
747
+ end
748
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @leagues[1].id, :name => "Division 1")
749
+ @teams = []
750
+ (1..3).each do |number|
751
+ @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => @leagues[1].id, :division_id => @division.id, :name => "Team #{number}", :manager => "Manager #{number}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
752
+ end
753
+ visit(url(:merb_admin_edit, :model_name => "league", :id => @leagues[0].id))
754
+ fill_in "Name", :with => "National League"
755
+ fill_in "Teams", :with => @teams[0].id.to_s
756
+ @response = click_button "Save"
757
+ @leagues[0].reload
758
+ end
759
+
760
+ it "should update an object with correct attributes" do
761
+ @leagues[0].name.should eql("National League")
762
+ end
763
+
764
+ it "should update an object with correct associations" do
765
+ @leagues[0].teams.should include(@teams[0])
766
+ end
767
+
768
+ it "should not update an object with incorrect associations" do
769
+ @leagues[0].teams.should_not include(@teams[1])
770
+ @leagues[0].teams.should_not include(@teams[2])
771
+ end
772
+ end
773
+
774
+ describe "update with missing object" do
775
+ before(:each) do
776
+ @response = visit(url(:merb_admin_update, :model_name => "player", :id => 1), :put, {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
777
+ end
778
+
779
+ it "should raise NotFound" do
780
+ @response.status.should equal(404)
781
+ end
782
+ end
783
+
784
+ describe "update with invalid object" do
785
+ before(:each) do
786
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
787
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
788
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
789
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
790
+ visit(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
791
+ fill_in "Name", :with => "Jackie Robinson"
792
+ fill_in "Number", :with => "a"
793
+ fill_in "Position", :with => "Second baseman"
794
+ @response = click_button "Save"
795
+ @player.reload
796
+ end
797
+
798
+ it "should show an error message" do
799
+ @response.body.should contain("Player failed to be updated")
800
+ end
801
+ end
802
+
803
+ describe "delete" do
804
+ before(:each) do
805
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
806
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
807
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
808
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
809
+ @response = visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
810
+ end
811
+
812
+ it "should respond sucessfully" do
813
+ @response.should be_successful
814
+ end
815
+
816
+ it "should show \"Delete model\"" do
817
+ @response.body.should contain("Delete player")
818
+ end
819
+ end
820
+
821
+ describe "delete with missing object" do
822
+ before(:each) do
823
+ @response = visit(url(:merb_admin_delete, :model_name => "player", :id => 1))
824
+ end
825
+
826
+ it "should raise NotFound" do
827
+ @response.status.should equal(404)
828
+ end
829
+ end
830
+
831
+ describe "delete with missing label" do
832
+ before(:each) do
833
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
834
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
835
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
836
+ @response = visit(url(:merb_admin_delete, :model_name => "league", :id => @league.id))
837
+ end
838
+
839
+ it "should respond sucessfully" do
840
+ @response.should be_successful
841
+ end
842
+ end
843
+
844
+ describe "destroy" do
845
+ before(:each) do
846
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
847
+ @division = MerbAdmin::AbstractModel.new("Division").create(:league_id => @league.id, :name => "Division 1")
848
+ @team = MerbAdmin::AbstractModel.new("Team").create(:league_id => @league.id, :division_id => @division.id, :name => "Team 1", :manager => "Manager 1", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
849
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => @team.id, :number => 1, :name => "Player 1")
850
+ visit(url(:merb_admin_delete, :model_name => "player", :id => @player.id))
851
+ @response = click_button "Yes, I'm sure"
852
+ @player = MerbAdmin::AbstractModel.new("Player").first
853
+ end
854
+
855
+ it "should be successful" do
856
+ @response.should be_successful
857
+ end
858
+
859
+ it "should destroy an object" do
860
+ @player.should be_nil
861
+ end
862
+ end
863
+
864
+ describe "destroy with missing object" do
865
+ before(:each) do
866
+ @response = visit(url(:merb_admin_destroy, :model_name => "player", :id => 1), :delete)
867
+ end
868
+
869
+ it "should raise NotFound" do
870
+ @response.status.should equal(404)
871
+ end
872
+ end
873
+ end