OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / license_groups_controller_spec.rb
index 63e42f7..377b05b 100644 (file)
@@ -6,11 +6,13 @@ describe LicenseGroupsController do
   before do
     @admin = FactoryGirl.create :admin
     @user = FactoryGirl.create( :user_yas)
+    @author = FactoryGirl.create :author, :user_id => @user.id
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group, :name => 'peta'
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
   end
 
+if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       sign_in @user
@@ -21,7 +23,7 @@ describe LicenseGroupsController do
         get :index
         response.should be_success 
       end
-      it 'ライセンスモデルに一覧を問い合わせている' do
+      it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97ã\83¢ã\83\87ã\83«ã\81«ä¸\80覧ã\82\92å\95\8fã\81\84å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' do
         LicenseGroup.should_receive(:list).exactly(1)
         get :index
       end
@@ -40,6 +42,10 @@ describe LicenseGroupsController do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do
+          LicenseGroup.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :index, :format => :json
           json = JSON.parse response.body
@@ -95,10 +101,17 @@ describe LicenseGroupsController do
           get :show, :id => @lg.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do
+          LicenseGroup.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @lg.id, :format => :json
+        end
         it 'データがアレになっている' do
           get :show, :id => @lg.id, :format => :json
           json = JSON.parse response.body
           json["name"].should match(/peta/)
+          json["classname"].should_not be_nil
+          json["caption"].should_not be_nil
+          json["url"].should_not be_nil
         end
       end
     end
@@ -113,5 +126,98 @@ describe LicenseGroupsController do
     end
   end
   
-
+else
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 okを返す' do
+        get :index
+        response.status.should eq 200
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      LicenseGroup.stub(:show).and_return(@lg)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @lg.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @lg.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @lg.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 okを返す' do
+        get :show, :id => @lg.id
+        response.status.should eq 200
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @lg.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @lg.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+end
 end