spec/requests/main_spec.rb in merb-admin-0.6.4 vs spec/requests/main_spec.rb in merb-admin-0.6.5
- old
+ new
@@ -8,19 +8,19 @@
@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))
end
given "two players exist" do
@players = []
- 2.times do |i|
- @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => i + 1, :name => "Player #{i + 1}")
+ (1..2).each do |number|
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
end
end
given "three teams exist" do
@teams = []
- 3.times do |i|
- @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
+ (1..3).each do |number|
+ @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)
end
end
given "a player exists and a draft exists" do
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
@@ -28,27 +28,35 @@
end
given "a player exists and three teams exist" do
@player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
@teams = []
- 3.times do |i|
- @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
+ (1..3).each do |number|
+ @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)
end
end
+given "a player exists and three teams with no name exist" do
+ @player = MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => 1, :name => "Player 1")
+ @teams = []
+ (1..3).each do |number|
+ @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)
+ end
+end
+
given "a league exists and three teams exist" do
- @league = League.create(:name => "League 1")
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
@teams = []
- 3.times do |i|
- @teams << MerbAdmin::AbstractModel.new("Team").create(:league_id => rand(99999), :division_id => rand(99999), :name => "Team #{i + 1}", :manager => "Manager #{i + 1}", :founded => 1869 + rand(130), :wins => (wins = rand(163)), :losses => 162 - wins, :win_percentage => ("%.3f" % (wins.to_f / 162)).to_f)
+ (1..3).each do |number|
+ @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)
end
end
given "twenty players exist" do
@players = []
- 20.times do |i|
- @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => i + 1, :name => "Player #{i + 1}")
+ (1..20).each do |number|
+ @players << MerbAdmin::AbstractModel.new("Player").create(:team_id => rand(99999), :number => number, :name => "Player #{number}")
end
end
describe "MerbAdmin" do
before(:each) do
@@ -70,12 +78,31 @@
end
it "should show \"Site administration\"" do
@response.body.should contain("Site administration")
end
+
+ it "should be sorted correctly" do
+ @response.body.should contain(/Division.*Draft.*League.*Player.*Team/m)
+ end
end
+ describe "dashboard with excluded models" do
+ before(:each) do
+ MerbAdmin[:excluded_models] = [:Player]
+ @response = request(url(:merb_admin_dashboard))
+ end
+
+ it "should respond sucessfully" do
+ @response.should be_successful
+ end
+
+ it "should not contain excluded models" do
+ @response.body.should_not contain(/Player/)
+ end
+ end
+
describe "list" do
before(:each) do
@response = request(url(:merb_admin_list, :model_name => "player"))
end
@@ -345,10 +372,20 @@
it "should show associated objects" do
@response.body.should contain(/TeamTeam 1Team 2Team 3/)
end
end
+ describe "new with missing label", :given => "a player exists and three teams with no name exist" do
+ before(:each) do
+ @response = request(url(:merb_admin_new, :model_name => "player"))
+ end
+
+ it "should respond sucessfully" do
+ @response.should be_successful
+ end
+ end
+
describe "edit", :given => "a player exists" do
before(:each) do
@response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
end
@@ -400,21 +437,30 @@
it "should show associated objects" do
@response.body.should contain(/TeamTeam 1Team 2Team 3/)
end
end
-
describe "edit with missing object" do
before(:each) do
@response = request(url(:merb_admin_edit, :model_name => "player", :id => 1))
end
it "should raise NotFound" do
@response.status.should == 404
end
end
+ describe "edit with missing label", :given => "a player exists and three teams with no name exist" do
+ before(:each) do
+ @response = request(url(:merb_admin_edit, :model_name => "player", :id => @player.id))
+ end
+
+ it "should respond sucessfully" do
+ @response.should be_successful
+ end
+ end
+
describe "create" do
before(:each) do
@response = request(url(:merb_admin_create, :model_name => "player"), :method => "post", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :position => "Second baseman"}})
end
@@ -628,9 +674,21 @@
@response = request(url(:merb_admin_delete, :model_name => "player", :id => 1))
end
it "should raise NotFound" do
@response.status.should == 404
+ end
+ end
+
+ describe "delete with missing label" do
+ before(:each) do
+ @league = MerbAdmin::AbstractModel.new("League").create(:name => "League 1")
+ @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)
+ @response = request(url(:merb_admin_delete, :model_name => "league", :id => @league.id))
+ end
+
+ it "should respond sucessfully" do
+ @response.should be_successful
end
end
describe "destroy", :given => "a player exists" do
before(:each) do