OSDN Git Service

fix test
authoryasushiito <yas@pen-chan.jp>
Thu, 3 Jul 2014 23:52:46 +0000 (08:52 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 3 Jul 2014 23:52:46 +0000 (08:52 +0900)
12 files changed:
app/controllers/application_controller.rb
app/controllers/panels_controller.rb
app/views/scrolls/show.html.erb
spec/controllers/panels_controller_spec.rb
spec/controllers/scrolls_controller_spec.rb
spec/factories/panel.rb
spec/factories/scroll.rb
spec/manifests/scroll_spec.rb [new file with mode: 0644]
spec/models/scroll_spec.rb
spec/peta/binder_spec.rb [new file with mode: 0644]
spec/support/binder_macros.rb [new file with mode: 0644]
spec/views/scrolls/show.html.erb_spec.rb

index 7c00385..f1da1ce 100644 (file)
@@ -130,7 +130,12 @@ class ApplicationController < ActionController::Base
           :filer => @filer
         }
       }
           :filer => @filer
         }
       }
-      format.json { render json: @items.to_json }
+      format.json { render json:  @items.map{|i| i.attributes}.to_json }
+      # rails3.2 has problem
+      # y method defined as private
+      # attribute y conflict at PanelPicture, balloon ..etc
+      # use i.attributes[name]
+      # format.json { render json:  @items.to_json }
       format.atom 
       format.rss
     end
       format.atom 
       format.rss
     end
@@ -172,7 +177,7 @@ class ApplicationController < ActionController::Base
   end
   
   def show_json_format_for_root format
   end
   
   def show_json_format_for_root format
-    format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
+    format.json { render json: @item.attributes.to_json(@my_model_class.show_json_opt_for_root) }
   end
   
   def set_new
   end
   
   def set_new
index a24fd71..6ea21ab 100644 (file)
@@ -4,7 +4,7 @@ class PanelsController < ApplicationController
     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
   else
     before_filter :authenticate_reader, :only => [
     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
   else
     before_filter :authenticate_reader, :only => [
-      :index, :show, :by_scroll, :by_sheet, :by_author, :by_speech_balloon_template, :count, :count_by_scroll, :count_by_sheet, :count_by_author, :count_by_speech_balloon_template
+      :index, :show, :by_scroll, :by_sheet, :by_author, :by_speech_balloon_template
     ]
     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
     ]
     before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy, :catch]
     before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy, :catch]
@@ -23,7 +23,7 @@ class PanelsController < ApplicationController
     @pager = list_result.paginate
     respond_to do |format|
       format.html 
     @pager = list_result.paginate
     respond_to do |format|
       format.html 
-      format.json { render json: @items.to_json }
+      format.json { render json: @items.map{|i| i.attributes}.to_json }
       format.atom 
       format.rss
     end
       format.atom 
       format.rss
     end
index a392264..6c58714 100644 (file)
@@ -31,7 +31,7 @@
 </div>
 
 <% if @item.own? @operators -%>
 </div>
 
 <% if @item.own? @operators -%>
-  <h3><%= t('editor') -%></h3>
+  <h3 class="edit"><%= t('editor') -%></h3>
   <p id="notice"><%= notice %></p>
   
   <p>
   <p id="notice"><%= notice %></p>
   
   <p>
index 2107730..019ca87 100644 (file)
@@ -3,138 +3,116 @@ require 'spec_helper'
 #コマ\r
 describe PanelsController do\r
   before do\r
 #コマ\r
 describe PanelsController do\r
   before do\r
-    SpeechBalloonTemplate.delete_all\r
-    @admin = FactoryGirl.create :admin\r
-    @sp = FactoryGirl.create :system_picture\r
-    @lg = FactoryGirl.create :license_group\r
-    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
-    @user = FactoryGirl.create :user_yas\r
-    @author = FactoryGirl.create :author, :user_id => @user.id\r
+    @admin =FactoryGirl.create :admin\r
+    @user_yas = FactoryGirl.create :user_yas_with_owner\r
+    @user_rom = FactoryGirl.create :user_rom\r
+    @author_yas =  @user_yas.author\r
+    \r
+    @my_model_class =  Panel   #操作モデル\r
   end\r
   \r
   end\r
   \r
-if MagicNumber['run_mode'] == 1\r
+if Manifest.manifest.magic_numbers['run_mode'] == 1\r
   describe '一覧表示に於いて' do\r
     before do\r
   describe '一覧表示に於いて' do\r
     before do\r
-      @panel = FactoryGirl.create :panel, :author_id => @author.id\r
-      Panel.stub(:list).and_return([@panel, @panel, @panel])\r
-      sign_in @user\r
+      factory_contents :panel_hello, @author_yas\r
+      @query_play = { }\r
+      @query = {:mode => 'filer'}\r
+      @query_format_json = @query_play.merge(:format => :json)\r
     end\r
     end\r
-    context '事前チェックする' do\r
-      it '与えられたpageがセットされている' do\r
-        get :index, :page => 5\r
-        assigns(:page).should eq 5\r
-      end\r
-      it '省略されると@pageに1値が入る' do\r
-        get :index\r
-        assigns(:page).should eq 1\r
-      end\r
-      it '与えられたpage_sizeがセットされている' do\r
-        get :index, :page_size => 15\r
-        assigns(:page_size).should eq 15\r
-      end\r
-      it '省略されると@page_sizeにデフォルト値が入る' do\r
-        get :index\r
-        assigns(:page_size).should eq Panel.default_page_size\r
-      end\r
-      it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
-        get :index, :page_size => 1500\r
-        assigns(:page_size).should eq Panel.max_page_size\r
-      end\r
-      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
-        get :index, :page_size => 0\r
-        assigns(:page_size).should eq Panel.default_page_size\r
-      end\r
-    end\r
-    context 'つつがなく終わるとき' do\r
-      it 'コマモデルに一覧を問い合わせている' do\r
-        Panel.should_receive(:list).exactly(1)\r
-        get :index\r
+    \r
+    context '正常系' do\r
+      before do\r
+        sign_in @user_yas\r
       end\r
       end\r
