Skip to main content
Code Review

Return to Answer

deleted 3 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

You forgot to test what view should be renderrendered. If you would use https://github.com/thoughtbot/shouldathis , your specs will be much more cleaner. LastThe last four it standard should be standard matchers. And first I propose write to you (see as exampleSee https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rbthis ) as an example.

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 describe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb )

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 describe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be rendered. If you use this , your specs will be much cleaner. The last four should be standard matchers. See this as an example.

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 describe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end
Bounty Awarded with 50 reputation awarded by Community Bot
added 1 characters in body
Source Link

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb)

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 contextdescribe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb)

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 context "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb)

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 describe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end
Rollback to Revision 4
Source Link

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb )

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it "defaults to showing 30 results per page" do
  { should Program.should_receive(:paginate).with(:page => nil, :per_page => 30).and_return(programs)
 get :index
 end
 it "passes on the page number to will_paginate" do
 Program.should_receive(:paginate).withwith_default_per_page(:page => '3', :per_page => 30).and_return(programs)
  get :index, 'page' => '3'
 end
 it "passes on the per_page to will_paginate" do
 Program.should_receive(:paginate).with(:page => nil, :per_page => '15').and_return(programs)
 get :index, 'per_page' => '15'
 end}
 
 describecontext "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner.

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it "defaults to showing 30 results per page" do
  Program.should_receive(:paginate).with(:page => nil, :per_page => 30).and_return(programs)
 get :index
 end
 it "passes on the page number to will_paginate" do
 Program.should_receive(:paginate).with(:page => '3', :per_page => 30).and_return(programs)
  get :index, 'page' => '3'
 end
 it "passes on the per_page to will_paginate" do
 Program.should_receive(:paginate).with(:page => nil, :per_page => '15').and_return(programs)
 get :index, 'per_page' => '15'
 end
 
 describe "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end

You forgot to test what view should be render. If you would use https://github.com/thoughtbot/shoulda your specs will be much more cleaner. Last four it standard should matchers. And first I propose write to you (see as example https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb )

describe ProgramsController do
 let(:programs) { [mock_model(Program)] } 
 describe "GET index" do
 it { should paginate(Program).with_default_per_page(30) }
 
 context "after pagination" do
 before(:each) do
 Program.stub(:paginate).and_return(programs) 
 get :index
 end
 it { should assign_to(:programs).with(programs) }
 it { should respond_with(:success) }
 it { should render_template(:index) }
 it { should_not set_the_flash } 
 end
 end
end
added 568 characters in body; deleted 208 characters in body
Source Link
Loading
deleted 217 characters in body
Source Link
Loading
added 5 characters in body
Source Link
Loading
Added alternative variant for pageable spec.
Source Link
Loading
Source Link
Loading
lang-rb

AltStyle によって変換されたページ (->オリジナル) /