Skip to content

Commit

Permalink
PR feedback: use shared examples in specs #627
Browse files Browse the repository at this point in the history
  • Loading branch information
jseraf committed Oct 8, 2020
1 parent bbf566b commit 6e97a80
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 48 deletions.
47 changes: 33 additions & 14 deletions spec/models/panel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,33 @@
end

context 'meeting_link' do
it 'requires a valid secure url' do
panel.meeting_link = 'invalid'
expect(panel).not_to be_valid
expect(panel.errors.full_messages).to include 'Meeting Link is not a valid secure URL.'
panel.meeting_link = 'ftp://abc.com/'
expect(panel).not_to be_valid
expect(panel.errors.full_messages).to include 'Meeting Link is not a valid secure URL.'
panel.meeting_link = 'http://abc.com/'
expect(panel).not_to be_valid
expect(panel.errors.full_messages).to include 'Meeting Link is not a valid secure URL.'
panel.meeting_link = 'https://abc.com/'
expect(panel).to be_valid
panel.meeting_link = 'https://college.zoom.us/z/123456789'
expect(panel).to be_valid
context 'requires a valid secure url' do
it 'may not be a string' do
panel.meeting_link = 'invalid'
is_invalid_meeting_link(panel: panel)
end

it 'may not be ftp' do
panel.meeting_link = 'ftp://abc.com/'
is_invalid_meeting_link(panel: panel)
end

it 'may not be http' do
panel.meeting_link = 'http://abc.com/'
is_invalid_meeting_link(panel: panel)
end
end

context 'valid secure url' do
it 'validates url' do
panel.meeting_link = 'https://abc.com/'
expect(panel).to be_valid
end

it 'validates full path url' do
panel.meeting_link = 'https://college.zoom.us/z/123456789'
expect(panel).to be_valid
end
end
end
end
Expand Down Expand Up @@ -106,4 +119,10 @@
end
end
end

def is_invalid_meeting_link(panel:)
expect(panel).not_to be_valid
expect(panel.errors.full_messages).to include 'Meeting Link is not a valid secure URL.'
end

end
63 changes: 29 additions & 34 deletions spec/system/panels/panels_spec.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
require 'rails_helper'

RSpec.describe 'Panels', type: :system, js: true do
button_text = 'Update Panel Information'

let(:grant) { create(:open_grant_with_users_and_form_and_submission_and_reviewer) }
let(:admin) { grant.admins.first }
let(:editor) { grant.editors.first }
let(:viewer) { grant.viewers.first }
let(:grant) { create(:open_grant_with_users_and_form_and_submission_and_reviewer) }
let(:admin) { grant.admins.first }
let(:editor) { grant.editors.first }
let(:viewer) { grant.viewers.first }
let(:button_text) { 'Update Panel Information' }

describe 'Edit' do
context 'user' do
context 'with grant_permission' do
context 'grant_admin' do
before(:each) do
login_as admin, scope: admin.type.underscore.to_sym
visit edit_grant_panel_path(grant)
end

scenario 'can visit the edit page' do
expect(page).not_to have_content 'You are not authorized to perform this action.'
login_as admin, scope: admin.type.underscore.to_sym
can_vist_edit_page(user: admin)
end
end

context 'grant_editor' do
before(:each) do
login_as editor, scope: editor.type.underscore.to_sym
visit edit_grant_panel_path(grant)
end

scenario 'can visit the edit page' do
expect(page).not_to have_content 'You are not authorized to perform this action.'
login_as admin, scope: admin.type.underscore.to_sym
can_vist_edit_page(user: editor)
end
end

context 'grant_viewer' do
before(:each) do
scenario 'cannot visit the edit page' do
login_as viewer, scope: viewer.type.underscore.to_sym
visit edit_grant_panel_path(grant)
end

scenario 'cannot visit the edit page' do
expect(page).to have_content 'You are not authorized to perform this action.'
end
end
Expand All @@ -54,30 +42,21 @@
context 'grant_admin' do
before(:each) do
login_as admin, scope: admin.type.underscore.to_sym
visit edit_grant_panel_path(grant)
# visit edit_grant_panel_path(grant)
end

scenario 'may update' do
new_address = Faker::Address.full_address
page.fill_in 'Meeting Location', with: new_address, fill_options: { clear: :backspace }
click_button button_text
expect(page).to have_content 'Panel information successfully updated.'
expect(grant.panel.meeting_location).to eql new_address
can_update_panel(user: admin)
end
end

context 'grant_editor' do
before(:each) do
login_as editor, scope: editor.type.underscore.to_sym
visit edit_grant_panel_path(grant)
end

scenario 'may update' do
new_address = Faker::Address.full_address
page.fill_in 'Meeting Location', with: new_address, fill_options: { clear: :backspace }
click_button button_text
expect(page).to have_content 'Panel information successfully updated.'
expect(grant.panel.meeting_location).to eql new_address
can_update_panel(user: editor)
end
end
end
Expand Down Expand Up @@ -150,4 +129,20 @@
end
end
end

def can_vist_edit_page(user:)
visit edit_grant_panel_path(grant)

expect(page).not_to have_content 'You are not authorized to perform this action.'
end

def can_update_panel(user:)
visit edit_grant_panel_path(grant)
new_address = Faker::Address.full_address
page.fill_in 'Meeting Location', with: new_address, fill_options: { clear: :backspace }
click_button button_text
expect(page).to have_content 'Panel information successfully updated.'
expect(grant.panel.meeting_location).to eql new_address
end

end

0 comments on commit 6e97a80

Please sign in to comment.