-      it '@panelsにリストを取得している' do\r
-        get :index\r
-        assigns(:panels).should have_at_least(3).items\r
+      context '共通処理' do\r
+        before do\r
+          get :index, @query\r
+        end\r
+        it 'コントローラのマニフェストから操作モデルを導出している' do\r
+          set_model? @my_model_class\r
+        end\r
+        it 'コントローラのマニフェストからリスト操作モデルを導出している' do\r
+          set_list_model? @my_model_class\r
+        end\r
+        it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do\r
+          set_list? 'panel', 'public'\r
+        end\r
+        it '@itemsにリストを取得している' do\r
+          expect(assigns(:items).size).to be >= 3\r
+        end\r
       end\r
       context 'html形式' do\r
       end\r
       context 'html形式' do\r
-        it '@paginateにページ制御を取得している' do\r
-          get :index\r
-          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true\r
+        before do\r
+          get :index, @query\r
         end\r
         end\r
-        it 'ステータスコード200 OKを返す' do\r
-          get :index\r
-          response.should be_success \r
+        it 'ステータス OKを返して、ファイラーを描画している' do\r
+          return_ok?\r
+          render_filer?\r
         end\r
         end\r
-        it 'indexテンプレートを描画する' do\r
-          get :index\r
-          response.should render_template("index")\r
+        it '@filerにファイラーを取得している' do\r
+          let_filer?\r
         end\r
       end\r
       context 'json形式' do\r
         end\r
       end\r
       context 'json形式' do\r
-        it 'ステータスコード200 OKを返す' do\r
-          get :index, :format => :json\r
-          response.should be_success \r
-        end\r
-        it 'jsonデータを返す' do\r
-          get :index, :format => :json\r
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        before do\r
+          get :index, @query_format_json\r
         end\r
         end\r
-        it 'コマモデルにコマリストのjson出力を問い合わせている' do\r
-          Panel.should_receive(:list_as_json_text).exactly(1)\r
-          get :index, :format => :json\r
+        it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do\r
+          set_list? 'panel', 'public'\r
         end\r
         end\r
-        it 'データがリスト構造になっている' do\r
-          get :index, :format => :json\r
-          json = JSON.parse response.body\r
-          json.should have_at_least(3).items\r
+        it 'ステータス OKを返して、jsonデータを返している' do\r
+          return_ok?\r
+          render_json?\r
         end\r
         end\r
-        it 'リストの先頭くらいはコマっぽいものであって欲しい' do\r
-          get :index, :format => :json\r
-          json = JSON.parse response.body\r
-          json.first.has_key?("border").should be_true\r
+        it '@filerにファイラーをセットしていない' do\r
+          expect(assigns(:filer)).to be nil\r
         end\r
       end\r
     end\r
         end\r
       end\r
     end\r
-    context 'ユーザ権限がないとき' do\r
-      before do\r
-        sign_out @user\r
-      end\r
+    context '件数取得' do\r
       context 'html形式' do\r
       context 'html形式' do\r
-        it 'ステータスコード302 Foundを返す' do\r
-          get :index\r
-          response.status.should eq 302\r
-        end\r
-        it 'サインインページへ遷移する' do\r
-          get :index\r
-          response.should redirect_to '/users/sign_in'\r
+        it '必要ないので実装していない' do\r
+          sign_in @user_yas\r
+          get :count, @query\r
+          expect(response.status).to eq(406)\r
         end\r
       end\r
       context 'json形式' do\r
         end\r
       end\r
       context 'json形式' do\r
-        it 'ステータスコード401 Unauthorizedを返す' do\r
-          get :index, :format => :json\r
-          response.status.should eq 401\r
+        it 'ステータス OKを返して、jsonデータを返している' do\r
+          sign_in @user_yas\r
+          get :count, @query_format_json\r
+          return_ok?\r
+          render_json?\r
         end\r
         end\r
-        it '応答メッセージにUnauthorizedを返す' do\r
-          get :index, :format => :json\r
-          response.message.should match(/Unauthorized/)\r
+      end\r
+      context 'ゲスト(サインインしていない)' do\r
+        it '通常通り応答する' do\r
+          get :count, @query_format_json\r
+          return_ok?\r
+          render_json?\r
         end\r
       end\r
     end\r
         end\r
       end\r
     end\r
-    context 'ユーザ権限はないが管理者権限があるとき' do\r
-      before do\r
-        sign_out @user\r
+    context 'サインインの状態が例外的なとき' do\r
+      it 'ユーザではなく管理者でも通常通り応答している' do\r
         sign_in @admin\r
         sign_in @admin\r
-      end\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :index\r
-        response.should be_success \r
-      end\r
-    end\r
-    context 'ユーザだが作家登録していないとき' do\r
-      before do\r
-        @author.destroy\r
-      end\r
-      it 'ステータスコード200 OKを返す' do\r
-        get :index\r
-        response.should be_success \r
+        get :index, @query\r
+        return_ok?\r
+        get :index, @query_format_json\r
+        render_json?\r
+      end\r
+      it '創作活動してないROM専の読者にも通常通り応答している' do\r
+        sign_in @user_rom\r
+        get :index, @query\r
+        return_ok?\r
+        get :index, @query_format_json\r
+        render_json?\r
+      end\r
+      it 'ゲスト(サインインしていない)はサインインページに遷移している' do\r
+        get :index, @query\r
+        redirect? sign_in_url\r
+        get :index, @query_format_json\r
+        render_unauthorized?\r
       end\r
     end\r
   end\r
       end\r
     end\r
   end\r
index 487548d..e828f7d 100644 (file)
@@ -209,6 +209,103 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
     end
   end
   
     end
   end
   
