Commit 51265f23

mo khan <mo@mokhan.ca>
2014-11-21 23:50:03
add specs for the cakes controller.
1 parent fdb13b8
Changed files (3)
app
views
spec
app/views/api/v2/cakes/index.json.jbuilder
@@ -12,4 +12,5 @@ json.categories Category.all do |category|
 end
 json.meta do
   json.totalPages @cakes.total_pages
+  json.total_pages @cakes.total_pages
 end
spec/controllers/api/v2/cakes_controller_spec.rb
@@ -0,0 +1,25 @@
+require 'rails_helper'
+
+module Api
+  module V2
+    describe CakesController do
+      describe "#index" do
+        let!(:cake) { create(:published_cake) }
+
+        it 'returns all cakes in the page' do
+          xhr :get, :index
+          expect(assigns(:cakes)).to match_array([cake])
+        end
+      end
+
+      describe "#show" do
+        let!(:cake) { create(:published_cake) }
+
+        it 'loads the cake' do
+          xhr :get, :show, id: cake.id
+          expect(assigns(:cake)).to eql(cake)
+        end
+      end
+    end
+  end
+end
spec/factories.rb
@@ -3,22 +3,22 @@ FactoryGirl.define do
     user { FactoryGirl.create(:user) }
     subject { FactoryGirl.create(:creation) }
   end
+
   factory :category, class: Category do
     name { Faker::Name.name }
     slug { Faker::Name.name.gsub(/ /, "-").downcase }
   end
-  factory :creation, class: Creation do
-    name { Faker::Name.name }
-    story 'whats the story morning glory?'
-    user { FactoryGirl.create(:user) }
-    association :category
-  end
 
-  factory :cake, class: Creation do
+  factory :cake, class: Creation, aliases: [:creation] do
     name { Faker::Name.name }
     story { Faker::HipsterIpsum.words(50).join(' ') }
     association :user
     association :category
+    factory :published_cake do
+      after(:create) do |cake, evaluator|
+        cake.photos << create(:photo, image: 'spec/fixtures/images/example.png')
+      end
+    end
   end
 
   factory :user_session, class: UserSession do
@@ -34,12 +34,21 @@ FactoryGirl.define do
     user { FactoryGirl.create(:user) }
     creation { FactoryGirl.create(:creation) }
   end
+
   factory :photo, class: Photo do
-    image { 'example.png' }
+    image { 'spec/fixtures/images/example.png' }
+    content_type { "" }
+    original_filename { "" }
+    latitude { "" }
+    longitude { "" }
+    sha256 { "" }
+    watermark { "" }
   end
+
   factory :tag, :class => "ActsAsTaggableOn::Tag" do
     name { Faker::Name.name }
   end
+
   factory :tutorial do
     heading { Faker::Name.name }
     description "well hello there"
@@ -48,6 +57,7 @@ FactoryGirl.define do
     author { Faker::Name.name }
     author_url { Faker::Internet.http_url }
   end
+
   factory :user, class: User do
     name { Faker::Name.name }
     email { Faker::Internet.email }
@@ -58,6 +68,7 @@ FactoryGirl.define do
       admin true
     end
   end
+
   factory :location do
     latitude "107"
     longitude "99"