Commit 2a48ce44

mo khan <mo@mokhan.ca>
2014-10-19 02:58:29
remove all cakes query.
1 parent 6a07158
Changed files (4)
app
controllers
services
spec
models
services
app/controllers/cakes_controller.rb
@@ -1,6 +1,11 @@
 class CakesController < ApplicationController
+  def initialize(repository = Spank::IOC.resolve(:cakes))
+    @repository = repository
+    super()
+  end
+
   def index
-    @creations = AllCakesQuery.new.fetch(params).page(page).per(per_page)
+    @creations = @repository.search_with(params).page(page).per(per_page)
   end
 
   def show
app/services/application/all_cakes_query.rb
@@ -1,9 +0,0 @@
-class AllCakesQuery
-  def initialize(repository = Spank::IOC.resolve(:cakes))
-    @repository = repository
-  end
-
-  def fetch(params)
-    @repository.search_with(params)
-  end
-end
spec/models/creation/repository_spec.rb
@@ -46,4 +46,27 @@ describe Creation::Repository do
       expect(results).to_not include(cup_cake)
     end
   end
+
+  context "#search_with" do
+    let(:cake_category) { create(:category) }
+    let!(:cake) { create(:cake, category: cake_category) }
+    let!(:cookie) { create(:cake) }
+
+    before :each do
+      cake.photos << create(:photo)
+      cookie.photos << create(:photo)
+    end
+
+    it 'returns all cakes in a specific category' do
+      cakes = subject.search_with(category: cake_category.slug)
+      expect(cakes).to include(cake)
+      expect(cakes).to_not include(cookie)
+    end
+
+    it 'returns all cakes that match the search query' do
+      cakes = subject.search_with(q: cake.name[0..2])
+      expect(cakes).to include(cake)
+      expect(cakes).to_not include(cookie)
+    end
+  end
 end
spec/services/application/all_cakes_query_spec.rb
@@ -1,47 +0,0 @@
-require "rails_helper"
-
-describe AllCakesQuery do
-  subject { AllCakesQuery.new }
-
-  context "with no filters" do
-    let!(:cake_with_a_photo) { create(:cake) }
-    let!(:cake_without_a_photo) { create(:cake, photos: []) }
-
-    before :each do
-      cake_with_a_photo.photos << create(:photo)
-    end
-
-    it "returns all cakes with at least one photo" do
-      results = subject.fetch({})
-      expect(results).to include(cake_with_a_photo)
-    end
-
-    it "ignores cakes without a photo" do
-      results = subject.fetch({})
-      expect(results).to_not include(cake_without_a_photo)
-    end
-  end
-
-  context "with filters" do
-    let(:cake_category) { create(:category) }
-    let!(:cake) { create(:cake, category: cake_category) }
-    let!(:cookie) { create(:cake) }
-
-    before :each do
-      cake.photos << create(:photo)
-      cookie.photos << create(:photo)
-    end
-
-    it 'returns all cakes in a specific category' do
-      cakes = subject.fetch(category: cake_category.slug)
-      expect(cakes).to include(cake)
-      expect(cakes).to_not include(cookie)
-    end
-
-    it 'returns all cakes that match the search query' do
-      cakes = subject.fetch(q: cake.name[0..2])
-      expect(cakes).to include(cake)
-      expect(cakes).to_not include(cookie)
-    end
-  end
-end