Add selected attribute to proposals
This commit is contained in:
@@ -74,6 +74,7 @@ class Proposal < ApplicationRecord
|
||||
scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) }
|
||||
scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) }
|
||||
scope :public_for_api, -> { all }
|
||||
scope :selected, -> { where(selected: true) }
|
||||
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) }
|
||||
scope :published, -> { where.not(published_at: nil) }
|
||||
scope :draft, -> { where(published_at: nil) }
|
||||
|
||||
5
db/migrate/20190410132842_add_selected_to_proposal.rb
Normal file
5
db/migrate/20190410132842_add_selected_to_proposal.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddSelectedToProposal < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :proposals, :selected, :bool, default: false, index: true
|
||||
end
|
||||
end
|
||||
@@ -1194,6 +1194,7 @@ ActiveRecord::Schema.define(version: 20190429125842) do
|
||||
t.text "retired_explanation"
|
||||
t.integer "community_id"
|
||||
t.datetime "published_at"
|
||||
t.boolean "selected", default: false
|
||||
t.index ["author_id", "hidden_at"], name: "index_proposals_on_author_id_and_hidden_at", using: :btree
|
||||
t.index ["author_id"], name: "index_proposals_on_author_id", using: :btree
|
||||
t.index ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
|
||||
|
||||
@@ -33,6 +33,10 @@ FactoryBot.define do
|
||||
created_at { 25.months.ago }
|
||||
end
|
||||
|
||||
trait :selected do
|
||||
selected true
|
||||
end
|
||||
|
||||
trait :with_hot_score do
|
||||
before(:save) { |d| d.calculate_hot_score }
|
||||
end
|
||||
|
||||
@@ -866,6 +866,23 @@ describe Proposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "selected" do
|
||||
let!(:unselected_proposal) { create(:proposal) }
|
||||
let!(:selected_proposal) { create(:proposal, :selected) }
|
||||
|
||||
it "selected? is true" do
|
||||
expect(unselected_proposal.selected?).to be false
|
||||
expect(selected_proposal.selected?).to be true
|
||||
end
|
||||
|
||||
it "scope selected" do
|
||||
selected = Proposal.selected
|
||||
|
||||
expect(selected.size).to be 1
|
||||
expect(selected.first).to eq selected_proposal
|
||||
end
|
||||
end
|
||||
|
||||
describe "public_for_api scope" do
|
||||
it "returns proposals" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
Reference in New Issue
Block a user