Browse Source
* Works but relies on routes ordering * Add helper test * Actually work * Test edit password auth even though we don't have a route for it * Add spec description * Consistencypull/451/head
baarkerlounger
3 years ago
committed by
GitHub
11 changed files with 111 additions and 40 deletions
@ -0,0 +1,9 @@
|
||||
module UserHelper |
||||
def aliased_user_edit(user, current_user) |
||||
current_user == user ? edit_account_path : edit_user_path(user) |
||||
end |
||||
|
||||
def pronoun(user, current_user) |
||||
current_user == user ? "you" : "they" |
||||
end |
||||
end |
@ -0,0 +1,20 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe UsersController, type: :controller do |
||||
let(:params) { { id: other_user.id } } |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let(:other_user) { FactoryBot.create(:user, organisation: user.organisation) } |
||||
|
||||
before do |
||||
sign_in user |
||||
end |
||||
|
||||
describe "GET #edit_password" do |
||||
context "when trying to view the edit page for another user in your organisation" do |
||||
it "does not let you and returns not found" do |
||||
get :edit_password, params: params |
||||
expect(response).to have_http_status(:not_found) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,38 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe UserHelper do |
||||
let(:current_user) { FactoryBot.create(:user, :data_coordinator) } |
||||
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||
|
||||
describe "aliased_user_edit" do |
||||
context "when the current logged in user is the same as the user being viewed" do |
||||
let(:user) { current_user } |
||||
|
||||
it "returns the edit account path" do |
||||
expect(aliased_user_edit(user, current_user)).to eq(edit_account_path) |
||||
end |
||||
end |
||||
|
||||
context "when the current logged in user is not the same as the user being viewed" do |
||||
it "returns the edit user path" do |
||||
expect(aliased_user_edit(user, current_user)).to eq(edit_user_path(user)) |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "pronoun" do |
||||
context "when the current logged in user is the same as the user being viewed" do |
||||
let(:user) { current_user } |
||||
|
||||
it "returns 'you'" do |
||||
expect(pronoun(user, current_user)).to eq("you") |
||||
end |
||||
end |
||||
|
||||
context "when the current logged in user is not the same as the user being viewed" do |
||||
it "returns 'they'" do |
||||
expect(pronoun(user, current_user)).to eq("they") |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue