Skip to content

Commit

Permalink
Fix specs by adding anonymous to the results.
Browse files Browse the repository at this point in the history
The User.anonymous is being created in the tests, because the
User.available_custom_fields method references it, thus it gets created
any time a user is created.
  • Loading branch information
dombesz committed Aug 12, 2024
1 parent 3e7db14 commit 2f7f173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions spec/models/principals/scopes/ordered_by_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

RSpec.describe Principals::Scopes::OrderedByName do
describe ".ordered_by_name" do
shared_let(:anonymous) { User.anonymous }
shared_let(:alice) { create(:user, login: "alice", firstname: "Alice", lastname: "Zetop") }
shared_let(:eve) { create(:user, login: "eve", firstname: "Eve", lastname: "Baddie") }

Expand All @@ -56,37 +57,37 @@

context "with default user sort", with_settings: { user_format: :firstname_lastname } do
it_behaves_like "sorted results" do
let(:order) { [alice.id, group.id, placeholder_user.id, eve.id] }
let(:order) { [alice.id, anonymous.id, group.id, placeholder_user.id, eve.id] }
end
end

context "with lastname_firstname user sort", with_settings: { user_format: :lastname_firstname } do
it_behaves_like "sorted results" do
let(:order) { [eve.id, group.id, placeholder_user.id, alice.id] }
let(:order) { [anonymous.id, eve.id, group.id, placeholder_user.id, alice.id] }
end
end

context "with lastname_n_firstname user sort", with_settings: { user_format: :lastname_n_firstname } do
it_behaves_like "sorted results" do
let(:order) { [eve.id, group.id, placeholder_user.id, alice.id] }
let(:order) { [anonymous.id, eve.id, group.id, placeholder_user.id, alice.id] }
end
end

context "with lastname_coma_firstname user sort", with_settings: { user_format: :lastname_coma_firstname } do
it_behaves_like "sorted results" do
let(:order) { [eve.id, group.id, placeholder_user.id, alice.id] }
let(:order) { [anonymous.id, eve.id, group.id, placeholder_user.id, alice.id] }
end
end

context "with firstname user sort", with_settings: { user_format: :firstname } do
it_behaves_like "sorted results" do
let(:order) { [alice.id, group.id, placeholder_user.id, eve.id] }
let(:order) { [alice.id, anonymous.id, group.id, placeholder_user.id, eve.id] }
end
end

context "with login user sort", with_settings: { user_format: :username } do
it_behaves_like "sorted results" do
let(:order) { [alice.id, group.id, placeholder_user.id, eve.id] }
let(:order) { [alice.id, anonymous.id, group.id, placeholder_user.id, eve.id] }
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion spec/models/users/scopes/with_time_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
preferences: { time_zone: "" }
)
end
shared_let(:anonymous) { User.anonymous }

describe ".with_time_zone" do
it "returns user having set a time zone in their preference matching the specified time zone(s)" do
Expand Down Expand Up @@ -119,7 +120,12 @@
it "assumes Etc/UTC as default time zone",
with_settings: { user_default_timezone: nil } do
expect(User.with_time_zone("Etc/UTC"))
.to contain_exactly(user_without_preferences, user_without_time_zone, user_with_empty_time_zone)
.to contain_exactly(
user_without_preferences,
user_without_time_zone,
user_with_empty_time_zone,
anonymous
)
end
end
end
Expand Down

0 comments on commit 2f7f173

Please sign in to comment.