Sha256: 386400265917c17014d90f7015c55f80fb7e60ec77d7552322b7d667e32d3466

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

shared_examples "unable to change" do |action|
  context "when cannot change" do
    context "when not permitted to change" do
      before do
        Neutral.configure { |config| config.can_change = false }
        controller.stub(:current_user).and_return(vote.voter)
      end
    
      after do
        Neutral.configure { |config| config.can_change = true }
      end 

      it_should_behave_like "not performing #{action}"
    end
    
    context "when current_user is not an owner of the vote" do
      before do
        controller.stub(:current_user).and_return(voter)
      end

      it_should_behave_like "not performing #{action}"
    end
  end
end

shared_examples "not performing update" do
  it "does not update the vote" do
    update(vote)
    vote.value.should == vote.reload.value
  end

  it "renders cannot_change template" do
    expect(update(vote)).to render_template('errors/cannot_change')
  end
end

shared_examples "not performing destroy" do
  it "does not destroy the vote" do
    expect { destroy(vote) }.to_not change(Neutral::Vote, :count).by(-1)
  end

  it "renders cannot_change template" do
    expect(destroy(vote)).to render_template('errors/cannot_change')
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
neutral-0.0.7 spec/support/shared_examples/controller_examples.rb
neutral-0.0.6 spec/support/shared_examples/controller_examples.rb
neutral-0.0.5 spec/support/shared_examples/controller_examples.rb
neutral-0.0.4 spec/support/shared_examples/controller_examples.rb
neutral-0.0.3 spec/support/shared_examples/controller_examples.rb
neutral-0.0.2 spec/support/shared_examples/controller_examples.rb
neutral-0.0.1 spec/support/shared_examples/controller_examples.rb