Skip to content

Commit

Permalink
Merge pull request #348 from dgmstuart/dgms/skip-login
Browse files Browse the repository at this point in the history
Skip login wherever possible
  • Loading branch information
dgmstuart authored Apr 8, 2024
2 parents ea197d4 + a9efd59 commit 240eaf9
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 191 deletions.
9 changes: 5 additions & 4 deletions spec/support/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ def stub_login(id: Faker::Facebook.uid, name: Faker::Name.lindy_hop_name, admin:
end
end

def skip_login
name = Faker::Name.lindy_hop_name
def skip_login(after_login_path = "/events", id: Faker::Facebook.uid, name: Faker::Name.lindy_hop_name, admin: false)
user = instance_double(LoginSession::User,
name:,
name_with_role: name,
admin?: false,
auth_id: Faker::Facebook.uid,
admin?: admin,
auth_id: id,
token: "a-super-secret-token",
logged_in?: true)
login_session = instance_double(LoginSession, "Fake login", user:)
allow(LoginSession).to receive(:new).and_return(login_session)
visit after_login_path
end
end
9 changes: 2 additions & 7 deletions spec/system/admins_can_clear_the_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
RSpec.describe "Admins can clear the cache" do
it "clears the cache and redirects to the events list" do
enable_cache
stub_login(admin: true)
Rails.cache.write("a_cache_key", "a value")
expect(Rails.cache.read("a_cache_key")).to eq("a value")

visit "/login"
click_on "Log in"
skip_login(admin: true)

click_on "Cache"
click_on "Clear"
Expand All @@ -21,10 +19,7 @@

context "when logged in as a non-admin" do
it "does not allow access" do
stub_login(admin: false)

visit "/login"
click_on "Log in"
skip_login(admin: false)

expect(page).to have_no_content("Cache")

Expand Down
34 changes: 7 additions & 27 deletions spec/system/admins_can_manage_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
stub_auth_hash(id: 98765987659876598)
create(:admin, facebook_ref: 98765987659876598)

visit "/login"
click_on "Log in"
visit "/admin/users"

VCR.use_cassette("fetch_facebook_names") do
open_menu
click_on "Users"
click_on "Log in"

expect(page).to have_no_content("Dawn Hampton")
end
Expand Down Expand Up @@ -60,12 +58,10 @@

Capybara.using_session("admin_session") do
stub_auth_hash(id: "98765987659876598")
visit "/login"
click_on "Log in"
visit "/admin/users"

VCR.use_cassette("fetch_facebook_names") do
open_menu
click_on "Users"
click_on "Log in"
end

expect(page).to have_content("Dawn Hampton")
Expand Down Expand Up @@ -94,16 +90,10 @@

it "promoting an editor to an admin", :js, :vcr do
stub_facebook_config(app_secret!: "super-secret-secret")
stub_auth_hash(id: 98765987659876598)
create(:editor, facebook_ref: 12345678901234567)
create(:admin, facebook_ref: 98765987659876598)

visit "/login"
click_on "Log in"

VCR.use_cassette("fetch_facebook_names") do
open_menu
click_on "Users"
skip_login("/admin/users", admin: true)
expect(page).to have_content("Dawn Hampton")
end

Expand All @@ -120,16 +110,10 @@

it "removing admin privileges from a user", :js, :vcr do
stub_facebook_config(app_secret!: "super-secret-secret")
stub_auth_hash(id: 98765987659876598)
create(:admin, facebook_ref: 12345678901234567)
create(:admin, facebook_ref: 98765987659876598)

visit "/login"
click_on "Log in"

VCR.use_cassette("fetch_facebook_names") do
open_menu
click_on "Users"
skip_login("/admin/users", admin: true)
expect(page).to have_content("Dawn Hampton (Admin)")
end

Expand All @@ -148,11 +132,7 @@

context "when logged in as a non-admin" do
it "does not allow access" do
stub_auth_hash(id: 12345678901234567)
create(:editor, facebook_ref: 12345678901234567)

visit "/login"
click_on "Log in"
skip_login(admin: false)

expect(page).to have_no_content("Users")

Expand Down
12 changes: 3 additions & 9 deletions spec/system/admins_can_view_an_audit_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
end

it "showing a list of audited events" do
stub_login(admin: true)

visit "/login"
click_on "Log in"

create(:event)
create(:venue)
create(:organiser)

skip_login(admin: true)

click_on "Audit Log"

expect(page).to have_content("Missing name create Event")
Expand All @@ -26,10 +23,7 @@

context "when logged in as a non-admin" do
it "does not allow access" do
stub_login(admin: false)

visit "/login"
click_on "Log in"
skip_login(admin: false)

expect(page).to have_no_content("Audit Log")

Expand Down
9 changes: 3 additions & 6 deletions spec/system/editors_can_copy_organiser_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
event = create(:event, organiser_token: "abc123")
grant_clipboard_permissions

skip_login
visit "/events/#{event.id}/edit"
skip_login("/events/#{event.id}/edit")

url = URI.join(page.server_url, "/external_events/abc123/edit").to_s
expect(page).to have_field("Organiser edit link", with: url)
Expand Down Expand Up @@ -42,8 +41,7 @@
grant_clipboard_permissions
allow(SecureRandom).to receive(:hex).and_return("abc123")

skip_login
visit "/events/#{event.id}/edit"
skip_login("/events/#{event.id}/edit")

expect(page).to have_content("No organiser edit link exists for this event")

Expand All @@ -64,8 +62,7 @@
event = create(:event)
allow(event).to receive(:update).and_return false

skip_login
visit "/events/#{event.id}/edit"
skip_login("/events/#{event.id}/edit")

click_on "Generate link"

Expand Down
32 changes: 8 additions & 24 deletions spec/system/editors_can_create_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

context "an intermittent social with a taster" do # rubocop:disable RSpec/ContextWording
it "with valid data" do
stub_login(id: 12345678901234567, name: "Al Minns")
create(:venue, name: "The 100 Club")
create(:organiser, name: "The London Swing Dance Society")
travel_to Time.zone.local(2012, 1, 2, 23, 17, 16)

visit "/login"
click_on "Log in"
skip_login(id: 12345678901234567, name: "Al Minns")

click_on "New event", match: :first

Expand Down Expand Up @@ -57,14 +55,10 @@
end

it "with invalid data" do
stub_login(id: 12345678901234567, name: "Al Minns")
create(:venue, name: "The 100 Club")
travel_to "2012-01-01"

visit "/login"
click_on "Log in"

click_on "New event", match: :first
skip_login("/events/new")

click_on "Create"

Expand Down Expand Up @@ -109,9 +103,8 @@
it "doesn't save any values from the class" do
create(:venue, name: "The 100 Club")
create(:organiser, name: "The London Swing Dance Society")
skip_login

visit "/events/new"
skip_login("/events/new")

fill_in "Url", with: "http://www.lsds.co.uk/stompin"
autocomplete_select "The 100 Club", from: "Venue"
Expand Down Expand Up @@ -146,9 +139,8 @@
it "doesn't save any values from the social" do
create(:venue, name: "The 100 Club")
create(:organiser, name: "The London Swing Dance Society")
skip_login

visit "/events/new"
skip_login("/events/new")

fill_in "Url", with: "http://www.lsds.co.uk/stompin"
autocomplete_select "The 100 Club", from: "Venue"
Expand Down Expand Up @@ -176,9 +168,9 @@

it "from the 'New event at this venue' button" do
create(:venue, name: "93 feet east", area: "Brick Lane")
skip_login

visit venues_path
skip_login(venues_path)

click_on "Show", match: :first

expect(page).to have_content("93 feet east")
Expand All @@ -192,15 +184,11 @@

context "a weekly class" do # rubocop:disable RSpec/ContextWording
it "with valid data" do
stub_login(id: 12345678901234567, name: "Leon James")
create(:venue, name: "Dogstar")
create(:organiser, name: "Sunshine Swing")
travel_to Time.zone.local(2012, 1, 2, 23, 17, 16)

visit "/login"
click_on "Log in"

click_on "New event", match: :first
skip_login("/events/new", id: 12345678901234567, name: "Leon James")

fill_in "Url", with: "https://sunshineswing.uk/events"
autocomplete_select "Dogstar", from: "Venue"
Expand All @@ -227,14 +215,10 @@
end

it "with missing data" do
stub_login(id: 12345678901234567, name: "Leon James")
create(:venue, name: "Dogstar")
create(:organiser, name: "Sunshine Swing")

visit "/login"
click_on "Log in"

click_on "New event", match: :first
skip_login("/events/new")

click_on "Create"

Expand Down
16 changes: 3 additions & 13 deletions spec/system/editors_can_create_organisers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

RSpec.describe "Editors can create organisers" do
it "with valid data" do
stub_login(id: 12345678901234567, name: "Al Minns")

visit "/login"
click_on "Log in"
skip_login(id: 12345678901234567, name: "Al Minns")

click_on "New Organiser"

Expand All @@ -29,12 +26,7 @@
end

it "with an empty shortname" do
stub_login

visit "/login"
click_on "Log in"

click_on "New Organiser"
skip_login("/organisers/new")

fill_in "Name", with: "The London Swing Dance Society"
fill_in "Shortname", with: ""
Expand All @@ -46,9 +38,7 @@

context "with invalid data" do
it "shows an error" do
skip_login

visit "/organisers/new"
skip_login("/organisers/new")

fill_in "Shortname", with: "12345678901234567890+"

Expand Down
9 changes: 2 additions & 7 deletions spec/system/editors_can_create_venues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

RSpec.describe "Editors can create venues" do
it "with valid data", :vcr do
stub_login(id: 12345678901234567, name: "Al Minns")

visit "/login"
click_on "Log in"
skip_login(id: 12345678901234567, name: "Al Minns")

click_on "New Venue"

Expand Down Expand Up @@ -37,9 +34,7 @@

context "with invalid data" do
it "shows an error" do
skip_login

visit "/venues/new"
skip_login("/venues/new")

fill_in "Website", with: "www.the100club.co.uk"

Expand Down
4 changes: 1 addition & 3 deletions spec/system/editors_can_delete_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

RSpec.describe "Editors can delete events" do
it "can be deleted from the event list", :js do
stub_login
create(:event, title: "Balboa at Bobby McGee's")

visit "/login"
click_on "Log in"
skip_login

# The delete link only shows above 900px wide
page.driver.browser.manage.window.resize_to(901, 600)
Expand Down
Loading

0 comments on commit 240eaf9

Please sign in to comment.