Skip to content

Commit

Permalink
Fix articles controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Feb 9, 2015
1 parent f70195d commit 77b7ddd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
10 changes: 6 additions & 4 deletions app/assets/stylesheets/controller/sessions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ h3 {
}

#private_sellers h2 {
background-color: orange;
border-color: darken(orange, 5%);
// orange background
background-color: #e5a83a;
border-color: darken(#e5a83a, 5%);
}

#business_sellers h2 {
background-color: purple;
border-color: darken(purple, 5%);
// purple-colored background
background-color: #983d98;
border-color: darken(#983d98, 5%);
}


Expand Down
55 changes: 38 additions & 17 deletions test/controllers/articles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,22 @@
@electronic_category = Category.find_by_name!("Elektronik")
@software_category = Category.find_by_name!("Software")

@normal_article = FactoryGirl.create(:article, :index_article, price_cents: 1, title: "noraml article thing", content: "super thing", created_at: 4.days.ago, id: 1234)
@second_hand_article = FactoryGirl.create(:second_hand_article, :index_article, price_cents: 2, title: "muscheln", categories: [ @vehicle_category ], content: "muscheln am meer", created_at: 3.days.ago, id: 1235)
@hardware_article = FactoryGirl.create(:second_hand_article, :index_article, :simple_fair,:simple_ecologic,:simple_small_and_precious,:with_ngo, price_cents: 3, title: "muscheln 2", categories: [ @hardware_category ], content: "abc" , created_at: 2.days.ago, id: 1236)
@no_second_hand_article = FactoryGirl.create :no_second_hand_article, :index_article, price_cents: 4, title: "muscheln 3", categories: [ @hardware_category ], content: "cde", id: 1237, created_at: 1.day.ago
@normal_article = FactoryGirl.create(:article, :index_article,
price_cents: 1, title: "noraml article thing", content: "super thing",
created_at: 4.days.ago, id: 1234)
@second_hand_article = FactoryGirl.create(:second_hand_article,
:index_article, price_cents: 2, title: "muscheln",
categories: [ @vehicle_category ], content: "muscheln am meer",
created_at: 3.days.ago, id: 1235)
@hardware_article = FactoryGirl.create(:second_hand_article,
:index_article, :simple_fair, :simple_ecologic,
:simple_small_and_precious,:with_ngo, price_cents: 3,
title: "muscheln 2", categories: [ @hardware_category ],
content: "abc" , created_at: 2.days.ago, id: 1236)
@no_second_hand_article = FactoryGirl.create :no_second_hand_article,
:index_article, price_cents: 4, title: "muscheln 3",
categories: [ @hardware_category ], content: "cde", id: 1237,
created_at: 1.day.ago
end

it "should work with all filters" do
Expand Down Expand Up @@ -241,7 +253,7 @@

it "should require login" do
get :new
assert_redirected_to(new_user_session_path)
assert_redirected_to(new_user_session_url(seller: true))
end

end
Expand Down Expand Up @@ -332,15 +344,17 @@
end

it "should save images even if article is invalid" do
@article_attrs = FactoryGirl.attributes_for :article, :invalid, categories: [FactoryGirl.create(:category).id]
@article_attrs = FactoryGirl.attributes_for :article, :invalid,
categories: [FactoryGirl.create(:category).id]
@article_attrs[:images_attributes] = { "0" => { image: fixture_file_upload("/test.png", 'image/png') }}
assert_difference 'Image.count', 1 do
post :create, article: @article_attrs
end
end

it "should not raise an error for very high quantity values" do
post :create, article: @article_attrs.merge(quantity: "100000000000000000000000")
post :create,
article: @article_attrs.merge(quantity: "100000000000000000000000")
assert_template :new
end

Expand All @@ -350,7 +364,8 @@
original_slug = original_article.slug

assert_difference 'Article.count', 1 do
post :create, article: @article_attrs.merge({original_id: original_article.id})
post :create,
article: @article_attrs.merge({original_id: original_article.id})
end
new_article = @controller.instance_variable_get(:@article)

Expand All @@ -371,7 +386,8 @@
describe "for signed-in users" do
before :each do
@article = FactoryGirl.create :preview_article, seller: user
@article_attrs = FactoryGirl.attributes_for :article, categories: [FactoryGirl.create(:category)]
@article_attrs = FactoryGirl.attributes_for :article,
categories: [FactoryGirl.create(:category)]
@article_attrs.delete :seller
sign_in user
end
Expand All @@ -385,7 +401,8 @@

it "should softdelete the locked article" do
assert_no_difference 'Article.count' do
put :update, id: @article.id, activate: true, article: { tos_accepted: '1' }
put :update, id: @article.id, activate: true,
article: { tos_accepted: '1' }
put :update, id: @article.id, deactivate: true
put :destroy, id: @article.id
end
Expand All @@ -398,7 +415,8 @@
describe "for signed-in users" do
before :each do
@article = FactoryGirl.create :preview_article, seller: user
@article_attrs = FactoryGirl.attributes_for :article, categories: [FactoryGirl.create(:category)]
@article_attrs = FactoryGirl.attributes_for :article,
categories: [FactoryGirl.create(:category)]
@article_attrs.delete :seller
sign_in user
end
Expand All @@ -411,7 +429,9 @@
it "changes the articles informations" do
put :update, id: @article.id, article: @article_attrs
assert_redirected_to @article.reload
@controller.instance_variable_get(:@article).title.must_equal @article_attrs[:title]
@controller
.instance_variable_get(:@article)
.title.must_equal @article_attrs[:title]
end
end

Expand All @@ -422,7 +442,8 @@
end

it "should work" do
put :update, id: @article.id, article: { tos_accepted: '1' }, activate: true
put :update, id: @article.id, article: { tos_accepted: '1' },
activate: true
assert_redirected_to @article
flash[:notice].must_equal I18n.t 'article.notices.create_html'
end
Expand All @@ -431,7 +452,8 @@
@article.title = nil
@article.save validate: false
## we now have an invalid record
put :update, id: @article.id, article: { tos_accepted: '1' }, activate: true
put :update, id: @article.id, article: { tos_accepted: '1' },
activate: true
assert_redirected_to new_article_path(edit_as_new: @article.id)
end
end
Expand Down Expand Up @@ -465,7 +487,8 @@

it "should be successful" do
ArticlesIndex.reset!
@article = FactoryGirl.create :article, :index_article, title: 'chunky bacon'
@article = FactoryGirl.create :article, :index_article,
title: 'chunky bacon'
get :autocomplete, q: 'chunky'
assert_response :success
response.body.must_equal({
Expand All @@ -490,6 +513,4 @@
end
end



end

0 comments on commit 77b7ddd

Please sign in to comment.