Skip to content

Commit

Permalink
Revert "Clean feedback controller"
Browse files Browse the repository at this point in the history
This reverts commit b81f31e.
  • Loading branch information
Yannick Francois committed Sep 23, 2013
1 parent 8bb5524 commit eb5f126
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 29 deletions.
16 changes: 15 additions & 1 deletion app/controllers/admin/feedback_controller.rb
Expand Up @@ -103,6 +103,18 @@ def update
end
end

def article
@article = Article.find(params[:id])
if params[:ham] && params[:spam].blank?
@feedback = @article.comments.ham
end
if params[:spam] && params[:ham].blank?
@feedback = @article.comments.spam
end
@feedback ||= @article.comments
end


def change_state
return unless request.xhr?

Expand All @@ -128,6 +140,7 @@ def change_state
def bulkops
ids = (params[:feedback_check]||{}).keys.map(&:to_i)
items = Feedback.find(ids)
@unexpired = true

bulkop = params[:bulkop_top].empty? ? params[:bulkop_bottom] : params[:bulkop_top]
case bulkop
Expand Down Expand Up @@ -177,12 +190,13 @@ def delete_all_spam
def update_feedback(items, method)
items.each do |value|
value.send(method)
value.invalidates_cache? or next
@unexpired && value.invalidates_cache? or next
flush_cache
end
end

def flush_cache
@unexpired = false
PageCache.sweep_all
end

Expand Down
57 changes: 29 additions & 28 deletions app/views/admin/feedback/index.html.erb
Expand Up @@ -5,7 +5,7 @@
<div>
<span class='badge badge-inverse'>
<%= link_to(_("All"), controller: 'admin/feedback', action: :index) %>
</span>&nbsp;
</span>&nbsp;
<span class='badge'>
<%= link_to(_("Unapproved comments"), controller: 'admin/feedback', action: :index, confirmed: 'f') %>
</span>&nbsp;
Expand All @@ -21,40 +21,41 @@
<span class='badge badge-warning'>
<%= link_to(_("Presumed spam"), controller: 'admin/feedback', action: :index, published: 'f') %>
</span>&nbsp;
<div class='pull-right input-append'>
<input type="text" id="feedback_search" name="search" value="<%=h params[:search] %>" class='medium' />
<%= submit_tag(_("Search"), {:class => 'btn'}) %>
</div>
<div class='pull-right input-append'>
<input type="text" id="feedback_search" name="search" value="<%=h params[:search] %>" class='medium' />
<%= submit_tag(_("Search"), {:class => 'btn'}) %>
</div>
</div>
<% end %>
<%= form_tag({action: 'bulkops'}) do %>
<%= render 'button', { position: 'top' } %>
<%= hidden_field_tag "search", params[:search]%>
<%= hidden_field_tag "page", params[:page]%>
<%= form_tag({:action => 'bulkops'}) do %>
<%= render 'button', { :position => 'top' } %>
<table class='table table-striped'>
<thead>
<tr class='noborder'>
<th><input type="checkbox" name="checkall" id="checkall" onclick="check_all(this);"/></th>
<th><%= _("Status")%></th>
<th><%= _("Comment Author")%></th>
<th><%= _("Comment")%></th>
<th><%= _("Article")%></th>
</tr>
</thead>
<%= render_void_table(@feedback.size, 5) %>
<%= hidden_field_tag "search", params[:search]%>
<%= hidden_field_tag "page", params[:page]%>

<% @feedback.each do |comment| %>
<%= render 'feedback', {comment: comment} %>
<% end %>
<%= display_pagination(@feedback, 5) %>
<tr>
<table class='table table-striped'>
<thead>
<tr class='noborder'>
<th><input type="checkbox" name="checkall" id="checkall" onclick="check_all(this);"/></th>
<th colspan='4'><%= _("Select all") %></th>
<th><%= _("Status")%></th>
<th><%= _("Comment Author")%></th>
<th><%= _("Comment")%></th>
<th><%= _("Article")%></th>
</tr>
</table>
<%= render 'button', { position: 'bottom' } %>
</thead>
<%= render_void_table(@feedback.size, 5) %>
<% @feedback.each do |comment| %>
<%= render 'feedback', {:comment => comment} %>
<% end %>
<%= display_pagination(@feedback, 5) %>
<tr>
<th><input type="checkbox" name="checkall" id="checkall" onclick="check_all(this);"/></th>
<th colspan='4'><%= _("Select all") %></th>
</tr>
</table>
<%= render 'button', { :position => 'bottom' } %>
<% end %>

<br class='clear' />
44 changes: 44 additions & 0 deletions spec/controllers/admin/feedback_controller_spec.rb
Expand Up @@ -135,6 +135,50 @@ def should_success_with_index(response)
get :index, :page => ''
should_success_with_index(response)
end

end

describe 'article action' do

def should_success_with_article_view(response)
response.should be_success
response.should render_template('article')
end

it 'should see all feedback on one article' do
article = FactoryGirl.create(:article)
FactoryGirl.create(:comment, :article => article)
FactoryGirl.create(:comment, :article => article)
get :article, :id => article.id
should_success_with_article_view(response)
assigns(:article).should == article
assigns(:feedback).size.should == 2
end

it 'should see only spam feedback on one article' do
article = FactoryGirl.create(:article)
FactoryGirl.create(:comment, :state => 'spam', :article => article)
get :article, :id => article.id, :spam => 'y'
should_success_with_article_view(response)
assigns(:article).should == article
assigns(:feedback).size.should == 1
end

it 'should see only ham feedback on one article' do
article = FactoryGirl.create(:article)
comment = FactoryGirl.create(:comment, :article => article)
get :article, :id => article.id, :ham => 'y'
should_success_with_article_view(response)
assigns(:article).should == article
assigns(:feedback).size.should == 1
end

it 'should redirect_to index if bad article id' do
lambda{
get :article, :id => 102302
}.should raise_error(ActiveRecord::RecordNotFound)
end

end

describe 'create action' do
Expand Down

0 comments on commit eb5f126

Please sign in to comment.