Skip to content

Instantly share code, notes, and snippets.

@justinko
Forked from alindeman/let_with_contexts.rb
Created June 23, 2011 23:45

Revisions

  1. justinko renamed this gist Jun 23, 2011. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions let_with_contexts.rb → do_action.rb
    Original file line number Diff line number Diff line change
    @@ -2,26 +2,26 @@
    describe "PUT #update" do
    let(:post) { Factory(:post) }

    before(:each) do
    sign_in user # user is defined as a memoized helper method using let { } below

    put :update, :id => post.id, :body => "new content"
    end

    context "when logged in as post's author" do
    let(:user) { post.author }
    before { sign_in post.author }

    it "allows the post to be updated" do
    do_action
    response.should be_success
    end
    end

    context "when logged in as another user" do
    let(:user) { Factory(:user) }
    before { sign_in Factory(:user) }

    it "does not allow the post to be updated" do
    do_action
    response.should be_forbidden
    end
    end

    def do_action
    put :update, :id => post.id, :body => "new content"
    end
    end
    end
  2. @alindeman alindeman revised this gist Jun 21, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion let_with_contexts.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    let(:post) { Factory(:post) }

    before(:each) do
    login_as user # user is defined as a memoized helper method using let { } below
    sign_in user # user is defined as a memoized helper method using let { } below

    put :update, :id => post.id, :body => "new content"
    end
  3. @alindeman alindeman revised this gist Jun 21, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion let_with_contexts.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    let(:post) { Factory(:post) }

    before(:each) do
    login_as user
    login_as user # user is defined as a memoized helper method using let { } below

    put :update, :id => post.id, :body => "new content"
    end
  4. @alindeman alindeman revised this gist Jun 21, 2011. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions let_with_contexts.rb
    Original file line number Diff line number Diff line change
    @@ -2,22 +2,26 @@
    describe "PUT #update" do
    let(:post) { Factory(:post) }

    before do
    before(:each) do
    login_as user

    put :update, :id => post.id, :body => "new content"
    end

    context "logged in as post's author" do
    context "when logged in as post's author" do
    let(:user) { post.author }

    its(:response) { should be_success }
    it "allows the post to be updated" do
    response.should be_success
    end
    end

    context "logged in as another user" do
    context "when logged in as another user" do
    let(:user) { Factory(:user) }

    its(:response) { should be_forbidden }
    it "does not allow the post to be updated" do
    response.should be_forbidden
    end
    end
    end
    end
  5. @alindeman alindeman created this gist Jun 21, 2011.
    23 changes: 23 additions & 0 deletions let_with_contexts.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    describe PostsController do
    describe "PUT #update" do
    let(:post) { Factory(:post) }

    before do
    login_as user

    put :update, :id => post.id, :body => "new content"
    end

    context "logged in as post's author" do
    let(:user) { post.author }

    its(:response) { should be_success }
    end

    context "logged in as another user" do
    let(:user) { Factory(:user) }

    its(:response) { should be_forbidden }
    end
    end
    end