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:
@@ -1,7 +1,6 @@
|
|||||||
class Comment < ActiveRecord::Base
|
class Comment < ActiveRecord::Base
|
||||||
include Flaggable
|
include Flaggable
|
||||||
include HasPublicAuthor
|
include HasPublicAuthor
|
||||||
include PublicVotersStats
|
|
||||||
|
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -8,7 +8,6 @@ class Debate < ActiveRecord::Base
|
|||||||
include Searchable
|
include Searchable
|
||||||
include Filterable
|
include Filterable
|
||||||
include HasPublicAuthor
|
include HasPublicAuthor
|
||||||
include PublicVotersStats
|
|
||||||
|
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class Proposal < ActiveRecord::Base
|
|||||||
include Searchable
|
include Searchable
|
||||||
include Filterable
|
include Filterable
|
||||||
include HasPublicAuthor
|
include HasPublicAuthor
|
||||||
include PublicVotersStats
|
|
||||||
|
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|||||||
@@ -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")
|
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
|
end
|
||||||
|
|
||||||
def public_voter
|
|
||||||
votable.votes_above_threshold? ? voter : nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def public_timestamp
|
def public_timestamp
|
||||||
self.created_at.change(min: 0)
|
self.created_at.change(min: 0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
class Voter < User
|
|
||||||
end
|
|
||||||
@@ -5,12 +5,6 @@ User:
|
|||||||
debates: [Debate]
|
debates: [Debate]
|
||||||
proposals: [Proposal]
|
proposals: [Proposal]
|
||||||
comments: [Comment]
|
comments: [Comment]
|
||||||
Voter:
|
|
||||||
fields:
|
|
||||||
gender: string
|
|
||||||
age_range: string
|
|
||||||
geozone_id: integer
|
|
||||||
geozone: Geozone
|
|
||||||
Debate:
|
Debate:
|
||||||
fields:
|
fields:
|
||||||
id: integer
|
id: integer
|
||||||
@@ -86,4 +80,3 @@ Vote:
|
|||||||
votable_id: integer
|
votable_id: integer
|
||||||
votable_type: string
|
votable_type: string
|
||||||
public_timestamp: string
|
public_timestamp: string
|
||||||
public_voter: Voter
|
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ Setting.create(key: 'proposal_code_prefix', value: 'MAD')
|
|||||||
Setting.create(key: 'votes_for_proposal_success', value: '100')
|
Setting.create(key: 'votes_for_proposal_success', value: '100')
|
||||||
Setting.create(key: 'months_to_archive_proposals', value: '12')
|
Setting.create(key: 'months_to_archive_proposals', value: '12')
|
||||||
Setting.create(key: 'comments_body_max_length', value: '1000')
|
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_handle', value: '@consul_dev')
|
||||||
Setting.create(key: 'twitter_hashtag', value: '#consul_dev')
|
Setting.create(key: 'twitter_hashtag', value: '#consul_dev')
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -69,7 +69,6 @@ module GraphQL
|
|||||||
|
|
||||||
file.each do |api_type_model, api_type_info|
|
file.each do |api_type_model, api_type_info|
|
||||||
model = api_type_model.constantize
|
model = api_type_model.constantize
|
||||||
options = api_type_info['options']
|
|
||||||
fields = {}
|
fields = {}
|
||||||
|
|
||||||
api_type_info['fields'].each do |field_name, field_type|
|
api_type_info['fields'].each do |field_name, field_type|
|
||||||
@@ -82,7 +81,7 @@ module GraphQL
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
api_type_definitions[model] = { options: options, fields: fields }
|
api_type_definitions[model] = { fields: fields }
|
||||||
end
|
end
|
||||||
|
|
||||||
api_type_definitions
|
api_type_definitions
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user