Sha256: 31ed56b424596eb153e1e0c0f870f4a5aba7511ec00bbf756e1057c5e2431283

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

class FooController < ActionController::Base

end

describe Memento::ActionControllerMethods do

  before do
    setup_db
    setup_data
    @controller = FooController.new
    @controller.stub(:current_user => @user)
    @headers = {}
    @controller.stub_chain(:response, :headers => @headers)
  end

  after do
    shutdown_db
  end

  it "should add memento-method to ActionController::Base" do
    FooController.private_instance_methods.map(&:to_sym).should include(:memento)
  end

  it "should call memento#memento with user and block" do
    project = Project.create!
    @controller.send(:memento) do
      project.update_attributes(:name => "P7")
    end
    project.reload.name.should eql("P7")
    project.memento_states.count.should eql(1)
    Memento::Session.count.should eql(1)
  end

  it "should set header X-MementoSessionId" do
    @controller.send(:memento) { Project.create!.update_attributes(:name => "P7") }
    @headers.should == {'X-Memento-Session-Id' => Memento::Session.last.id.to_s }
  end

  it "should return result of given block" do
    @controller.send(:memento) do
      1 + 2
    end.should eql(3)
  end

  it "should not set header when no session stored" do
    @controller.send(:memento) { Customer.create! } # not stored
    @headers['X-MementoSessionId'].should be_nil
    @headers.should_not have_key('X-Memento-Session-Id')
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
memento-0.5.2 spec/memento/action_controller_methods_spec.rb
memento-0.5.1 spec/memento/action_controller_methods_spec.rb
memento-0.5.0 spec/memento/action_controller_methods_spec.rb
memento-0.4.3 spec/memento/action_controller_methods_spec.rb
memento-0.4.2 spec/memento/action_controller_methods_spec.rb