merb-admin 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +29 -27
  2. data/Gemfile +24 -22
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +20 -20
  5. data/README.rdoc +54 -58
  6. data/Rakefile +11 -44
  7. data/app/controllers/application.rb +6 -6
  8. data/app/controllers/main.rb +191 -191
  9. data/app/helpers/application_helper.rb +64 -64
  10. data/app/helpers/main_helper.rb +167 -167
  11. data/app/models/.gitkeep +0 -0
  12. data/app/views/layout/_message.html.erb +10 -10
  13. data/app/views/layout/dashboard.html.erb +34 -34
  14. data/app/views/layout/form.html.erb +48 -48
  15. data/app/views/layout/list.html.erb +42 -42
  16. data/app/views/main/_belongs_to.html.erb +29 -29
  17. data/app/views/main/_big_decimal.html.erb +12 -12
  18. data/app/views/main/_boolean.html.erb +7 -7
  19. data/app/views/main/_date.html.erb +12 -12
  20. data/app/views/main/_datetime.html.erb +12 -12
  21. data/app/views/main/_float.html.erb +12 -12
  22. data/app/views/main/_has_many.html.erb +16 -16
  23. data/app/views/main/_has_one.html.erb +30 -30
  24. data/app/views/main/_integer.html.erb +12 -12
  25. data/app/views/main/_properties.html.erb +18 -18
  26. data/app/views/main/_string.html.erb +15 -15
  27. data/app/views/main/_text.html.erb +11 -11
  28. data/app/views/main/_time.html.erb +12 -12
  29. data/app/views/main/_timestamp.html.erb +12 -12
  30. data/app/views/main/delete.html.erb +28 -28
  31. data/app/views/main/edit.html.erb +19 -19
  32. data/app/views/main/index.html.erb +22 -22
  33. data/app/views/main/list.html.erb +93 -93
  34. data/app/views/main/new.html.erb +16 -16
  35. data/config/init.rb +30 -0
  36. data/config/router.rb +4 -0
  37. data/lib/abstract_model.rb +84 -86
  38. data/lib/active_record_support.rb +147 -147
  39. data/lib/datamapper_support.rb +139 -140
  40. data/lib/generic_support.rb +13 -13
  41. data/lib/merb-admin.rb +99 -99
  42. data/lib/merb-admin/merbtasks.rb +103 -103
  43. data/lib/merb-admin/slicetasks.rb +174 -174
  44. data/lib/merb-admin/spectasks.rb +55 -55
  45. data/lib/merb-admin/version.rb +3 -0
  46. data/lib/sequel_support.rb +275 -275
  47. data/merb-admin.gemspec +42 -232
  48. data/public/javascripts/CollapsedFieldsets.js +85 -85
  49. data/public/javascripts/DateTimeShortcuts.js +255 -255
  50. data/public/javascripts/RelatedObjectLookups.js +96 -96
  51. data/public/javascripts/SelectBox.js +111 -111
  52. data/public/javascripts/SelectFilter2.js +113 -113
  53. data/public/javascripts/actions.js +39 -39
  54. data/public/javascripts/calendar.js +143 -143
  55. data/public/javascripts/core.js +176 -176
  56. data/public/javascripts/dateparse.js +233 -233
  57. data/public/javascripts/getElementsBySelector.js +167 -167
  58. data/public/javascripts/i18n.js +33 -33
  59. data/public/javascripts/ordering.js +137 -137
  60. data/public/javascripts/timeparse.js +94 -94
  61. data/public/javascripts/urlify.js +140 -140
  62. data/public/stylesheets/base.css +746 -746
  63. data/public/stylesheets/changelists.css +269 -269
  64. data/public/stylesheets/dashboard.css +24 -24
  65. data/public/stylesheets/forms.css +327 -327
  66. data/public/stylesheets/global.css +142 -142
  67. data/public/stylesheets/ie.css +50 -50
  68. data/public/stylesheets/layout.css +29 -29
  69. data/public/stylesheets/login.css +54 -54
  70. data/public/stylesheets/master.css +1 -1
  71. data/public/stylesheets/patch-iewin.css +7 -7
  72. data/public/stylesheets/rtl.css +206 -206
  73. data/public/stylesheets/widgets.css +506 -506
  74. data/screenshots/create.png +0 -0
  75. data/screenshots/delete.png +0 -0
  76. data/screenshots/edit.png +0 -0
  77. data/screenshots/index.png +0 -0
  78. data/screenshots/list.png +0 -0
  79. data/screenshots/new.png +0 -0
  80. data/spec/controllers/main_spec.rb +25 -25
  81. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  82. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  83. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  84. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -20
  85. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  86. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  87. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  88. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  89. data/spec/migrations/sequel/004_create_players_migration.rb +21 -22
  90. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  91. data/spec/models/activerecord/division.rb +7 -7
  92. data/spec/models/activerecord/draft.rb +11 -11
  93. data/spec/models/activerecord/league.rb +6 -6
  94. data/spec/models/activerecord/player.rb +8 -8
  95. data/spec/models/activerecord/team.rb +13 -13
  96. data/spec/models/datamapper/division.rb +12 -12
  97. data/spec/models/datamapper/draft.rb +18 -18
  98. data/spec/models/datamapper/league.rb +11 -11
  99. data/spec/models/datamapper/player.rb +20 -21
  100. data/spec/models/datamapper/team.rb +22 -22
  101. data/spec/models/sequel/division.rb +15 -15
  102. data/spec/models/sequel/draft.rb +19 -19
  103. data/spec/models/sequel/league.rb +14 -14
  104. data/spec/models/sequel/player.rb +18 -18
  105. data/spec/models/sequel/team.rb +21 -21
  106. data/spec/requests/main_spec.rb +763 -763
  107. data/spec/spec_helper.rb +113 -112
  108. metadata +247 -41
  109. data/VERSION +0 -1
@@ -1,11 +1,11 @@
1
- class Draft < ActiveRecord::Base
2
- validates_numericality_of(:player_id, :only_integer => true)
3
- validates_numericality_of(:team_id, :only_integer => true)
4
- validates_presence_of(:date)
5
- validates_numericality_of(:round, :only_integer => true)
6
- validates_numericality_of(:pick, :only_integer => true)
7
- validates_numericality_of(:overall, :only_integer => true)
8
-
9
- belongs_to(:team)
10
- belongs_to(:player)
11
- end
1
+ class Draft < ActiveRecord::Base
2
+ validates_numericality_of(:player_id, :only_integer => true)
3
+ validates_numericality_of(:team_id, :only_integer => true)
4
+ validates_presence_of(:date)
5
+ validates_numericality_of(:round, :only_integer => true)
6
+ validates_numericality_of(:pick, :only_integer => true)
7
+ validates_numericality_of(:overall, :only_integer => true)
8
+
9
+ belongs_to(:team)
10
+ belongs_to(:player)
11
+ end
@@ -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,21 +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(:deleted_at, ParanoidDateTime)
8
- property(:team_id, Integer, :index => true)
9
- property(:name, String, :length => 100, :required => true, :index => true)
10
- property(:position, String, :index => true)
11
- property(:number, Integer, :required => true)
12
- property(:retired, Boolean, :default => false)
13
- property(:injured, Boolean, :default => false)
14
- property(:born_on, Date)
15
- property(:notes, Text)
16
-
17
- validates_is_unique(:number, :scope => :team_id, :message => "There is already a player with that number on this team")
18
-
19
- belongs_to(:team)
20
- has(1, :draft)
21
- 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_is_unique(: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_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,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,763 @@
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*Deleted 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
+ 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