Fix account page forms & add account actions rspec
All checks were successful
CI / scan_ruby (push) Successful in 21s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 37s

#5
This commit is contained in:
sto
2025-12-10 10:44:03 +01:00
parent cce090587a
commit 8cea403dc9
12 changed files with 131 additions and 47 deletions

View File

@@ -2,14 +2,15 @@
#
# Table name: users
#
# id :integer not null, primary key
# admin :boolean default(FALSE), not null
# email_address :string not null
# lang :string default("en")
# password_digest :string not null
# username :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# admin :boolean default(FALSE), not null
# email_address :string not null
# lang :string default("en")
# password_change_attempt :boolean
# password_digest :string not null
# username :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#

View File

@@ -21,21 +21,64 @@ RSpec.feature "Users", type: :feature do
expect(page).not_to have_content(I18n.t("users.index.title"))
end
it "should be able to create a new contest" do
it "should be able to open their account info" do
visit root_path
click_link "Create a new contest"
click_link I18n.t("nav.settings")
expect(page).to have_content(I18n.t("contests.new.title"))
expect(page).to have_current_path(edit_user_path(user))
end
it "should be able to open an existing contest" do
visit root_path
context "when updating their account info" do
let!(:existing_user) { create(:user, username: "taken_username") }
expect(page).to have_content(contest.name)
find("div.card", text: contest.name).find("a").click
it "should allow changing to an untaken username" do
visit edit_user_path(user)
expect(page).to have_content(I18n.t("contests.show.title", name: contest.name))
fill_in I18n.t("activerecord.attributes.user.username"), with: "untaken_username"
expect { click_button(I18n.t("helpers.buttons.save")); user.reload }.to change(user, :username).to("untaken_username")
end
it "should prevent changing to an already taken username" do
visit edit_user_path(user)
fill_in I18n.t("activerecord.attributes.user.username"), with: "taken_username"
expect { click_button(I18n.t("helpers.buttons.save")); user.reload }.not_to change(user, :username)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.username.taken"))
end
it "should prevent changing to a blank username" do
visit edit_user_path(user)
fill_in I18n.t("activerecord.attributes.user.username"), with: ""
expect { click_button(I18n.t("helpers.buttons.save")); user.reload }.not_to change(user, :username)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.username.blank"))
end
it "should allow changing to a non-blank password" do
visit edit_user_path(user)
fill_in I18n.t("activerecord.attributes.user.password"), with: "new_password"
expect { click_button(I18n.t("helpers.buttons.save_password")); user.reload }
.to change(user, :password_digest)
.and change { user.authenticate("new_password") }.from(false).to(user)
end
it "should prevent changing to a blank password" do
visit edit_user_path(user)
fill_in I18n.t("activerecord.attributes.user.password"), with: ""
expect { click_button(I18n.t("helpers.buttons.save_password")); user.reload }.not_to change(user, :password)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.password.blank"))
end
end
end

View File

@@ -2,14 +2,15 @@
#
# Table name: users
#
# id :integer not null, primary key
# admin :boolean default(FALSE), not null
# email_address :string not null
# lang :string default("en")
# password_digest :string not null
# username :string
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# admin :boolean default(FALSE), not null
# email_address :string not null
# lang :string default("en")
# password_change_attempt :boolean
# password_digest :string not null
# username :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#