summaryrefslogtreecommitdiff
path: root/spec/controllers/api/v2
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/controllers/api/v2
parent227bdd2d5eb7532c5a5af7136f488fb410e1eabe (diff)
add tests for searching cakes.
Diffstat (limited to 'spec/controllers/api/v2')
-rw-r--r--spec/controllers/api/v2/cakes_controller_spec.rb26
1 files changed, 24 insertions, 2 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