Sha256: f51439f38f8c92d67252935fa451ffb1024a80c5cfa5812556954a00a4dac4d7

Contents?: true

Size: 1.65 KB

Versions: 39

Compression:

Stored size: 1.65 KB

Contents

RSpec.shared_examples 'a requests' do |attribute|
  let(:entity) { FactoryBot.create(subject) }
  let(:entities_list) { FactoryBot.create_list(subject, 3) }

  it '#index' do
    entities_list
    get route.polymorphic_path(subject.pluralize)
    expect(response).to have_http_status(:success)
  end

  it '#new' do
    get route.new_polymorphic_path subject
    expect(response).to have_http_status(:success)
  end

  it '#edit' do
    get route.edit_polymorphic_path(entity)
    expect(response).to have_http_status(:success)
  end

  it '#show' do
    get route.polymorphic_path(entity)
    expect(response).to have_http_status(:success)
  end

  context '#create' do

    it 'invalid' do
      expect {
        post route.polymorphic_path(subject.pluralize, { subject => { attribute => '' } })
      }.to change(described_class, :count).by 0
      expect(response).to have_http_status :success
    end

    it 'valid' do
      expect {
        post(route.polymorphic_path(subject.pluralize, { subject => FactoryBot.attributes_for(subject) }))
      }.to change(described_class, :count).by 1
      expect(response).to have_http_status :redirect
    end

  end

  context '#update' do

    it 'invalid' do
      put route.polymorphic_path(entity, { subject => { attribute => '' } })
      expect(response).to have_http_status :success
      expect(entity.reload.send(attribute)).not_to be_blank
    end

    it 'valid' do
      new_value = Faker::Internet.unique.email
      put route.polymorphic_path(entity, { subject => { attribute => new_value } })
      expect(entity.reload.send(attribute)).to eq new_value
      expect(response).to have_http_status :redirect
    end


  end

end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
symphonia-3.3.2 spec/support/shared.rb
symphonia-3.3.0 spec/support/shared.rb
symphonia-3.2.4 spec/support/shared.rb
symphonia-3.2.3 spec/support/shared.rb
symphonia-3.2.2 spec/support/shared.rb
symphonia-3.2.1 spec/support/shared.rb
symphonia-3.1.5 spec/support/shared.rb
symphonia-3.1.4 spec/support/shared.rb
symphonia-3.1.3 spec/support/shared.rb
symphonia-3.1.2 spec/support/shared.rb
symphonia-3.1.1 spec/support/shared.rb
symphonia-3.1.0 spec/support/shared.rb
symphonia-3.0.3 spec/support/shared.rb
symphonia-3.0.2 spec/support/shared.rb
symphonia-2.2.1 spec/support/shared.rb
symphonia-3.0.1 spec/support/shared.rb
symphonia-3.0.0 spec/support/shared.rb
symphonia-2.1.8 spec/support/shared.rb
symphonia-2.1.7 spec/support/shared.rb