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.
This commit is contained in:
Alberto Miedes Garcés
2017-01-25 13:37:29 +01:00
parent ef6d089022
commit e3fca5c49f
11 changed files with 1 additions and 62 deletions

View File

@@ -1,7 +1,6 @@
class Comment < ActiveRecord::Base
include Flaggable
include HasPublicAuthor
include PublicVotersStats
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,2 +0,0 @@
class Voter < User
end

View File

@@ -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

View File

@@ -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')

View File

@@ -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

View File

@@ -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

View File

@@ -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