Sha256: ce772c41a0a4f59510743897204326a04c375149131d7a636087c85f57c8138d

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'rails_helper'

RSpec.describe PostsController, type: :controller do
  controller do
  end

  before(:each) do
    reset_to_defaults
  end

  context 'when updating a Post' do
    it 'sets the correct updater' do
      request.session  = { person_id: @delynn.id }
      post :update, id: @first_post.id, post: { title: 'Different' }

      expect(response.status).to eq(200)
      expect(controller.instance_variable_get(:@post).title).to eq('Different')
      expect(controller.instance_variable_get(:@post).updater).to eq(@delynn)
    end
  end

  context 'when handling multiple requests' do
    def simulate_second_request
      old_request_session = request.session
      request.session = { person_id: @nicole.id }

      post :update, id: @first_post.id, post: { title: 'Different Second'}
      expect(controller.instance_variable_get(:@post).updater).to eq(@nicole)
    ensure
      request.session = old_request_session
    end

    it 'sets the correct updater' do
      request.session = { person_id: @delynn.id }
      get :edit, id: @first_post.id
      expect(response.status).to eq(200)

      simulate_second_request

      post :update, id: @first_post.id, post: { title: 'Different' }
      expect(response.status).to eq(200)
      expect(controller.instance_variable_get(:@post).title).to eq('Different')
      expect(controller.instance_variable_get(:@post).updater).to eq(@delynn)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-userstamp-3.0.1 spec/controllers/posts_controller_spec.rb
activerecord-userstamp-3.0.0 spec/controllers/posts_controller_spec.rb