Skip to content

Commit

Permalink
Change default column value to 0 on user stats
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Nov 28, 2024
1 parent adac0ed commit 8ae94f0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,4 @@ RUBY VERSION
ruby 3.3.5p100

BUNDLED WITH
2.5.18
2.5.23
10 changes: 10 additions & 0 deletions db/migrate/20241128052830_fix_users_table_defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class FixUsersTableDefaults < ActiveRecord::Migration[7.2]
def change
change_column_default :users, :num_machines_added, default: 0
change_column_default :users, :num_machines_removed, default: 0
change_column_default :users, :num_locations_suggested, default: 0
change_column_default :users, :num_lmx_comments_left, default: 0
change_column_default :users, :num_msx_scores_added, default: 0
change_column_default :users, :user_submissions_count, default: 0
end
end
16 changes: 16 additions & 0 deletions db/migrate/20241128060236_fix_users_table_defaults_again.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class FixUsersTableDefaultsAgain < ActiveRecord::Migration[7.2]
def change
change_column_null :users, :num_machines_added, false
change_column_null :users, :num_machines_removed, false
change_column_null :users, :num_locations_suggested, false
change_column_null :users, :num_lmx_comments_left, false
change_column_null :users, :num_msx_scores_added, false
change_column_null :users, :user_submissions_count, false
change_column_default :users, :num_machines_added, from: nil, to: 0
change_column_default :users, :num_machines_removed, from: nil, to: 0
change_column_default :users, :num_locations_suggested, from: nil, to: 0
change_column_default :users, :num_lmx_comments_left, from: nil, to: 0
change_column_default :users, :num_msx_scores_added, from: nil, to: 0
change_column_default :users, :user_submissions_count, from: nil, to: 0
end
end
14 changes: 8 additions & 6 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -926,13 +926,13 @@ CREATE TABLE public.users (
is_disabled boolean,
authentication_token character varying(30),
security_test character varying,
user_submissions_count integer,
user_submissions_count integer DEFAULT 0 NOT NULL,
flag character varying,
num_machines_added integer,
num_machines_removed integer,
num_locations_suggested integer,
num_lmx_comments_left integer,
num_msx_scores_added integer,
num_machines_added integer DEFAULT 0 NOT NULL,
num_machines_removed integer DEFAULT 0 NOT NULL,
num_locations_suggested integer DEFAULT 0 NOT NULL,
num_lmx_comments_left integer DEFAULT 0 NOT NULL,
num_msx_scores_added integer DEFAULT 0 NOT NULL,
contributor_rank character varying,
admin_title character varying
);
Expand Down Expand Up @@ -1795,6 +1795,8 @@ ALTER TABLE ONLY public.active_storage_attachments
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20241128060236'),
('20241128052830'),
('20241127215612'),
('20241127054132'),
('20241127051246'),
Expand Down
10 changes: 10 additions & 0 deletions spec/features/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
expect(page).to_not have_content('Saved Locations:')
end

it 'returns zeros when appropriate' do
visit "/users/#{@user.id}/profile"

expect(page).to have_content("0\nTOTAL CONTRIBUTIONS")
expect(page).to have_content("0\nMACHINES ADDED")
expect(page).to have_content("0\nMACHINES REMOVED")
expect(page).to have_content("0\nMACHINE COMMENTS")
expect(page).to have_content("0\nLOCATIONS SUBMITTED")
end

it 'adds commas to high scores' do
FactoryBot.create(:user_submission, user: @user, location: FactoryBot.create(:location, id: 500, name: 'Location One'), machine: FactoryBot.create(:machine, name: 'Machine One'), submission_type: UserSubmission::NEW_SCORE_TYPE, submission: 'ssw added a high score of 1000000 on Machine One at Location One', created_at: '2016-01-02')

Expand Down

0 comments on commit 8ae94f0

Please sign in to comment.