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.1.8 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.7 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.6 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.5 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.4 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.3 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.2 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.1.1 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.76 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.75 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.74 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.73 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.72 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.71 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.70 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.69 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.68 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.67 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.66 spec/controllers/tenon/settings_controller_spec.rb
tenon-1.0.65 spec/controllers/tenon/settings_controller_spec.rb