+  describe 'コマフィルタ一覧及びカウント' do
+    before do
+      @panel = FactoryGirl.create :panel_hello_with_scroll_panels, author_id: @author_yas.id
+      @query = {:id => @panel.id}
+      @query_format_json = @query.merge(:format => :json)
+    end
+    
+    context '正常系' do
+      before do
+        sign_in @user_yas
+      end
+      context '共通処理' do
+        before do
+          get :by_panel, @query
+        end
+        it 'コントローラのマニフェストから操作モデルを導出している' do
+          set_model? @my_model_class
+        end
+        it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+          set_list? 'scroll', 'by_panel'
+        end
+        it '@itemsにリストを取得している' do
+          expect(assigns(:items).size).to be >= 3
+        end
+      end
+      context 'html形式' do
+        before do
+          get :by_panel, @query
+        end
+        it 'ステータス OKを返して、ファイラーを描画している' do
+          return_ok?
+          render_filer?
+        end
+        it '@filerにファイラーを取得している' do
+          let_filer?
+        end
+      end
+      context 'json形式' do
+        before do
+          get :by_panel, @query_format_json
+        end
+        it 'ステータス OKを返して、jsonデータを返している' do
+          return_ok?
+          render_json?
+        end
+        it '@filerにファイラーをセットしていない' do
+          expect(assigns(:filer)).to be nil
+        end
+      end
+    end
+    context '件数取得' do
+      context 'html形式' do
+        it '必要ないので実装していない' do
+          sign_in @user_yas
+          get :count_by_panel, @query
+          expect(response.status).to eq(406)
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          sign_in @user_yas
+          get :count_by_panel, @query_format_json
+          return_ok?
+          render_json?
+        end
+      end
+      context 'ゲスト(サインインしていない)' do
+        it '通常通り応答している' do
+          get :count_by_panel, @query_format_json
+          return_ok?
+          render_json?
+        end
+      end
+    end
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答している' do
+        sign_in @admin
+        get :by_panel, @query
+        return_ok?
+        get :by_panel, @query_format_json
+        render_json?
+      end
+      it '創作活動してないROM専の読者にも通常通り応答している' do
+        sign_in @user_rom
+        return_ok?
+        get :by_panel, @query_format_json
+        render_json?
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+        get :by_panel, @query
+        redirect? sign_in_url
+        get :by_panel, @query_format_json
+        render_unauthorized?
+      end
+    end
+  end
+  
   describe '単体表示に於いて' do
     before do
       @item =  FactoryGirl.create :scroll_hello, author: @author_yas
   describe '単体表示に於いて' do
     before do
       @item =  FactoryGirl.create :scroll_hello, author: @author_yas
index 7d2538c..39d1f10 100644 (file)
@@ -14,6 +14,15 @@ FactoryGirl.define do
     i.border 2\r
     i.caption 'hello'\r
     i.publish 1\r
     i.border 2\r
     i.caption 'hello'\r
     i.publish 1\r
+    trait :with_scroll_panels do\r
+      after(:create) do |panel, evaluator|\r
+        create(:scroll_panel_plain, t: 0, scroll: create(:scroll_hello, author: panel.author), panel: panel)\r
+        create(:scroll_panel_plain, t: 1, scroll: create(:scroll_itojun, author: panel.author), panel: panel)\r
+        create(:scroll_panel_plain, t: 2, scroll: create(:scroll_great, author: panel.author), panel: panel)\r
+        create(:scroll_panel_plain, t: 3, scroll: create(:scroll_diary, author: panel.author), panel: panel)\r
+      end\r
+    end\r
+    factory :panel_hello_with_scroll_panels, traits: [:with_scroll_panels]\r
   end\r
   factory :panel_my_name, :class => Panel do |i|\r
     i.width 514\r
   end\r
   factory :panel_my_name, :class => Panel do |i|\r
     i.width 514\r
index ba106f2..0efb1c2 100644 (file)
@@ -7,14 +7,10 @@ FactoryGirl.define do
     #association :author, factory: :author_yas\r
     trait :with_scroll_panels do\r
       after(:create) do |scroll, evaluator|\r
     #association :author, factory: :author_yas\r
     trait :with_scroll_panels do\r
       after(:create) do |scroll, evaluator|\r
-        #panel_hello = create(:panel_hello, author: scroll.author)\r
         create(:scroll_panel_plain, t: 0, scroll: scroll, panel: create(:panel_hello, author: scroll.author))\r
         create(:scroll_panel_plain, t: 0, scroll: scroll, panel: create(:panel_hello, author: scroll.author))\r
-        panel_my_name = create(:panel_hello, author: scroll.author)\r
-        create(:scroll_panel_plain, t: 1, scroll: scroll, panel: panel_my_name)\r
-        panel_penjiro = create(:panel_hello, author: scroll.author)\r
-        create(:scroll_panel_plain, t: 2, scroll: scroll, panel: panel_penjiro)\r
-        panel_enjoy = create(:panel_hello, author: scroll.author)\r
-        create(:scroll_panel_plain, t: 3, scroll: scroll, panel: panel_enjoy)\r
+        create(:scroll_panel_plain, t: 1, scroll: scroll, panel: create(:panel_my_name, author: scroll.author))\r
+        create(:scroll_panel_plain, t: 2, scroll: scroll, panel: create(:panel_penjiro, author: scroll.author))\r
+        create(:scroll_panel_plain, t: 3, scroll: scroll, panel: create(:panel_enjoy, author: scroll.author))\r
       end\r
     end\r
     factory :scroll_hello_with_scroll_panels, traits: [:with_scroll_panels]\r
       end\r
     end\r
     factory :scroll_hello_with_scroll_panels, traits: [:with_scroll_panels]\r
@@ -24,23 +20,20 @@ FactoryGirl.define do
     i.description '非公開の状態で作成したり、公開スクロールを非公開に変えるときに使う。'\r
     i.visible 0\r
   end\r
     i.description '非公開の状態で作成したり、公開スクロールを非公開に変えるときに使う。'\r
     i.visible 0\r
   end\r
-  factory :scroll003, :class => Scroll do |i|\r
+  factory :scroll_itojun, :class => Scroll do |i|\r
     i.title 'aaaaaaaa'\r
     i.description ''\r
     i.visible 1\r
     i.title 'aaaaaaaa'\r
     i.description ''\r
     i.visible 1\r
-    i.author_id 1\r
   end\r
   end\r
