From e3fca5c49f0f8008c88978f0e1f9f0548453ea38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Miedes=20Garc=C3=A9s?= Date: Wed, 25 Jan 2017 13:37:29 +0100 Subject: [PATCH] Remove functionality related to votes demographic info Since this was giving me too much pain and nobody actually requested this functionality, I decided to remove it. --- app/models/comment.rb | 1 - app/models/concerns/public_voters_stats.rb | 12 ------------ app/models/debate.rb | 1 - app/models/proposal.rb | 1 - app/models/vote.rb | 4 ---- app/models/voter.rb | 2 -- config/api.yml | 7 ------- db/dev_seeds.rb | 3 --- lib/age_range_calculator.rb | 15 --------------- lib/graph_ql/api_types_creator.rb | 3 +-- spec/lib/age_range_calculator_spec.rb | 14 -------------- 11 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 app/models/concerns/public_voters_stats.rb delete mode 100644 app/models/voter.rb delete mode 100644 lib/age_range_calculator.rb delete mode 100644 spec/lib/age_range_calculator_spec.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index 5671fa1dc..118e56b28 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,7 +1,6 @@ class Comment < ActiveRecord::Base include Flaggable include HasPublicAuthor - include PublicVotersStats acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/concerns/public_voters_stats.rb b/app/models/concerns/public_voters_stats.rb deleted file mode 100644 index 88d695f20..000000000 --- a/app/models/concerns/public_voters_stats.rb +++ /dev/null @@ -1,12 +0,0 @@ -module PublicVotersStats - - def votes_above_threshold? - threshold = Setting["#{self.class.name.downcase}_api_votes_threshold"] - threshold = (threshold ? threshold.to_i : default_threshold) - (total_votes >= threshold) - end - - def default_threshold - 200 - end -end diff --git a/app/models/debate.rb b/app/models/debate.rb index 34fcf548e..ce5b63fd7 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -8,7 +8,6 @@ class Debate < ActiveRecord::Base include Searchable include Filterable include HasPublicAuthor - include PublicVotersStats acts_as_votable acts_as_paranoid column: :hidden_at diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 527ed7968..0cfc9bcc9 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -7,7 +7,6 @@ class Proposal < ActiveRecord::Base include Searchable include Filterable include HasPublicAuthor - include PublicVotersStats acts_as_votable acts_as_paranoid column: :hidden_at diff --git a/app/models/vote.rb b/app/models/vote.rb index 15d486ea4..93bcc54be 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -7,10 +7,6 @@ class Vote < ActsAsVotable::Vote where("votable_type = 'Proposal' AND proposals.hidden_at IS NULL OR votable_type = 'Debate' AND debates.hidden_at IS NULL OR votable_type = 'Comment' AND comments.hidden_at IS NULL") end - def public_voter - votable.votes_above_threshold? ? voter : nil - end - def public_timestamp self.created_at.change(min: 0) end diff --git a/app/models/voter.rb b/app/models/voter.rb deleted file mode 100644 index 7d4f52676..000000000 --- a/app/models/voter.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Voter < User -end diff --git a/config/api.yml b/config/api.yml index a8eb1efbe..7e8559ced 100644 --- a/config/api.yml +++ b/config/api.yml @@ -5,12 +5,6 @@ User: debates: [Debate] proposals: [Proposal] comments: [Comment] -Voter: - fields: - gender: string - age_range: string - geozone_id: integer - geozone: Geozone Debate: fields: id: integer @@ -86,4 +80,3 @@ Vote: votable_id: integer votable_type: string public_timestamp: string - public_voter: Voter diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 347994a00..4a716a160 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -15,9 +15,6 @@ Setting.create(key: 'proposal_code_prefix', value: 'MAD') Setting.create(key: 'votes_for_proposal_success', value: '100') Setting.create(key: 'months_to_archive_proposals', value: '12') Setting.create(key: 'comments_body_max_length', value: '1000') -Setting.create(key: 'debate_api_votes_threshold', value: '2') -Setting.create(key: 'proposal_api_votes_threshold', value: '2') -Setting.create(key: 'comment_api_votes_threshold', value: '2') Setting.create(key: 'twitter_handle', value: '@consul_dev') Setting.create(key: 'twitter_hashtag', value: '#consul_dev') diff --git a/lib/age_range_calculator.rb b/lib/age_range_calculator.rb deleted file mode 100644 index acb12e19e..000000000 --- a/lib/age_range_calculator.rb +++ /dev/null @@ -1,15 +0,0 @@ -class AgeRangeCalculator - - MIN_AGE = 16 - MAX_AGE = 1.0/0.0 # Infinity - RANGES = [ (MIN_AGE..25), (26..40), (41..60), (61..MAX_AGE) ] - - def self.range_from_birthday(dob) - # Inspired by: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby/2357790#2357790 - now = Time.current.to_date - age = now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) - - index = RANGES.find_index { |range| range.include?(age) } - index ? RANGES[index] : nil - end -end diff --git a/lib/graph_ql/api_types_creator.rb b/lib/graph_ql/api_types_creator.rb index cf266d13f..03ddd5d3a 100644 --- a/lib/graph_ql/api_types_creator.rb +++ b/lib/graph_ql/api_types_creator.rb @@ -69,7 +69,6 @@ module GraphQL file.each do |api_type_model, api_type_info| model = api_type_model.constantize - options = api_type_info['options'] fields = {} api_type_info['fields'].each do |field_name, field_type| @@ -82,7 +81,7 @@ module GraphQL end end - api_type_definitions[model] = { options: options, fields: fields } + api_type_definitions[model] = { fields: fields } end api_type_definitions diff --git a/spec/lib/age_range_calculator_spec.rb b/spec/lib/age_range_calculator_spec.rb deleted file mode 100644 index a6fd183ed..000000000 --- a/spec/lib/age_range_calculator_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -describe AgeRangeCalculator do - subject { AgeRangeCalculator } - - describe '::range_from_birthday' do - it 'returns the age range' do - expect(subject::range_from_birthday(Time.current - 1.year)).to eq(nil) - expect(subject::range_from_birthday(Time.current - 26.year)).to eq(26..40) - expect(subject::range_from_birthday(Time.current - 60.year)).to eq(41..60) - expect(subject::range_from_birthday(Time.current - 200.year)).to eq(61..subject::MAX_AGE) - end - end -end