OSDN Git Service

t#30443:add test for open mode
[pettanr/pettanr.git] / spec / controllers / colors_controller_spec.rb
index 7ad3e50..78fc896 100644 (file)
@@ -12,6 +12,7 @@ describe ColorsController do
     @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
@@ -151,4 +152,100 @@ describe ColorsController do
     end
   end
   
+else
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @color = FactoryGirl.create :color
+      Color.stub(:list).and_return([@color, @color, @color])
+    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
+      @color = FactoryGirl.create :color
+      Color.stub(:show).and_return(@color)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @color.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @color.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @color.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 => @color.id
+        response.status.should eq 200
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @color.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @color.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+end
 end