-  factory :scroll004, :class => Scroll do |i|\r
+  factory :scroll_great, :class => Scroll do |i|\r
     i.title 'aaaaaaaa'\r
     i.description ''\r
     i.visible 1\r
     i.title 'aaaaaaaa'\r
     i.description ''\r
     i.visible 1\r
-    i.author_id 1\r
   end\r
   end\r
-  factory :scroll005, :class => Scroll do |i|\r
+  factory :scroll_diary, :class => Scroll do |i|\r
     i.title '投稿した直後'\r
     i.description ''\r
     i.visible 1\r
     i.title '投稿した直後'\r
     i.description ''\r
     i.visible 1\r
-    i.author_id 4\r
   end\r
   factory :scroll006, :class => Scroll do |i|\r
     i.title '投稿した直後'\r
   end\r
   factory :scroll006, :class => Scroll do |i|\r
     i.title '投稿した直後'\r
diff --git a/spec/manifests/scroll_spec.rb b/spec/manifests/scroll_spec.rb
new file mode 100644 (file)
index 0000000..1e18386
--- /dev/null
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#スクロールマニフェスト
+
+describe Scroll do
+  before do
+  end
+  
+  describe 'ペタナイズに於いて' do
+    context 'オーソドックスなデータのとき' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    end
+    
+  end
+  
+  describe 'コントローラに於いて' do
+    describe 'actionに於いて' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    end
+    
+  end
+  
+  describe 'モデルに於いて' do
+    context 'オーソドックスなデータのとき' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    end
+    
+  end
+  
+end
index 9128dc7..73220ed 100644 (file)
@@ -3,6 +3,8 @@ require 'spec_helper'
 #スクロール
 
 describe Scroll do
 #スクロール
 
 describe Scroll do
+  include BinderMacros
+  
   before do
     SpeechBalloonTemplate.delete_all
     @admin = FactoryGirl.create :admin
   before do
     SpeechBalloonTemplate.delete_all
     @admin = FactoryGirl.create :admin
@@ -18,6 +20,48 @@ describe Scroll do
     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
   end
   
     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
   end
   
+  describe 'ペタナイズに於いて' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    context 'バインダー' do
+      it '' do
+        define_leaf_items?
+      end
+      it '' do
+        define_leafs_items?
+      end
+    end
+    
+  end
+  
+  describe 'マニフェストに於いて' do
+    context 'オーソドックスなデータのとき' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    end
+    
+  end
+  
+  describe 'ローカルマニフェストに於いて' do
+    context 'ファイラーのとき' do
+      it 'スクコマを閉じるためのバインダーである' do
+        expect(@item.is_a?(Peta::Binder)).to be true
+      end
+      it 'ブースト特筆すべき注意事項はない' do
+        expect(self.class.my_peta.boost.keys).to be true
+      end
+    end
+    
+  end
+  
   describe '検証に於いて' do
     before do
       @scroll = FactoryGirl.build :scroll, :author_id => @author.id
   describe '検証に於いて' do
     before do
       @scroll = FactoryGirl.build :scroll, :author_id => @author.id
