@@ -42,7 +42,7 @@ class Proposal < ActiveRecord::Base
|
|||||||
scope :sort_by_relevance , -> { all }
|
scope :sort_by_relevance , -> { all }
|
||||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||||
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
|
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
|
||||||
scope :in_categories, -> { where("lower(tags.name) IN (?)", ActsAsTaggableOn::Tag.category_names) }
|
scope :in_categories, -> { where("tags.name IN (?)", ActsAsTaggableOn::Tag.category_names) }
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => 'A',
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<% @proposals.each do |group_name, proposals| %>
|
<% @proposals.each do |group_name, proposals| %>
|
||||||
<div id="<%= group_name.parameterize %>">
|
<div id="<%= group_name.parameterize %>">
|
||||||
<h2 class="margin-top"><%= group_name %></h2>
|
<h2 class="margin-top"><%= group_name.capitalize %></h2>
|
||||||
|
|
||||||
<% proposals[0..2].each do |proposal| %>
|
<% proposals[0..2].each do |proposal| %>
|
||||||
<div class="proposal clear">
|
<div class="proposal clear">
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="proposal-description">
|
<div class="proposal-description">
|
||||||
<%= proposal.description %>
|
<p><%= proposal.summary %></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1166,11 +1166,11 @@ feature 'Proposals' do
|
|||||||
context "Summary" do
|
context "Summary" do
|
||||||
|
|
||||||
scenario "Displays proposals grouped by category" do
|
scenario "Displays proposals grouped by category" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
create(:tag, kind: 'category', name: 'Social Services')
|
create(:tag, kind: 'category', name: 'social services')
|
||||||
|
|
||||||
3.times { create(:proposal, tag_list: 'Culture') }
|
3.times { create(:proposal, tag_list: 'culture') }
|
||||||
3.times { create(:proposal, tag_list: 'Social Services') }
|
3.times { create(:proposal, tag_list: 'social services') }
|
||||||
|
|
||||||
create(:proposal, tag_list: 'Random')
|
create(:proposal, tag_list: 'Random')
|
||||||
|
|
||||||
@@ -1183,14 +1183,14 @@ feature 'Proposals' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
within("#social-services") do
|
within("#social-services") do
|
||||||
expect(page).to have_content("Social Services")
|
expect(page).to have_content("Social services")
|
||||||
expect(page).to have_css(".proposal", count: 3)
|
expect(page).to have_css(".proposal", count: 3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Displays a maximum of 3 proposals per category" do
|
scenario "Displays a maximum of 3 proposals per category" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
4.times { create(:proposal, tag_list: 'Culture') }
|
4.times { create(:proposal, tag_list: 'culture') }
|
||||||
|
|
||||||
visit summary_proposals_path
|
visit summary_proposals_path
|
||||||
|
|
||||||
@@ -1198,10 +1198,10 @@ feature 'Proposals' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Orders proposals by votes" do
|
scenario "Orders proposals by votes" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
create(:proposal, title: 'Best', tag_list: 'Culture').update_column(:confidence_score, 10)
|
create(:proposal, title: 'Best', tag_list: 'culture').update_column(:confidence_score, 10)
|
||||||
create(:proposal, title: 'Worst', tag_list: 'Culture').update_column(:confidence_score, 2)
|
create(:proposal, title: 'Worst', tag_list: 'culture').update_column(:confidence_score, 2)
|
||||||
create(:proposal, title: 'Medium', tag_list: 'Culture').update_column(:confidence_score, 5)
|
create(:proposal, title: 'Medium', tag_list: 'culture').update_column(:confidence_score, 5)
|
||||||
|
|
||||||
visit summary_proposals_path
|
visit summary_proposals_path
|
||||||
|
|
||||||
@@ -1210,10 +1210,10 @@ feature 'Proposals' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Displays proposals from last week" do
|
scenario "Displays proposals from last week" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
proposal1 = create(:proposal, tag_list: 'Culture', created_at: 1.day.ago)
|
proposal1 = create(:proposal, tag_list: 'culture', created_at: 1.day.ago)
|
||||||
proposal2 = create(:proposal, tag_list: 'Culture', created_at: 5.days.ago)
|
proposal2 = create(:proposal, tag_list: 'culture', created_at: 5.days.ago)
|
||||||
proposal3 = create(:proposal, tag_list: 'Culture', created_at: 8.days.ago)
|
proposal3 = create(:proposal, tag_list: 'culture', created_at: 8.days.ago)
|
||||||
|
|
||||||
visit summary_proposals_path
|
visit summary_proposals_path
|
||||||
|
|
||||||
|
|||||||
@@ -644,36 +644,36 @@ describe Proposal do
|
|||||||
|
|
||||||
describe "for_summary" do
|
describe "for_summary" do
|
||||||
it "should return proposals tagged with a category" do
|
it "should return proposals tagged with a category" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
proposal = create(:proposal, tag_list: 'Culture')
|
proposal = create(:proposal, tag_list: 'culture')
|
||||||
|
|
||||||
expect(Proposal.for_summary.values.flatten).to include(proposal)
|
expect(Proposal.for_summary.values.flatten).to include(proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not return proposals tagged without a category" do
|
it "should not return proposals tagged without a category" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
proposal = create(:proposal, tag_list: 'Parks')
|
proposal = create(:proposal, tag_list: 'parks')
|
||||||
|
|
||||||
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
|
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return proposals created this week" do
|
it "should return proposals created this week" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
proposal = create(:proposal, tag_list: 'Culture')
|
proposal = create(:proposal, tag_list: 'culture')
|
||||||
expect(Proposal.for_summary.values.flatten).to include(proposal)
|
expect(Proposal.for_summary.values.flatten).to include(proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not return proposals created more than a week ago" do
|
it "should not return proposals created more than a week ago" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
proposal = create(:proposal, tag_list: 'Culture', created_at: 8.days.ago)
|
proposal = create(:proposal, tag_list: 'culture', created_at: 8.days.ago)
|
||||||
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
|
expect(Proposal.for_summary.values.flatten).to_not include(proposal)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should order by votes" do
|
it "should order by votes" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
create(:proposal, tag_list: 'Culture').update_column(:confidence_score, 2)
|
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 2)
|
||||||
create(:proposal, tag_list: 'Culture').update_column(:confidence_score, 10)
|
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 10)
|
||||||
create(:proposal, tag_list: 'Culture').update_column(:confidence_score, 5)
|
create(:proposal, tag_list: 'culture').update_column(:confidence_score, 5)
|
||||||
|
|
||||||
results = Proposal.for_summary.values.flatten
|
results = Proposal.for_summary.values.flatten
|
||||||
|
|
||||||
@@ -683,18 +683,18 @@ describe Proposal do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should return proposals grouped by tag" do
|
it "should return proposals grouped by tag" do
|
||||||
create(:tag, kind: 'category', name: 'Culture')
|
create(:tag, kind: 'category', name: 'culture')
|
||||||
create(:tag, kind: 'category', name: 'Health')
|
create(:tag, kind: 'category', name: 'health')
|
||||||
|
|
||||||
proposal1 = create(:proposal, tag_list: 'Culture')
|
proposal1 = create(:proposal, tag_list: 'culture')
|
||||||
proposal2 = create(:proposal, tag_list: 'Culture')
|
proposal2 = create(:proposal, tag_list: 'culture')
|
||||||
proposal2.update_column(:confidence_score, 100)
|
proposal2.update_column(:confidence_score, 100)
|
||||||
proposal3 = create(:proposal, tag_list: 'Health')
|
proposal3 = create(:proposal, tag_list: 'health')
|
||||||
|
|
||||||
proposal1.update_column(:confidence_score, 10)
|
proposal1.update_column(:confidence_score, 10)
|
||||||
proposal2.update_column(:confidence_score, 9)
|
proposal2.update_column(:confidence_score, 9)
|
||||||
|
|
||||||
expect(Proposal.for_summary).to include('Culture' => [proposal1, proposal2], 'Health' => [proposal3])
|
expect(Proposal.for_summary).to include('culture' => [proposal1, proposal2], 'health' => [proposal3])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user