+# -*- encoding: utf-8 -*-
+#ライセンス
require 'spec_helper'
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator. If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails. There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec. Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
describe LicensesController do
-
- # This should return the minimal set of attributes required to create a valid
- # License. As you add validations to License, be sure to
- # update the return value of this method accordingly.
- def valid_attributes
- {}
- end
-
- describe "GET index" do
- it "assigns all licenses as @licenses" do
- license = License.create! valid_attributes
- get :index
- assigns(:licenses).should eq([license])
- end
+ before do
+ @admin = FactoryGirl.create :admin
+ @lg = FactoryGirl.create :license_group
+ @sp = FactoryGirl.create :system_picture
+ @user = FactoryGirl.create( :user_yas)
+ @author = FactoryGirl.create :author, :user_id => @user.id
+ @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
end
- describe "GET show" do
- it "assigns the requested license as @license" do
- license = License.create! valid_attributes
- get :show, :id => license.id
- assigns(:license).should eq(license)
+ describe '一覧表示に於いて' do
+ before do
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ sign_in @user
+ License.stub(:list).and_return([@l, @l, @l])
end
- end
-
- describe "GET new" do
- it "assigns a new license as @license" do
- get :new
- assigns(:license).should be_a_new(License)
- end
- end
-
- describe "GET edit" do
- it "assigns the requested license as @license" do
- license = License.create! valid_attributes
- get :edit, :id => license.id
- assigns(:license).should eq(license)
- end
- end
-
- describe "POST create" do
- describe "with valid params" do
- it "creates a new License" do
- expect {
- post :create, :license => valid_attributes
- }.to change(License, :count).by(1)
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
end
-
- it "assigns a newly created license as @license" do
- post :create, :license => valid_attributes
- assigns(:license).should be_a(License)
- assigns(:license).should be_persisted
+ it 'ライセンスモデルに一覧を問い合わせている' do
+ License.should_receive(:list).exactly(1)
+ get :index
end
-
- it "redirects to the created license" do
- post :create, :license => valid_attributes
- response.should redirect_to(License.last)
+ it '@licensesにリストを取得している' do
+ get :index
+ assigns(:licenses).should have_at_least(3).items
+ 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
+ it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
+ License.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
+ it 'データがリスト構造になっている' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("name").should be_true
+ json.first.has_key?("caption").should be_true
+ json.first.has_key?("url").should be_true
+ end
end
end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved license as @license" do
- # Trigger the behavior that occurs when invalid params are submitted
- License.any_instance.stub(:save).and_return(false)
- post :create, :license => {}
- assigns(:license).should be_a_new(License)
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
end
-
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- License.any_instance.stub(:save).and_return(false)
- post :create, :license => {}
- response.should render_template("new")
+ it 'ステータスコード200 okを返す' do
+ get :index
+ response.status.should eq 200
end
end
end
-
- describe "PUT update" do
- describe "with valid params" do
- it "updates the requested license" do
- license = License.create! valid_attributes
- # Assuming there are no other licenses in the database, this
- # specifies that the License created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- License.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => license.id, :license => {'these' => 'params'}
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ License.stub(:show).and_return(@l)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @l.id
+ response.should be_success
end
-
- it "assigns the requested license as @license" do
- license = License.create! valid_attributes
- put :update, :id => license.id, :license => valid_attributes
- assigns(:license).should eq(license)
+ it 'ライセンスモデルに単体取得を問い合わせている' do
+ License.should_receive(:show).exactly(1)
+ get :show
end
-
- it "redirects to the license" do
- license = License.create! valid_attributes
- put :update, :id => license.id, :license => valid_attributes
- response.should redirect_to(license)
+ it '@licenseにアレを取得している' do
+ get :show, :id => @l.id
+ assigns(:license).id.should eq(@l.id)
end
- end
-
- describe "with invalid params" do
- it "assigns the license as @license" do
- license = License.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- License.any_instance.stub(:save).and_return(false)
- put :update, :id => license.id, :license => {}
- assigns(:license).should eq(license)
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @l.id
+ response.should render_template("show")
+ end
end
-
- it "re-renders the 'edit' template" do
- license = License.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- License.any_instance.stub(:save).and_return(false)
- put :update, :id => license.id, :license => {}
- response.should render_template("edit")
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @l.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
+ License.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @l.id, :format => :json
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @l.id, :format => :json
+ json = JSON.parse response.body
+ json["name"].should match(/peta/)
+ json["caption"].should_not be_nil
+ json["url"].should_not be_nil
+ end
end
end
- end
-
- describe "DELETE destroy" do
- it "destroys the requested license" do
- license = License.create! valid_attributes
- expect {
- delete :destroy, :id => license.id
- }.to change(License, :count).by(-1)
- end
-
- it "redirects to the licenses list" do
- license = License.create! valid_attributes
- delete :destroy, :id => license.id
- response.should redirect_to(licenses_url)
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 okを返す' do
+ get :show, :id => @l.id
+ response.status.should eq 200
+ end
end
end
-
+
end