# frozen_string_literal: true # == Schema Information # # Table name: users # # id :integer not null, primary key # anonymous_by_default :boolean default(FALSE), not null # authentication_token :string not null # avatar :string # comments_always_jump_to_last :boolean default(FALSE), not null # comments_newest_first :boolean default(TRUE), not null # comments_per_page :integer default(20), not null # comments_posted_count :integer default(0), not null # consumed_timestep :integer # current_sign_in_at :datetime # current_sign_in_ip :inet # deleted_at :datetime # description :string # email :string default(""), not null # encrypted_password :string default(""), not null # failed_attempts :integer # fancy_tag_field_on_edit :boolean default(TRUE), not null # fancy_tag_field_on_upload :boolean default(TRUE), not null # forum_posts_count :integer default(0), not null # hide_comments :boolean default(FALSE) # hide_default_role :boolean default(FALSE), not null # hide_vote_counts :boolean default(FALSE), not null # images_per_page :integer default(15), not null # last_renamed_at :datetime default(Thu, 01 Jan 1970 00:00:00.000000000 UTC +00:00), not null # last_sign_in_at :datetime # last_sign_in_ip :inet # locked_at :datetime # messages_newest_first :boolean default(FALSE), not null # metadata_updates_count :integer default(0), not null # name :string not null # no_spoilered_in_watched :boolean default(FALSE), not null # otp_backup_codes :string is an Array # otp_required_for_login :boolean # otp_secret :text # personal_title :string # posts_favorited_count :integer default(0), not null # recent_filter_ids :integer default([]), not null, is an Array # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string # role :string default("user"), not null # scale_large_images :boolean default(TRUE), not null # scratchpad :text # secondary_role :string # serve_webm :boolean default(FALSE), not null # show_large_thumbnails :boolean default(TRUE), not null # show_sidebar_and_watched_images :boolean default(TRUE), not null # sign_in_count :integer default(0), not null # slug :string not null # spoiler_type :string default("static"), not null # theme :string default("default"), not null # topic_count :integer default(0), not null # unlock_token :string # uploads_count :integer default(0), not null # use_centered_layout :boolean default(FALSE), not null # votes_cast_count :integer default(0), not null # watch_on_new_topic :boolean default(TRUE), not null # watch_on_reply :boolean default(TRUE), not null # watch_on_upload :boolean default(TRUE), not null # watched_images_exclude_str :string default(""), not null # watched_images_query_str :string default(""), not null # watched_tag_ids :integer default([]), not null, is an Array # created_at :datetime not null # updated_at :datetime not null # current_filter_id :integer # deleted_by_user_id :integer # # Indexes # # index_users_on_authentication_token (authentication_token) UNIQUE # index_users_on_current_filter_id (current_filter_id) # index_users_on_deleted_by_user_id (deleted_by_user_id) WHERE (deleted_by_user_id IS NOT NULL) # index_users_on_email (email) UNIQUE # index_users_on_name (name) # index_users_on_reset_password_token (reset_password_token) UNIQUE # index_users_on_slug (slug) # # Foreign Keys # # fk_rails_... (current_filter_id => filters.id) ON DELETE => restrict ON UPDATE => cascade # fk_rails_... (deleted_by_user_id => users.id) ON DELETE => nullify ON UPDATE => cascade # require 'test_helper' class UserTest < ActiveSupport::TestCase setup do @user = build(:user) end test 'should be valid' do @user.valid? end test 'should have default filter after creation' do @user.save! assert_equal 'Default', @user.current_filter.name end test 'switching filters should populate recent_filter_ids without duplicates' do @filter1 = create(:filter_everything) @filter2 = create(:filter_porn_only) assert_not_includes @user.recent_filter_ids, @filter1.id @user.set_filter!(@filter1) assert_includes @user.recent_filter_ids, @filter1.id @user.set_filter!(@filter2) @user.set_filter!(@filter1) @user.set_filter!(@filter2) assert_equal 1, @user.recent_filter_ids.count(@filter1.id) assert_equal 1, @user.recent_filter_ids.count(@filter2.id) end test '#staff?' do assert_not build(:user).staff? assert build(:assistant).staff? assert build(:moderator).staff? assert build(:admin).staff? end end