summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-01-11 09:39:08 -0700
committermo khan <mo@mokhan.ca>2015-01-11 09:39:08 -0700
commit2b450d0c49da229768467953bbdba9687fc40ee5 (patch)
treec7683a5d7f56cc40969c8d6176b1fe90d35faec4 /spec
parent227bdd2d5eb7532c5a5af7136f488fb410e1eabe (diff)
add tests for searching cakes.
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v2/cakes_controller_spec.rb26
-rw-r--r--spec/factories.rb3
2 files changed, 26 insertions, 3 deletions
diff --git a/spec/controllers/api/v2/cakes_controller_spec.rb b/spec/controllers/api/v2/cakes_controller_spec.rb
index f313285e..93ba4beb 100644
--- a/spec/controllers/api/v2/cakes_controller_spec.rb
+++ b/spec/controllers/api/v2/cakes_controller_spec.rb
@@ -6,10 +6,32 @@ module Api
render_views
describe "#index" do
- let!(:cake) { create(:published_cake) }
+ let!(:cakes) { create(:category, slug: 'cakes') }
+ let!(:cookies) { create(:category, slug: 'cookies') }
+ let!(:cake) { create(:published_cake, name: 'cake', category: cakes) }
+ let!(:cookie) { create(:published_cake, name: 'cookie', category: cookies) }
+ let!(:unpublished_cake) { create(:cake, name: 'unpublished', category: cakes) }
- it 'returns all cakes in the page' do
+ it 'returns all published cakes' do
xhr :get, :index
+ expect(assigns(:cakes)).to match_array([cake, cookie])
+ end
+
+ it 'returns all cakes in the category' do
+ xhr :get, :index, category: cookie.category.slug
+ expect(assigns(:cakes)).to match_array([cookie])
+ end
+
+ it 'returns all cakes matching the search query' do
+ xhr :get, :index, q: cake.name[0..2]
+ expect(assigns(:cakes)).to match_array([cake])
+ end
+
+ it 'returns all cakes tagged with the tag' do
+ cake.tag_list = 'cakes'
+ cake.save!
+
+ xhr :get, :index, tags: 'cakes'
expect(assigns(:cakes)).to match_array([cake])
end
end
diff --git a/spec/factories.rb b/spec/factories.rb
index 64309da3..8cdc18f3 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -15,6 +15,7 @@ FactoryGirl.define do
association :user
association :category
factory :published_cake do
+ photos_count 1
after(:create) do |cake, evaluator|
cake.photos << create(:photo, image: 'spec/fixtures/images/example.png')
end
@@ -81,4 +82,4 @@ FactoryGirl.define do
name { Faker::Name.name }
asin { SecureRandom.uuid }
end
-end \ No newline at end of file
+end