Skip to content

Commit

Permalink
Merge pull request #1058 from publify/issue-898-bulkops-error
Browse files Browse the repository at this point in the history
Provide correct article_id input in bulkops form
  • Loading branch information
mvz committed Mar 6, 2022
2 parents 9028b1a + 5cf9751 commit 84e67ac
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
9 changes: 5 additions & 4 deletions publify_core/app/views/admin/feedback/article.html.erb
@@ -1,12 +1,13 @@
<% content_for :page_heading do %>
<h2 class="page-title">
<%= t('.comments_for_html', title: @article.title) %>
</h2>
<h2 class="page-title">
<%= t('.comments_for_html', title: @article.title) %>
</h2>
<% end %>
<%= form_tag({ action: 'bulkops' }, { class: 'form-inline' }) do %>
<%= hidden_field 'article_id', @article.id %>
<%= hidden_field_tag 'article_id', @article.id %>
<%= render 'button', position: 'top' %>

<br class='clear' />
Expand Down
1 change: 1 addition & 0 deletions publify_core/app/views/admin/feedback/index.html.erb
Expand Up @@ -40,6 +40,7 @@
</td>
</tr>
<% end %>
<% @feedback.each do |comment| %>
<%= render 'feedback', comment: comment %>
<% end %>
Expand Down
65 changes: 41 additions & 24 deletions publify_core/spec/controllers/admin/feedback_controller_spec.rb
Expand Up @@ -58,7 +58,7 @@
end
end

describe "index" do
describe "#index" do
let!(:spam) { create(:spam_comment) }
let!(:unapproved) { create(:unconfirmed_comment) }
let!(:presumed_ham) { create(:presumed_ham_comment) }
Expand Down Expand Up @@ -108,45 +108,57 @@
end
end

describe "article action" do
describe "#article" do
# render_template
let(:article) { create(:article) }
let!(:ham) { create(:comment, article: article) }
let!(:spam) { create(:comment, article: article, state: "spam") }

def should_success_with_article_view(response)
expect(response).to be_successful
expect(response).to render_template("article")
it "sees all feedback on one article" do
get :article, params: { id: article.id }
aggregate_failures do
expect(response).to be_successful
expect(response).to render_template("article")
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [ham, spam]
end
end

it "sees all feedback on one article" do
it "includes hidden article id field in bulkops form" do
get :article, params: { id: article.id }
should_success_with_article_view(response)
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [ham, spam]
expect(response.body).
to have_css("form[action='/admin/feedback/bulkops'] input[name=article_id]",
visible: :hidden)
end

it "sees only spam feedback on one article" do
get :article, params: { id: article.id, spam: "y" }
should_success_with_article_view(response)
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [spam]
aggregate_failures do
expect(response).to be_successful
expect(response).to render_template("article")
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [spam]
end
end

it "sees only ham feedback on one article" do
get :article, params: { id: article.id, ham: "y" }
should_success_with_article_view(response)
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [ham]
aggregate_failures do
expect(response).to be_successful
expect(response).to render_template("article")
expect(assigns(:article)).to eq(article)
expect(assigns(:feedback)).to match_array [ham]
end
end

it "redirect_toes index if bad article id" do
it "renders error if bad article id" do
expect do
get :article, params: { id: 102_302 }
end.to raise_error(ActiveRecord::RecordNotFound)
end
end

describe "create action" do
describe "#create" do
def base_comment(options = {})
{ "body" => "a new comment", "author" => "Me", "url" => "https://bar.com/",
"email" => "foo@bar.com" }.merge(options)
Expand Down Expand Up @@ -193,7 +205,7 @@ def base_comment(options = {})
end
end

describe "edit action" do
describe "#edit" do
it "renders edit form" do
article = create(:article)
comment = create(:comment, article: article)
Expand All @@ -205,7 +217,7 @@ def base_comment(options = {})
end
end

describe "update action" do
describe "#update" do
it "updates comment if post request" do
article = create(:article)
comment = create(:comment, article: article)
Expand All @@ -218,7 +230,7 @@ def base_comment(options = {})
expect(comment.body).to eq("updated comment")
end

it "does not update comment if get request" do
it "does not update comment if get request" do
comment = create(:comment)
get "update", params: { id: comment.id,
comment: { author: "Bob Foo2",
Expand All @@ -240,7 +252,7 @@ def base_comment(options = {})
sign_in publisher
end

describe "destroy action" do
describe "#destroy" do
it_behaves_like "destroy feedback with feedback from own article"

it "does not destroy feedback doesn't own" do
Expand All @@ -253,7 +265,7 @@ def base_comment(options = {})
end
end

describe "edit action" do
describe "#edit" do
it "does not edit comment no own article" do
get "edit", params: { id: feedback_from_not_own_article.id }
expect(response).to redirect_to(action: "index")
Expand All @@ -268,7 +280,7 @@ def base_comment(options = {})
end
end

describe "update action" do
describe "#update" do
it "updates comment if own article" do
post "update", params: { id: feedback_from_own_article.id,
comment: { author: "Bob Foo2",
Expand All @@ -292,11 +304,16 @@ def base_comment(options = {})
end

describe "#bulkops action" do
it "redirect to index" do
it "redirects to index" do
post :bulkops, params: { bulkop_top: "destroy all spam" }
expect(@response).to redirect_to(action: "index")
end

it "redirects to article when id is given" do
post :bulkops, params: { article_id: article.id, bulkop_top: "destroy all spam" }
expect(@response).to redirect_to article_admin_feedback_url(article)
end

it "delete all spam" do
Feedback.delete_all
create(:comment, state: :spam)
Expand Down

0 comments on commit 84e67ac

Please sign in to comment.