Sha256: 447d0efa824bc849ee31f4c9e967859929cf619082862de456fec78683457295

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 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

2 entries across 2 versions & 1 rubygems

Version Path
memento-0.4.1 spec/memento/action_controller_methods_spec.rb
memento-0.4.0 spec/memento/action_controller_methods_spec.rb