OSDN Git Service

t#29620:json output include child
[pettanr/pettanr.git] / spec / models / license_group_spec.rb
index 97cc5d2..181cb7c 100644 (file)
@@ -122,7 +122,7 @@ describe LicenseGroup do
       l.should eq [@lg, @lg2]
     end
   end
-  describe 'list関連テーブルプションに於いて' do
+  describe '一覧取得オプションに於いて' do
     it 'includeキーを含んでいる' do
       r = LicenseGroup.list_opt
       r.has_key?(:include).should be_true
@@ -137,17 +137,26 @@ describe LicenseGroup do
     end
   end
   describe 'json一覧出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = LicenseGroup.list_json_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = LicenseGroup.list_json_opt[:include]
-      r.should have(1).items
+    before do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @user = FactoryGirl.create( :user_yas)
+      @author = @user.author
+      @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
     end
     it 'ライセンスを含んでいる' do
-      r = LicenseGroup.list_json_opt[:include]
-      r.has_key?(:licenses).should be_true
+      r = LicenseGroup.list.to_json LicenseGroup.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('licenses').should be_true
     end
   end
   
@@ -174,7 +183,7 @@ describe LicenseGroup do
       end\r
     end\r
   end
-  describe 'å\8d\98ä½\93å\87ºå\8a\9bオプションに於いて' do
+  describe 'å\8d\98ä½\93å\8f\96å¾\97オプションに於いて' do
     it 'includeキーを含んでいる' do
       r = LicenseGroup.show_opt
       r.has_key?(:include).should be_true
@@ -189,17 +198,26 @@ describe LicenseGroup do
     end
   end
   describe 'json単体出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = LicenseGroup.show_json_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = LicenseGroup.show_json_opt[:include]
-      r.should have(1).items
+    before do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @user = FactoryGirl.create( :user_yas)
+      @author = @user.author
+      @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
     end
     it 'ライセンスを含んでいる' do
-      r = LicenseGroup.show_json_opt[:include]
-      r.has_key?(:licenses).should be_true
+      r = LicenseGroup.show(@lg.id).to_json LicenseGroup.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('licenses').should be_true
     end
   end