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