Sha256: b038b38e98c808efb6fff20a2fb8a9eebfd7f4b8f909aacb790ae7a293a9d255

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 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).and_return(@user)
    @headers = {}
    @controller.stub!(:response).and_return(mock("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

1 entries across 1 versions & 1 rubygems

Version Path
memento-0.3.7 spec/memento/action_controller_methods_spec.rb