Skip to content
Permalink
Browse files
Show all articles, including drafts, when using default admin filter
Default behaviour when landing on "All Articles" section as well as
when using the filter for ALL should include drafts along with the
rest of the various publish states.

Can then filter to show just all published, all drafts, etc. as
needed.

Updates function name from `function_search_no_draft` to
`function_search_all_posts` to match new behaviour.
  • Loading branch information
randomecho committed Dec 13, 2012
1 parent 6f3ab89 commit 60b3603a8f488f009cba5ac37e376a820bb033b6
@@ -105,9 +105,13 @@ def self.last_draft(article_id)
end

def self.search_with_pagination(search_hash, paginate_hash)
state = (search_hash[:state] and ["no_draft", "drafts", "published", "withdrawn", "pending"].include? search_hash[:state]) ? search_hash[:state] : 'no_draft'
state = (search_hash[:state] and ["no_draft", "drafts", "published", "withdrawn", "pending"].include? search_hash[:state]) ? search_hash[:state] : nil

list_function = ["Article.#{state}"] + function_search_no_draft(search_hash)
if state.nil?
list_function = function_search_all_posts(search_hash)
elsif
list_function = ["Article.#{state}"] + function_search_all_posts(search_hash)
end

if search_hash[:category] && search_hash[:category].to_i > 0
list_function << 'category(search_hash[:category])'
@@ -54,7 +54,7 @@ def self.find_already_published(limit)
where('published_at < ?', Time.now).limit(1000).order('created_at DESC')
end

# Use only for self.function_search_no_draft method
# Use only for self.function_search_all_posts method
scope :published_at_like, lambda {|date_at| {:conditions => {
:published_at => (
if date_at =~ /\d{4}-\d{2}-\d{2}/
@@ -70,7 +70,7 @@ def self.find_already_published(limit)
}
}

def self.function_search_no_draft(search_hash)
def self.function_search_all_posts(search_hash)
list_function = []
search_hash ||= {}

@@ -21,7 +21,7 @@
<tr class='noborder'>
<td>
<select name="search[state]">
<option value='no_draft'><%= _("All articles") %></option>
<option value=''><%= _("All articles") %></option>
<option value='published'><%= _("Published") %></option>
<option value='pending'><%= _("Publication pending") %></option>
<option value='drafts'><%= _("Drafts") %></option>
@@ -751,10 +751,11 @@ def assert_sets_trigger(art)
Article.search_with_pagination({}, {page: nil, per_page: 1}).should eq([article])
end

it "returns no draft article by default" do
it "returns both published and draft articles by default" do
article = FactoryGirl.create(:article, state: 'published')
draft_article = FactoryGirl.create(:article, state: 'draft')
Article.search_with_pagination({}, {page: nil, per_page: 12}).should eq([article])
result = Article.search_with_pagination({}, {page: nil, per_page: 12})
result.count.should eq 2
end

it "returns article of search categorie" do
@@ -59,34 +59,34 @@
end
end

describe "#function_search_no_draft" do
describe "#function_search_all_posts" do
it "returns empty array when nil given" do
Content.function_search_no_draft(nil).should be_empty
Content.function_search_all_posts(nil).should be_empty
end

it "returns article that match with searchstring" do
expected_function = ['searchstring(search_hash[:searchstring])']
Content.function_search_no_draft({searchstring: 'something'}).should eq expected_function
Content.function_search_all_posts({searchstring: 'something'}).should eq expected_function
end

it "returns article that match with published_at" do
expected_function = ['published_at_like(search_hash[:published_at])']
Content.function_search_no_draft({published_at: '2012-02'}).should eq expected_function
Content.function_search_all_posts({published_at: '2012-02'}).should eq expected_function
end

it "returns article that match with user_id" do
expected_function = ['user_id(search_hash[:user_id])']
Content.function_search_no_draft({user_id: '1'}).should eq expected_function
Content.function_search_all_posts({user_id: '1'}).should eq expected_function
end

it "returns article that match with not published" do
expected_function = ['not_published']
Content.function_search_no_draft({published: '0'}).should eq expected_function
Content.function_search_all_posts({published: '0'}).should eq expected_function
end

it "returns article that match with published" do
expected_function = ['published']
Content.function_search_no_draft({published: '1'}).should eq expected_function
Content.function_search_all_posts({published: '1'}).should eq expected_function
end

end

0 comments on commit 60b3603

Please sign in to comment.