Commit 80c973e

mo khan <mo@mokhan.ca>
2014-11-10 03:05:59
correct json rendering and add rake task to load fake data.
1 parent d9eae73
app/views/videos/_video.json.jbuilder
@@ -1,4 +1,4 @@
-json.id @video.id
-json.title @video.title
-json.description @video.description
-json.uri @video.uri
+json.id video.id
+json.title video.title
+json.description video.description
+json.uri video.uri
app/views/videos/create.json.jbuilder
@@ -1,1 +1,3 @@
-json.partial! @video
+json.video do
+  json.partial! @video, video: @video
+end
app/views/videos/index.jbuilder
@@ -1,5 +1,5 @@
 json.videos do
   json.array! @videos do |video|
-    json.partial! video
+    json.partial! video, video: video
   end
 end
lib/tasks/populate.rake
@@ -0,0 +1,15 @@
+namespace :db do
+  task populate: :environment do
+    user = User.last
+    Video.destroy_all
+
+    20.times do
+      user.videos.create(
+        title: Faker::Name.name,
+        description: Faker::Lorem.words(50).join(' '),
+        uri: Faker::Internet.uri('https')
+      )
+    end
+
+  end
+end
spec/controllers/videos_controller_spec.rb
@@ -8,6 +8,8 @@ describe VideosController do
   end
 
   describe "#index" do
+    render_views
+
     let!(:video) { create(:video) }
 
     it 'returns all the videos' do
@@ -24,10 +26,10 @@ describe VideosController do
       xhr :post, :create, video: { title: 'hello', uri: 'http://youtu.be/jghvdDB-t30?list=PLYuXlc3r66uFJErV5rYpZRcD8oDGtQlQc' }
       expect(response).to be_success
       json = JSON.parse(response.body)
-      expect(json['id']).to_not be_nil
-      expect(json['title']).to eql('hello')
-      expect(json['description']).to be_nil
-      expect(json['uri']).to eql("http://youtu.be/jghvdDB-t30?list=PLYuXlc3r66uFJErV5rYpZRcD8oDGtQlQc")
+      expect(json['video']['id']).to_not be_nil
+      expect(json['video']['title']).to eql('hello')
+      expect(json['video']['description']).to be_nil
+      expect(json['video']['uri']).to eql("http://youtu.be/jghvdDB-t30?list=PLYuXlc3r66uFJErV5rYpZRcD8oDGtQlQc")
     end
   end
 end