OSDN Git Service

t#29677:
authoryasushiito <yas@pen-chan.jp>
Thu, 27 Sep 2012 07:48:14 +0000 (16:48 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 27 Sep 2012 07:48:14 +0000 (16:48 +0900)
app/models/panel.rb
spec/models/panel_spec.rb

index e9424b1..98437e4 100644 (file)
@@ -189,6 +189,10 @@ class Panel < ActiveRecord::Base
     self.to_json({:include => {:author => {}}, :methods => :elements})
   end
   
+  def self.list_as_json_text ary
+    '[' + ary.map {|i| i.panel_elements_as_json }.join(',') + ']'
+  end
+  
   def self.visible_count
     Panel.count
   end
index 002f9dd..af02387 100644 (file)
@@ -883,6 +883,28 @@ describe Panel do
       #t:1\r
     end\r
   end\r
+  describe 'コマリストのjson出力に於いて' do\r
+    before do\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+      Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'コマのjson出力を依頼している' do\r
+        Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)\r
+        r = Panel.list_as_json_text [@panel]\r
+      end\r
+    end\r
+    it 'json textを返している' do\r
+      r = Panel.list_as_json_text [@panel]\r
+      j = JSON.parse r\r
+      j.is_a?(Array).should be_true\r
+    end\r
+    it 'コマを含んでいる' do\r
+      r = Panel.list_as_json_text [@panel]\r
+      j = JSON.parse r\r
+      j.first.has_key?('p').should be_true\r
+    end\r
+  end\r
   describe '検証値収集に於いて' do\r
     context 'つつがなく終わるとき' do\r
       it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r