Sha256: 7510ff55597ca7521967082a29e613fcf050423d024090d5a015950159333029

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActionController::SetSessionMatcher do
  context 'a controller that sets a session variable' do
    it 'accepts assigning to that variable' do
      controller_with_session(:var => 'hi').should set_session(:var)
    end

    it 'accepts assigning the correct value to that variable' do
      controller_with_session(:var => 'hi').should set_session(:var).to('hi')
    end

    it 'rejects assigning another value to that variable' do
      controller_with_session(:var => 'hi').should_not set_session(:var).to('other')
    end

    it 'rejects assigning to another variable' do
      controller_with_session(:var => 'hi').should_not set_session(:other)
    end

    it 'accepts assigning nil to another variable' do
      controller_with_session(:var => 'hi').should set_session(:other).to(nil)
    end

    it 'accepts assigning false to that variable' do
      controller_with_session(:var => false).should set_session(:var).to(false)
    end

    it 'accepts assigning to the same value in the test context' do
      expected = 'value'

      controller_with_session(:var => expected).
        should set_session(:var).in_context(self).to { expected }
    end

    it 'rejects assigning to the another value in the test context' do
      expected = 'other'

      controller_with_session(:var => 'unexpected').
        should_not set_session(:var).in_context(self).to { expected }
    end

    def controller_with_session(session_hash)
      build_response do
        session_hash.each do |key, value|
          session[key] = value
        end
      end
    end
  end
end

Version data entries

18 entries across 17 versions & 2 rubygems

Version Path
shoulda-matchers-2.5.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.4.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.4.0.rc1 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.3.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
challah-1.0.0 vendor/bundle/gems/shoulda-matchers-2.2.0/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.2.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-2.1.0/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.1.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-2.0.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.6 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.5 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.4 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.2 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.1 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb
shoulda-matchers-1.5.0 spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb