OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / spec / controllers / home_controller_spec.rb
index 0f7f3e7..62ac4cf 100644 (file)
@@ -18,6 +18,7 @@ describe HomeController do
     @panel = FactoryGirl.create :panel, :author_id => @author.id
   end
   
+if MagicNumber['run_mode'] == 1
   describe '自分のコミック一覧表示に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
@@ -626,4 +627,516 @@ describe HomeController do
     end
   end
   
+  describe '自分の素材一覧表示に於いて' 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
+      sign_in @user
+      ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :resource_picture, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :resource_picture
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :resource_picture, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :resource_picture
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :resource_picture, :page_size => 1500
+        assigns(:page_size).should eq Author.comic_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :resource_picture, :page_size => 0
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :resource_picture
+        response.should be_success 
+      end
+      it '素材モデルに一覧を問い合わせている' do
+        ResourcePicture.should_receive(:mylist).exactly(1)
+        get :resource_picture
+      end
+      it '@resource_picturesにリストを取得している' do
+        get :resource_picture
+        assigns(:resource_pictures).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'resource_pictureテンプレートを描画する' do
+          get :resource_picture
+          response.should render_template("resource_picture")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :resource_picture, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '素材モデルにjson一覧出力オプションを問い合わせている' do
+          ResourcePicture.should_receive(:list_json_opt).exactly(1)
+          get :resource_picture, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :resource_picture, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは素材っぽいものであって欲しい' do
+          get :resource_picture, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("original_picture_id").should be_true
+          json.first.has_key?("license_id").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :resource_picture
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :resource_picture
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :resource_picture, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :resource_picture, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '作家が絵師でないとき' do
+      before do
+        Author.any_instance.stub(:artist?).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :resource_picture
+          response.status.should eq 302
+        end
+        it '絵師登録ページへ遷移する' do
+          get :resource_picture
+          response.should redirect_to new_artist_path
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :resource_picture, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
+  end
+  
+else
+  describe '自分のコミック一覧表示に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      sign_in @user
+      Comic.stub(:mylist).and_return([@comic, @comic, @comic])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comic
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :comic
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comic, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comic
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comic
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comic, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comic, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のコマ一覧表示に於いて' do
+    before do
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      sign_in @user
+      Panel.stub(:mylist).and_return([@panel, @panel, @panel])
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel
+          response.should be_success 
+        end
+        it 'panelテンプレートを描画する' do
+          get :panel
+          response.should render_template("panel")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :panel, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :panel
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :panel
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :panel, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :panel, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のコマ絵一覧表示に於いて' do
+    before do
+      @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+        :width => @p.width, :height => @p.height
+      sign_in @user
+      PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :panel_picture
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'panel_pictureテンプレートを描画する' do
+          get :panel_picture
+          response.should render_template("panel_picture")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panel_picture, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :panel_picture
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :panel_picture
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :panel_picture, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :panel_picture, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のコマの色背景一覧表示に於いて' do
+    before do
+      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+      sign_in @user
+      PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :panel_color
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'panel_colorテンプレートを描画する' do
+          get :panel_color
+          response.should render_template("panel_color")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panel_color, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :panel_color
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :panel_color
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :panel_color, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :panel_color, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のコマの画像背景一覧表示に於いて' do
+    before do
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      sign_in @user
+      GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :ground_picture
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'ground_pictureテンプレートを描画する' do
+          get :ground_picture
+          response.should render_template("ground_picture")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :ground_picture, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :ground_picture
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :ground_picture
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :ground_picture, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :ground_picture, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分の間接背景一覧表示に於いて' do
+    before do
+      @gc = FactoryGirl.create :ground_color
+      sign_in @user
+      GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :ground_color
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'ground_colorテンプレートを描画する' do
+          get :ground_color
+          response.should render_template("ground_color")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :ground_color, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :ground_color
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :ground_color
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :ground_color, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :ground_color, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分の素材一覧表示に於いて' 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
+      sign_in @user
+      ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :resource_picture
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'resource_pictureテンプレートを描画する' do
+          get :resource_picture
+          response.should render_template("resource_picture")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :resource_picture, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :resource_picture
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :resource_picture
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :resource_picture, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :resource_picture, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context '作家が絵師でないとき' do
+      before do
+        Author.any_instance.stub(:artist?).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :resource_picture
+          response.status.should eq 302
+        end
+        it '絵師登録ページへ遷移する' do
+          get :resource_picture
+          response.should redirect_to new_artist_path
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :resource_picture, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
+  end
+  
+end
 end