Created
December 21, 2010 17:54
-
-
Save santiago/750292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fake_login(user=nil, partner=nil, roles=[]) | |
user= mock("user") unless user | |
partner= Factory.stub(:partner) unless partner | |
user.stub(:roles).and_return(roles) | |
user.stub(:partner).and_return(partner) | |
controller.stub(:current_user).and_return(user) | |
controller.stub(:current_partner).and_return(partner) | |
end | |
def it_should_require_a_logged_in_user(partner=nil, &block) | |
it "should succeed when logged in" do | |
fake_login(Factory.stub(:user), partner) | |
instance_eval(&block) | |
if response.redirect? | |
response.redirected_to.should_not eql(new_user_session_url) | |
else | |
response.should be_success | |
end | |
end | |
... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NsbgsController ... | |
... | |
def score | |
# the test is reaching the implementation of the update method | |
current_partner.nsbg.update({:need_id => params[:need_id], :score => params[:score]}) | |
respond_to do |format| | |
format.json { render :json => [] } | |
end | |
end | |
... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe NsbgsController do | |
before(:each) do | |
@partner= Factory.stub(:partner) | |
end | |
describe "#score" do | |
it_should_require_a_logged_in_user(@partner) do | |
@nsbg= mock("nsbg").as_null_object | |
@partner.stub(:nsbg).and_return(@nsbg) | |
post :score | |
end | |
... | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment