Sha256: 8fff99aa439d7873adeced58ba85cb7f115518a5f44209c00c68d22281e36165

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe Lcms::Engine::Admin::ResourcesController do
  let(:resource) { create :resource }
  let(:user) { create :admin }

  before { sign_in user }

  describe '#edit' do
    subject { get :edit, params: { id: resource.to_param } }

    it { is_expected.to be_successful }
  end

  describe '#index' do
    subject { get :index }

    it { is_expected.to be_successful }
  end

  describe '#update' do
    let(:description) { Faker::Lorem.sentence }
    let(:params) { { description: description, directory: resource.metadata.keys.join(',') } }

    subject { post :update, params: { id: resource.to_param, resource: params } }

    context 'with valid params' do
      it { is_expected.to redirect_to lcms_engine(admin_resources_path) }

      it 'passes notice' do
        subject
        expect(flash[:notice]).to be_present
      end
    end

    context 'with overridden parameters' do
      let(:extra_param_array) { { extra_array: Faker::Lorem.words } }
      let(:extra_param_simple) { { extra_simple: Faker::Lorem.word } }

      subject do
        post :update, params: { id: resource.to_param,
                                resource: params.merge(**extra_param_simple, **extra_param_array) }
      end

      before do
        Lcms::Engine::Resource.class_eval do
          attr_accessor :extra_array
          attr_accessor :extra_simple
        end

        allow_any_instance_of(Lcms::Engine::Admin::ResourcesController).to \
          receive(:form_params_arrays_override).and_return(extra_param_array.keys[0] => [])

        allow_any_instance_of(Lcms::Engine::Admin::ResourcesController).to \
          receive(:form_params_simple_override).and_return(extra_param_simple.keys)
      end

      it 'accepts overridden parameters' do
        expect { subject }.to_not raise_error
      end

      after do
        Lcms::Engine::Resource.class_eval do
          delete :extra_array
          delete :extra_simple
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.5.4 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.5.3 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.5.2 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.5.1 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.5.0 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.4.2 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.4.1 spec/controllers/admin/resources_controller_spec.rb
lcms-engine-0.4.0 spec/controllers/admin/resources_controller_spec.rb