summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-10-16 20:43:15 -0600
committermo khan <mo@mokhan.ca>2014-10-16 20:43:15 -0600
commit4eb7dd4fb2ed71006aee665ae7f666ee88d44c22 (patch)
treee97551e8248a239a958fe7d2a7ff9bea5e75e183
parentf2eef36abce2148fe044b6dbda85fadf77754019 (diff)
remove usage of find cake by id query object.
-rw-r--r--app/controllers/creations_controller.rb8
-rw-r--r--app/controllers/favorites_controller.rb2
-rw-r--r--app/services/application/find_creation_query.rb9
-rw-r--r--spec/controllers/creations_controller_spec.rb20
4 files changed, 16 insertions, 23 deletions
diff --git a/app/controllers/creations_controller.rb b/app/controllers/creations_controller.rb
index 6db6b203..618d9986 100644
--- a/app/controllers/creations_controller.rb
+++ b/app/controllers/creations_controller.rb
@@ -4,11 +4,7 @@ class CreationsController < ApplicationController
end
def show
- @creation = FindCreationQuery.new.fetch(params[:id])
- if params[:photo_id].present?
- @primary_image = @creation.photos.find(params[:photo_id])
- else
- @primary_image = @creation.primary_image
- end
+ @creation = Creation.find(params[:id])
+ @primary_image = params[:photo_id].present? ? @creation.photos.find(params[:photo_id]) : @creation.primary_image
end
end
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index b3986845..830ed6c9 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -7,7 +7,7 @@ class FavoritesController < ApplicationController
end
def index
- @creation = FindCreationQuery.new.fetch(params[:creation_id])
+ @creation = Creation.find(params[:creation_id])
@favorites = @creation.favorites
end
diff --git a/app/services/application/find_creation_query.rb b/app/services/application/find_creation_query.rb
deleted file mode 100644
index 21ccead1..00000000
--- a/app/services/application/find_creation_query.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class FindCreationQuery
- def initialize(repository = CreationRepository.new)
- @repository = repository
- end
-
- def fetch(id)
- @repository.find(id)
- end
-end
diff --git a/spec/controllers/creations_controller_spec.rb b/spec/controllers/creations_controller_spec.rb
index 5988ead4..e1e1b786 100644
--- a/spec/controllers/creations_controller_spec.rb
+++ b/spec/controllers/creations_controller_spec.rb
@@ -1,26 +1,32 @@
require 'rails_helper'
describe CreationsController do
- let(:user){ create(:user) }
- let(:creation){ create(:creation, :user => user) }
+ let(:user) { create(:user) }
+ let(:cake) { create(:cake, user: user) }
before(:each) do
photo = 'spec/fixtures/images/example.png'
- creation.photos.create(image: photo, image_processing: nil)
+ cake.photos.create(image: photo)
end
describe "#index" do
before { get :index }
it "should display all creations" do
- assigns(:creations).should include(creation)
+ expect(assigns(:creations)).to include(cake)
end
end
describe "#show" do
- it "assigns the requested creation" do
- get :show, :id => creation.id
- assigns(:creation).should == creation
+ it "loads the cake" do
+ get :show, id: cake.id
+ expect(assigns(:creation)).to eql(cake)
+ end
+
+ it 'loads the selected image' do
+ photo = cake.photos.first
+ get :show, id: cake.id, photo_id: photo.id
+ expect(assigns(:primary_image)).to eql(photo)
end
end
end