Sha256: 66419fe2272f30c328600ae3f8bf618437375a3264d4dbb434516fe2d89a282b

Contents?: true

Size: 1.55 KB

Versions: 83

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe Tenon::SettingsController do
  routes { Tenon::Engine.routes }

  let(:settings) { double.as_null_object }
  before do
    controller.stub(:current_user) { user }
    stub_const('Tenon::MySettings', settings)
  end

  context 'as not an admin' do
    let(:user) do
      double(
        :staff? => false,
        :is_super_admin? => false,
        :is_admin? => false
      )
    end

    describe 'PATCH update' do
      it 'should redirect to /login' do
        patch :update
        expect(response).to redirect_to(new_user_session_path)
      end
    end

    describe 'GET show' do
      it 'should redirect to /login' do
        get :show
        expect(response).to redirect_to(new_user_session_path)
      end
    end
  end

  context 'as an admin' do
    let(:user) do
      double(
        :staff? => true,
        :is_super_admin? => false,
        :is_admin? => true
      )
    end

    describe 'PATCH update' do
      it 'should assign a setting for each param setting submitted' do
        expect(Tenon::MySettings).to receive(:one=).with('one')
        expect(Tenon::MySettings).to receive(:two=).with('two')
        patch :update, settings: { one: 'one', two: 'two' }
      end

      it 'should set the flash' do
        patch :update, settings: { one: 'one', two: 'two' }
        expect(controller.flash[:notice]).not_to be_blank
      end
    end

    describe 'GET show' do
      it 'should assign settings to Tenon::MySettings' do
        get :show
        expect(assigns[:settings]).to eq(Tenon::MySettings)
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
tenon-1.0.43 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.42 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.41 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.40 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.39 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.38 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.37 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.36 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.35 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.33 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.32 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.31 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.30 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.29 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.28 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.27 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.26 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.25 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.24 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.23 spec/controllers/tenon/settings_controller_spec.rb