Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix spec. Order search by created_at because draft post have no
published date.

Clean some hash syntax
  • Loading branch information
Yannick Francois committed Aug 26, 2013
1 parent ee15619 commit b60461d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
22 changes: 10 additions & 12 deletions app/models/article.rb
Expand Up @@ -15,24 +15,22 @@ class Article < Content

belongs_to :user

has_many :pings, :dependent => :destroy, :order => "created_at ASC"
has_many :trackbacks, :dependent => :destroy, :order => "created_at ASC"
has_many :feedback, :order => "created_at DESC"
has_many :resources, :order => "created_at DESC", :dependent => :nullify
has_many :pings, dependent: :destroy, order: "created_at ASC"
has_many :trackbacks, dependent: :destroy, order: "created_at ASC"
has_many :feedback, order: "created_at DESC"
has_many :resources, order: "created_at DESC", dependent: :nullify
has_many :categorizations
has_many :categories, :through => :categorizations
has_many :triggers, :as => :pending_item

has_many :comments, :dependent => :destroy, :order => "created_at ASC" do

has_many :categories, through: :categorizations
has_many :triggers, as: :pending_item
has_many :comments, dependent: :destroy, order: "created_at ASC" do
# Get only ham or presumed_ham comments
def ham
where(:state => ["presumed_ham", "ham"])
where(state: ["presumed_ham", "ham"])
end

# Get only spam or presumed_spam comments
def spam
where(:state => ["presumed_spam", "spam"])
where(state: ["presumed_spam", "spam"])
end
end

Expand Down Expand Up @@ -124,7 +122,7 @@ def self.search_with(params)
scoped = scoped.category(params[:category])
end

scoped.order('published_at DESC').order('created_at DESC')
scoped.order('created_at DESC')
end

def permalink_url(anchor=nil, only_path=false)
Expand Down
6 changes: 3 additions & 3 deletions spec/models/article_spec.rb
Expand Up @@ -663,9 +663,9 @@ def assert_sets_trigger(art)
let(:params) { nil }
let(:now) { DateTime.new(2011,3,12) }
let!(:article) { create(:article, state: 'published', created_at: now) }
let!(:last_draft_article) { create(:article, state: 'draft', created_at: now + 2.days, published_at: nil) }
let!(:draft_article) { create(:article, state: 'draft', created_at: now + 20.days, published_at:nil) }
it { expect(subject).to eq([article, draft_article, last_draft_article]) }
let!(:last_draft_article) { create(:article, state: 'draft', created_at: now + 2.days) }
let!(:draft_article) { create(:article, state: 'draft', created_at: now + 20.days) }
it { expect(subject).to eq([draft_article, last_draft_article, article]) }
end

context "with two articles in two catageory" do
Expand Down

0 comments on commit b60461d

Please sign in to comment.