diff --git a/spec/peta/binder_spec.rb b/spec/peta/binder_spec.rb
new file mode 100644 (file)
index 0000000..512416e
--- /dev/null
@@ -0,0 +1,797 @@
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#スクロール
+
+describe Scroll do
+  before do
+    SpeechBalloonTemplate.delete_all
+    @admin = FactoryGirl.create :admin
+    @demand_user = FactoryGirl.create :demand_user
+    @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 = FactoryGirl.create :author, :user_id => @user.id
+    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+    @other_user = FactoryGirl.create( :user_yas)
+    @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+    @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+  end
+  
+  describe '文字コード検証に於いて' do
+    before do
+      @scroll = FactoryGirl.build :scroll, :author_id => @author.id
+    end
+    
+    context 'titleを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @scroll.title = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @scroll.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+    
+    context 'descriptionを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @scroll.description = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @scroll.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+  end
+  
+  describe 'デフォルト値補充に於いて' do
+    it 'visibleが0になっている' do
+      @scroll = FactoryGirl.build :scroll, :visible => nil
+      @scroll.supply_default
+      @scroll.visible.should eq 0
+    end
+  end
+  
+  describe '上書き補充に於いて' do
+    it '作家idが設定されている' do
+      @scroll = FactoryGirl.build :scroll, :author_id => nil
+      @scroll.overwrite @author
+      @scroll.author_id.should eq @author.id
+    end
+  end
+  
+  describe 'ロールリストからの作家取得に於いて' do
+    context 'ロールがユーザのとき' do
+      it 'ユーザから作家を取得して、それを返す' do
+        r = Scroll.get_author_from_roles([@user])
+        r.should eq @author
+      end
+    end
+    context 'ロールが作家のとき' do
+      it '作家を返す' do
+        r = Scroll.get_author_from_roles([@author])
+        r.should eq @author
+      end
+    end
+    context 'ロールが絵師のとき' do
+      it '絵師から作家を取得できれば、それをを返す' do
+        r = Scroll.get_author_from_roles([@artist])
+        r.should eq @author
+      end
+      it '絵師から作家を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Scroll.get_author_from_roles([@artist])
+        r.should be_nil
+      end
+    end
+    context 'ロールが管理者のとき' do
+      it 'nilを返す' do
+        r = Scroll.get_author_from_roles([@admin])
+        r.should be_nil
+      end
+    end
+  end
+  
+  describe 'ロールリストからの絵師取得に於いて' do
+    context 'ロールがユーザのとき' do
+      it 'ユーザから作家を取得して、そこから絵師を取得できれば、それを返す' do
+        r = Scroll.get_artist_from_roles([@user])
+        r.should eq @artist
+      end
+      it '作家から絵師を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Scroll.get_artist_from_roles([@user])
+        r.should be_nil
+      end
+    end
+    context 'ロールが作家のとき' do
+      it 'そこから絵師を取得できれば、それを返す' do
+        r = Scroll.get_artist_from_roles([@author])
+        r.should eq @artist
+      end
+      it '作家から絵師を取得できないときnilを返す' do
+        @artist.author_id = nil
+        @artist.save!
+        r = Scroll.get_artist_from_roles([@author])
+        r.should be_nil
+      end
+    end
+    context 'ロールが絵師のとき' do
+      it 'それを返す' do
+        r = Scroll.get_artist_from_roles([@artist])
+        r.should eq @artist
+      end
+    end
+    context 'ロールが管理者のとき' do
+      it 'nilを返す' do
+        r = Scroll.get_artist_from_roles([@admin])
+        r.should be_nil
+      end
+    end
+  end
+  
+  describe '所持判定に於いて' do
+    before do
+      @scroll = FactoryGirl.build :scroll, :author_id => @author.id
+    end
+    context '事前チェックする' do
+      it '自身にロールリストからの作家取得を依頼している' do
+        Scroll.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+        r = @scroll.own?([@author])
+      end
+    end
+    context 'ロール内作家が取得できるとき' do
+      before do
+      end
+      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+        Scroll.stub(:get_author_from_roles).with(any_args).and_return(@author)
+        r = @scroll.own?([@author])
+        r.should be_true
+      end
+      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+        Scroll.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+        @scroll.own?(@other_author).should be_false
+      end
+    end
+    context 'ロール内作家が取得できないとき' do
+      before do
+        Scroll.stub(:get_author_from_roles).with(any_args).and_return(nil)
+      end
+      it 'Falseを返す' do
+        r = @scroll.own?([@author])
+        r.should be_false
+      end
+    end
+  end
+  
+  describe '読者用ロールチェックに於いて' do
+    before do
+      @scroll = FactoryGirl.build :scroll, :author_id => @author.id
+    end
+    context 'ロールリストに作家が含まれるとき' do
+      it 'ロールリストがリストではないとき、リストにする trueを返す' do
+        r = @scroll.reader_role_check(@author)
+        r.should be_true
+      end
+      it 'trueを返す' do
+        r = @scroll.reader_role_check([@author])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに絵師が含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.reader_role_check([@artist])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザが含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.reader_role_check([@user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに管理者が含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.reader_role_check([@admin])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザ、管理者、作家、絵師が含まれないとき' do
+      it 'falseを返す' do
+        r = @scroll.reader_role_check([nil])
+        r.should be_false
+      end
+    end
+  end
+  
+  describe '素材読者用ロールチェックに於いて' do
+    before do
+      @scroll = FactoryGirl.build :scroll, :author_id => @author.id
+    end
+    context 'ロールリストに作家が含まれるとき' do
+      it 'ロールリストがリストではないとき、リストにする trueを返す' do
+        r = @scroll.resource_reader_role_check(@author)
+        r.should be_true
+      end
+      it 'trueを返す' do
+        r = @scroll.resource_reader_role_check([@author])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに絵師が含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.resource_reader_role_check([@artist])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザが含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.resource_reader_role_check([@user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに管理者が含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.resource_reader_role_check([@admin])
+        r.should be_true
+      end
+    end
+    context 'ロールリストに借手が含まれるとき' do
+      it 'trueを返す' do
+        r = @scroll.resource_reader_role_check([@demand_user])
+        r.should be_true
+      end
+    end
+    context 'ロールリストにユーザ、管理者、作家、絵師、借手が含まれないとき' do
+      it 'falseを返す' do
+        r = @scroll.resource_reader_role_check([nil])
+        r.should be_false
+      end
+    end
+  end
+  
+  describe '閲覧許可に於いて' do
+    before do
+      @scroll = FactoryGirl.build :scroll, :author_id => @author.id
+    end
+    context 'オープンモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 0
+      end
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        Scroll.any_instance.stub(:guest_role_check).and_return(true)
+        Scroll.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @scroll.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        Scroll.any_instance.stub(:guest_role_check).and_return(false)
+        r = @scroll.visible?([@author])
+        r.should be_false
+      end
+    end
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        Scroll.any_instance.stub(:reader_role_check).and_return(true)
+        Scroll.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @scroll.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        Scroll.any_instance.stub(:reader_role_check).and_return(false)
+        r = @scroll.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Scroll.any_instance.stub(:reader_role_check).and_return(true)
+        Scroll.any_instance.stub(:own?).and_return(true)
+      end
+      it '自身に所持判定を問い合わせしている' do
+        Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @scroll.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Scroll.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のスクロールなら許可する' do
+        Scroll.any_instance.stub(:own?).and_return(true)
+        Scroll.any_instance.stub(:visible).and_return(0)
+        r = @scroll.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開スクロールなら許可しない' do
+        Scroll.any_instance.stub(:own?).and_return(false)
+        Scroll.any_instance.stub(:visible).and_return(0)
+        r = @scroll.visible?([@author])
+        r.should be_false
+      end
+      it '他人のスクロールでも公開なら許可する' do
+        Scroll.any_instance.stub(:own?).and_return(false)
+        Scroll.any_instance.stub(:visible).and_return(1)
+        r = @scroll.visible?([@author])
+        r.should be_true
+      end
+    end
+  end
+  
+  describe '一覧取得に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+    end
+    context 'page補正について' do
+      it '文字列から数値に変換される' do
+        Scroll.page('8').should eq 8
+      end
+      it 'nilの場合は1になる' do
+        Scroll.page().should eq 1
+      end
+      it '0以下の場合は1になる' do
+        Scroll.page('0').should eq 1
+      end
+    end
+    context 'page_size補正について' do
+      it '文字列から数値に変換される' do
+        Scroll.page_size('7').should eq 7
+      end
+      it 'nilの場合はScroll.default_page_sizeになる' do
+        Scroll.page_size().should eq Scroll.default_page_size
+      end
+      it '0以下の場合はScroll.default_page_sizeになる' do
+        Scroll.page_size('0').should eq Scroll.default_page_size
+      end
+      it 'Scroll.max_page_sizeを超えた場合はScroll.max_page_sizeになる' do
+        Scroll.page_size('1000').should eq Scroll.max_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        Scroll.stub(:list_opt).with(any_args).and_return({})
+        Scroll.should_receive(:list_opt).with(any_args).exactly(1)
+        r = Scroll.list
+      end
+    end
+    it 'リストを返す' do
+      c = Scroll.list
+      c.should eq [@scroll]
+    end
+    it '非公開スクロールは(自分のスクロールであっても)含んでいない' do
+      FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0
+      c = Scroll.list
+      c.should eq [@scroll]
+    end
+    it '時系列で並んでいる' do
+      #公開スクロールは(他人のスクロールであっても)含んでいる
+      v = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
+      c = Scroll.list
+      c.should eq [v, @scroll]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
+        @scroll3 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 200
+        @scroll4 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 300
+        @scroll5 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 400
+        Scroll.stub(:default_page_size).and_return(2)
+      end
+      it '通常は2件を返す' do
+        c = Scroll.list
+        c.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        c = Scroll.list(1)
+        c.should eq [@scroll5, @scroll4]
+      end
+      it 'page=2なら中間2件を返す' do
+        c = Scroll.list(2)
+        c.should eq [@scroll3, @scroll2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        c = Scroll.list(3)
+        c.should eq [@scroll]
+      end
+    end
+  end
+  
+  describe '自分のスクロール一覧取得に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        Scroll.stub(:list_opt).with(any_args).and_return({})
+        Scroll.should_receive(:list_opt).with(any_args).exactly(1)
+        r = Scroll.mylist @author
+      end
+    end
+    it 'リストを返す' do
+      c = Scroll.mylist @author
+      c.should eq [@scroll]
+    end
+    it '時系列で並んでいる' do
+      nc = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
+      cl = Scroll.mylist @author
+      cl.should eq [nc, @scroll]
+    end
+    it '他人のスクロールは公開でも含まない' do
+      nc = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
+      cl = Scroll.mylist @author
+      cl.should eq [@scroll]
+    end
+    it '自分のスクロールは非公開でも含んでいる' do
+      nc = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
+      cl = Scroll.mylist @author
+      cl.should eq [nc, @scroll]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 100
+        @scroll3 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 200
+        @scroll4 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 300
+        @scroll5 = FactoryGirl.create :scroll, :author_id => @author.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        c = Scroll.mylist @author, 1, 2
+        c.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        c = Scroll.mylist(@author, 1, 2)
+        c.should eq [@scroll5, @scroll4]
+      end
+      it 'page=2なら中間2件を返す' do
+        c = Scroll.mylist(@author, 2, 2)
+        c.should eq [@scroll3, @scroll2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        c = Scroll.mylist(@author, 3, 2)
+        c.should eq [@scroll]
+      end
+    end
+  end
+  
+  describe '他作家のスクロール一覧取得に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        Scroll.stub(:list_opt).with(any_args).and_return({})
+        Scroll.should_receive(:list_opt).with(any_args).exactly(1)
+        r = Scroll.himlist @other_author
+      end
+    end
+    it '指定した作家のリストを返す' do
+      r = Scroll.himlist @other_author
+      r.should eq [@other_scroll]
+    end
+    it '時系列で並んでいる' do
+      nc = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
+      r = Scroll.himlist @other_author
+      r.should eq [nc, @other_scroll]
+    end
+    it '公開スクロールに限る ' do
+      hidden = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 0
+      r = Scroll.himlist @other_author
+      r.should eq [@other_scroll]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @other_scroll2 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 100
+        @other_scroll3 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 200
+        @other_scroll4 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 300
+        @other_scroll5 = FactoryGirl.create :scroll, :author_id => @other_author.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        c = Scroll.himlist @other_author, 1, 2
+        c.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        c = Scroll.himlist(@other_author, 1, 2)
+        c.should eq [@other_scroll5, @other_scroll4]
+      end
+      it 'page=2なら中間2件を返す' do
+        c = Scroll.himlist(@other_author, 2, 2)
+        c.should eq [@other_scroll3, @other_scroll2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        c = Scroll.himlist(@other_author, 3, 2)
+        c.should eq [@other_scroll]
+      end
+    end
+  end
+  
+  describe 'スクロール一覧ページ制御に於いて' do
+    before do
+      Scroll.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Scroll.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'スクロール一覧の取得条件を利用している' do
+      Scroll.stub(:list_where).with(any_args).and_return('')
+      Scroll.should_receive(:list_where).with(any_args).exactly(1)
+      r = Scroll.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Scroll.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '自分のスクロール一覧ページ制御に於いて' do
+    before do
+      Scroll.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Scroll.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分のスクロール一覧の取得条件を利用している' do
+      Scroll.stub(:mylist_where).with(any_args).and_return('')
+      Scroll.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = Scroll.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Scroll.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家のスクロール一覧ページ制御に於いて' do
+    before do
+      Scroll.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = Scroll.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家のスクロール一覧の取得条件を利用している' do
+      Scroll.stub(:himlist_where).with(any_args).and_return('')
+      Scroll.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = Scroll.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = Scroll.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
+    it '2つの項目を含んでいる' do
+      r = Scroll.list_opt
+      r.should have(2).items
+    end
+    it 'スクコマを含んでいる' do
+      r = Scroll.list_opt
+      r.has_key?(:scroll_panels).should be_true
+    end
+      it 'スクコマはコマを含んでいる' do
+        r = Scroll.list_opt
+        r[:scroll_panels].has_key?(:panel).should be_true
+      end
+    it '作家を含んでいる' do
+      r = Scroll.list_opt
+      r.has_key?(:author).should be_true
+    end
+  end
+  describe 'json一覧出力オプションに於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+      @sbt = FactoryGirl.create :speech_balloon_template
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
+    end
+    it 'スクコマを含んでいる' do
+      r = Scroll.list.to_json Scroll.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('scroll_panels').should be_true
+    end
+      it 'スクコマはコマを含んでいる' do
+        r = Scroll.list.to_json Scroll.list_json_opt
+        j = JSON.parse r
+        i = j.first
+        s = i['scroll_panels'].first
+        s.has_key?('panel').should be_true
+      end
+    it '作家を含んでいる' do
+      r = Scroll.list.to_json Scroll.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('author').should be_true
+    end
+  end
+  
+  describe '単体取得に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+    end
+    context 'つつがなく終わるとき' do
+      it '単体取得オプションを利用している' do
+        Scroll.stub(:show_opt).with(any_args).and_return({})
+        Scroll.should_receive(:show_opt).with(any_args).exactly(1)
+        r = Scroll.show @scroll.id, @author
+      end
+      it '閲覧許可を問い合わせている' do
+        Scroll.any_instance.stub(:visible?).with(any_args).and_return(true)
+        Scroll.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = Scroll.show @scroll.id, @author
+      end
+    end
+    it '指定のスクロールを返す' do
+      c = Scroll.show @scroll.id, @author
+      c.should eq @scroll
+    end
+    context '閲覧許可が出なかったとき' do
+      it '403Forbidden例外を返す' do
+        Scroll.any_instance.stub(:visible?).and_return(false)
+        lambda{
+          Scroll.show @scroll.id, @author
+        }.should raise_error(ActiveRecord::Forbidden)
+      end
+    end
+    context '存在しないスクロールを開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          Scroll.show 110, @author
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
+  end
+  
+  describe '編集取得に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+    end
+    context 'つつがなく終わるとき' do
+      it '単体取得オプションを利用している' do
+        Scroll.stub(:show_opt).with(any_args).and_return({})
+        Scroll.should_receive(:show_opt).with(any_args).exactly(1)
+        r = Scroll.edit @scroll.id, @author
+      end
+      it '所持判定を問い合わせている' do
+        Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
+        Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = Scroll.edit @scroll.id, @author
+      end
+    end
+    it '指定のスクロールを返す' do
+      Scroll.any_instance.stub(:own?).and_return(true)
+      c = Scroll.edit @scroll.id, @author.id
+      c.should eq @scroll
+    end
+    context '他人のスクロールを開こうとしたとき' do
+      it '403Forbidden例外を返す' do
+        Scroll.any_instance.stub(:own?).and_return(false)
+        lambda{
+          Scroll.edit @scroll.id, @author
+        }.should raise_error(ActiveRecord::Forbidden)
+      end
+    end
+    context '存在しないスクロールを開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          Scroll.edit 110, @author
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
+  end
+  describe '単体取得オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = Scroll.show_opt
+      r.has_key?(:include).should be_true
+    end
+    it '2つの項目を含んでいる' do
+      r = Scroll.show_opt[:include]
+      r.should have(2).items
+    end
+    it '作家を含んでいる' do
+      r = Scroll.show_opt[:include]
+      r.has_key?(:author).should be_true
+    end
+    it 'スクコマを含んでいる' do
+      r = Scroll.show_opt[:include]
+      r.has_key?(:scroll_panels).should be_true
+    end
+      it 'スクコマはコマを含んでいる' do
+        r = Scroll.show_opt[:include]
+        r[:scroll_panels].has_key?(:panel).should be_true
+      end
+  end
+  describe 'json単体出力オプションに於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+      @sbt = FactoryGirl.create :speech_balloon_template
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
+    end
+    it 'スクコマを含んでいる' do
+      r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('scroll_panels').should be_true
+    end
+      it 'スクコマはコマを含んでいる' do
+        r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
+        j = JSON.parse r
+        i = j
+        s = i['scroll_panels'].first
+        s.has_key?('panel').should be_true
+      end
+    it '作家を含んでいる' do
+      r = Scroll.show(@scroll.id, @author).to_json Scroll.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('author').should be_true
+    end
+  end
+  
+  describe '削除に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
+      @other_scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @other_scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @other_scroll.id, :panel_id => @panel.id
+    end
+    context 'つつがなく終わるとき' do
+      it '自身を削除する' do
+        lambda {
+          r = @scroll.destroy_with_scroll_panel
+        }.should change(Scroll, :count).by(-1)
+        lambda {
+          r = Scroll.find @scroll.id
+        }.should raise_error
+      end
+      it '自身にリンクしているスクコマをすべて削除する' do
+        lambda {
+          r = @scroll.destroy_with_scroll_panel
+        }.should change(ScrollPanel, :count).by(-1)
+        lambda {
+          r = ScrollPanel.find @scroll_panel.id
+        }.should raise_error
+      end
+      it 'Trueを返す' do
+        r = @scroll.destroy_with_scroll_panel
+        r.should be_true
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        ScrollPanel.any_instance.stub(:destroy).with(any_args).and_return(false)
+      end
+      it 'Falseを返す' do
+        r = @scroll.destroy_with_scroll_panel
+        r.should be_false
+      end
+      it 'ロールバックしている' do
+        lambda {
+          r = @scroll.destroy_with_scroll_panel
+        }.should_not change(Scroll, :count)
+        lambda {
+          r = @scroll.destroy_with_scroll_panel
+        }.should_not change(ScrollPanel, :count)
+      end
+    end
+  end
+end
diff --git a/spec/support/binder_macros.rb b/spec/support/binder_macros.rb
new file mode 100644 (file)
index 0000000..afa1290
--- /dev/null
@@ -0,0 +1,127 @@
+module BinderMacros\r
+  def define_leaf_items?\r
+    # ステータス OKを返す\r
+    expect(response).to be_success\r
+  end\r
+  \r
+  def render_json?\r
+    # jsonデータを返す\r
+    expect {JSON.parse(response.body)}.not_to raise_error\r
+  end\r
+  \r
+  def render_filer?\r
+    # filerテンプレートを描画する\r
+    expect(response).to render_template("templates/r/filer/filer")\r
+  end\r
+  \r
+  def render_profiler?\r
+    # profilerテンプレートを描画する\r
+    expect(response).to render_template("templates/r/profiler/profiler")\r
+  end\r
+  \r
+  def render_form?\r
+    # formテンプレートを描画する\r
+    expect(response).to render_template("templates/r/form/form")\r
+  end\r
+  \r
+  def redirect? url\r
+    # html形式: ステータスコード302 Foundを返す\r
+    expect(response.status).to eq(302)\r
+    expect(response).to redirect_to url\r
+  end\r
+  \r
+  # ゲストがapiからコンテンツにアクセスしようとした時の動作を確認する\r
+  def render_unauthorized?\r
+    # json形式: ステータスコード401 Unauthorizedを返す\r
+    expect(response.status).to eq(401)\r
+    expect(response.message).to match(/Unauthorized/)\r
+  end\r
+  \r
+  # 処理不能を返す\r
+  def render_unprocessable?\r
+    expect(response.status).to eq(422)\r
+    expect(response.message).to match(/Unprocessable/)\r
+  end\r
+  \r
+  def render_complated?\r
+    expect(response.message).to match /./\r
+  end\r
+  \r
+  def set_model? model_class, var_name = :my_model_class\r
+    expect(assigns(var_name)).to be model_class\r
+  end\r
+  \r
+  def set_list_model? model_class, var_name = :my_list_model_class\r
+    expect(assigns(var_name)).to be model_class\r
+  end\r
+  \r
+  def set_list? item_name, list_name, var_name = :list\r
+    expect(assigns(var_name).item_name).to eq(item_name)\r
+    expect(assigns(var_name).list_name).to eq(list_name)\r
+  end\r
+  \r
+  def set_play_list? model_class\r
+    expect(assigns(:items).size).to be >= 3\r
+    expect(assigns(:count)).to be >= 3\r
+    expect(assigns(:pager)).not_to be nil\r
+    expect(assigns(:items).first.class).to be model_class\r
+  end\r
+  \r
+  def let_filer? var_name = :filer\r
+    expect(assigns(var_name).class).to eq(Locmare::Filer)\r
+  end\r
+  \r
+  def let_profiler? var_name = :profiler\r
+    expect(assigns(var_name).class).to eq(Locmare::Profiler)\r
+  end\r
+  \r
+  def set_bucket? item, var_name = :form\r
+    # @filerにファイラーを取得している\r
+    expect(assigns(var_name).item).to eq(item)\r
+    expect(assigns(var_name).mounted).to eq(true)\r
+    expect(assigns(var_name).submit).to eq(true)\r
+  end\r
+  \r
+  def boost? names, var_name = :item\r
+    if names.empty?\r
+      assigns(var_name).boosters.empty?\r
+    else\r
+      names.each do |boost_name|\r
+        expect(assigns(var_name).boosters[boost_name]).to_not be nil\r
+      end\r
+    end\r
+  end\r
+  \r
+  # 作家活動していないユーザーがAPIから創作活動をしようとしたとき、例外を発生させる。\r
+  # 暫定的な仕様なので、良い方法があれば変えるかもしれない。メンテしやすいように切り分けてある。\r
+  # リクエストして例外が発生したところとらえるので、リクエストと検証を同時に行う\r
+  def announce_regist_author_for_json method, params = {}, action = :create\r
+    expect {__send__(method, action, params.merge(:format => :json))}.to raise_error(ActiveRecord::Forbidden)\r
+  end\r
+  \r
+  # 保存処理を成功したことにしてスキップする\r
+  def allow_save my_model_class\r
+    allow_any_instance_of(my_model_class).to receive(:save).and_return(true)\r
+  end\r
+  \r
+  # 保存処理を失敗したことにしてスキップする\r
+  def reject_save my_model_class\r
+    allow_any_instance_of(my_model_class).to receive(:save).and_return(false)\r
+  end\r
+  \r
+  # 削除処理を成功したことにしてスキップする\r
+  def allow_destroy my_model_class\r
+    allow_any_instance_of(my_model_class).to receive(:destroy).and_return(true)\r
+  end\r
+  \r
+  # 削除処理を失敗したことにしてスキップする\r
+  def reject_destroy my_model_class\r
+    allow_any_instance_of(my_model_class).to receive(:destroy).and_return(false)\r
+  end\r
+  \r
+  def factory_contents factory_name, author, count = 5\r
+    FactoryGirl.create_list(factory_name, count, author: author)\r
+  end\r
+  \r
+end\r
+\r
index 2755426..7e59124 100644 (file)
@@ -1,24 +1,32 @@
+# -*- encoding: utf-8 -*-\r
 require 'spec_helper'\r
 require 'spec_helper'\r
+#スクロール\r
 \r
 describe 'scrolls/show.html.erb' do\r
   before do\r
 \r
 describe 'scrolls/show.html.erb' do\r
   before do\r
-    @user = FactoryGirl.create( :user_yas)\r
-    @author = FactoryGirl.create :author, :user_id => @user.id\r
+    @admin =FactoryGirl.create :admin\r
+    @user_yas = FactoryGirl.create :user_yas_with_owner\r
+    @user_rom = FactoryGirl.create :user_rom\r
+    @author_yas =  @user_yas.author\r
+    \r
   end\r
 \r
   end\r
 \r
-  context 'with 2 widgets' do\r
+  describe 'エディタ' do\r
     before(:each) do\r
     before(:each) do\r
-      @scroll = FactoryGirl.create :scroll, :author_id => @author.id\r
-      @operators = Operator.new [@user, @author, @artist, @admin, @demand_user]\r
-      assign(:item, @scroll)\r
+      @item =  FactoryGirl.create :scroll_hello, author: @author_yas\r
+      @item_id = @item.id\r
+      @operators = Operator.new [@user_yas, @author_yas, @artist, @admin, @demand_user]\r
+      assign(:item, @item)\r
       assign(:play_count, 3)\r
       assign(:operators, @operators)\r
     end\r
     \r
       assign(:play_count, 3)\r
       assign(:operators, @operators)\r
     end\r
     \r
-    it 'rendered' do\r
-      render\r
-      \r
-      rendered.should contain('icon')\r
+    context 'ownerなとき' do\r
+      it 'rendered' do\r
+        render\r
+        \r
+        rendered.should have_tag('h3.edit')\r
+      end\r
     end\r
   end\r
 end\r
     end\r
   end\r
 end\r