describe AuthorsController do
before do
- Factory :admin
- @user = Factory( :user_yas)
- @author = @user.author
- @artist = Factory :artist_yas, :author_id => @author.id
+ @admin =FactoryGirl.create :admin
+ @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
end
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
Author.stub(:list).and_return([@author, @author, @author])
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it '作家モデルにjson一覧出力オプションを問い合わせている' do
+ Author.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
it 'データがリスト構造になっている' do
get :index, :format => :json
json = JSON.parse response.body
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("name").should be_true
+ json.first.has_key?("user_id").should be_true
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ end
end
describe '閲覧に於いて' do
Author.should_receive(:show).exactly(1)
get :show
end
- it '@authorにアレを取得している' do
+ #@authorだとログイン中のアカウントと干渉してしまう。
+ it '@auにアレを取得している' do
get :show, :id => @author.id
- assigns(:author).should eq(@author)
+ assigns(:au).should eq(@author)
end
context 'html形式' do
it 'showテンプレートを描画する' do
get :show, :id => @author.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it '作家モデルにjson単体出力オプションを問い合わせている' do
+ Author.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @author.id, :format => :json
+ end
it 'データがアレになっている' do
get :show, :id => @author.id, :format => :json
json = JSON.parse response.body
- json["name"].should match(/yas/)
+ json["name"].should match(/test/)
+ json["user_id"].should eq @author.user_id
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @author.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @author.id
+ response.should be_success
+ end
+ end
=begin
context '対象作家がないとき' do
context 'html形式' do
get :count, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'データがHash構造になっていてコミック数が1である' do
+ it 'データがHash構造になっていて作家数が3である' do
get :count, :format => :json
json = JSON.parse response.body
json["count"].should == 3
end
end
end
-
- describe 'コミック一覧表示に於いて' do
- #指定作家のコミックpage_size件を一覧形式で表示する。ただし、作者によって非公開にされたコミックは含まない。
+
+ describe '新規作成フォーム表示に於いて' do
before do
- @comic = Factory :normal_comic, :author_id => @author.id
- Comic.stub(:list_by_author).and_return([@comic, @comic, @comic])
- sign_in @user
+ @new_user = FactoryGirl.create( :user_yas)
+ sign_in @new_user
end
- context '事前チェックする' do
- it '与えられたpageがセットされている' do
- get :comics, :id => @author.id, :page => 5
- assigns(:page).should eq 5
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
end
- it '省略されると@pageに1値が入る' do
- get :comics, :id => @author.id
- assigns(:page).should eq 1
+ it '@auに新規データを用意している' do
+ get :new
+ assigns(:au).should be_a_new(Author)
end
- it 'ä¸\8eã\81\88ã\82\89ã\82\8cã\81\9fpage_sizeã\81\8cã\82»ã\83\83ã\83\88ã\81\95ã\82\8cている' do
- get :comics, :id => @author.id, :page_size => 15
- assigns(:page_size).should eq 15
+ it 'ä½\9c家ã\83¢ã\83\87ã\83«ã\81«ã\83\87ã\83\95ã\82©ã\83«ã\83\88å\80¤è£\9cå\85\85ã\82\92ä¾\9dé ¼ã\81\97ている' do
+ Author.any_instance.should_receive(:supply_default).exactly(1)
+ get :new
end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :comics, :id => @author.id
- assigns(:page_size).should eq Author.default_page_size
+ context 'html形式' do
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :comics, :id => @author.id, :page_size => 1500
- assigns(:page_size).should eq Author.max_page_size
+ context 'js形式' do
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :comics, :id => @author.id, :page_size => 0
- assigns(:page_size).should eq Author.default_page_size
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it '作家モデルにjson単体出力オプションを問い合わせている' do
+ Author.should_receive(:show_json_opt).exactly(1)
+ get :new, :format => :json
+ end
end
end
- context 'つつがなく終わるとき' do
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @new_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
it 'ステータスコード200 OKを返す' do
- get :comics, :id => @author.id
+ get :new
response.should be_success
end
- it 'コミックモデルに一覧を問い合わせている' do
- Comic.should_receive(:list_by_author).exactly(1)
- get :comics, :id => @author.id
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ @new_user = FactoryGirl.create( :user_yas)
+ sign_in @new_user
+ @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
+ end
+ context '事前チェックしておく' do
+ it '作家モデルにデフォルト値補充を依頼している' do
+ Author.any_instance.should_receive(:supply_default).exactly(1)
+ post :create, :author => @attr
+ end
+ it '作家モデルにカラム値復元を依頼している' do
+ Author.any_instance.should_receive(:attributes=).exactly(1)
+ post :create, :author => @attr
end
- it '@comicsにリストを取得している' do
- get :comics, :id => @author.id
- assigns(:comics).should have_at_least(3).items
+ it '作家モデルに上書き補充を依頼している' do
+ Author.any_instance.should_receive(:overwrite).exactly(1)
+ post :create, :author => @attr
+ end
+ it 'モデルに保存依頼する' do
+ Author.any_instance.should_receive(:save).exactly(1)
+ post :create, :author => @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it "@auに作成された作家を保持していて、それがDBにある" do
+ post :create, :author => @attr
+ assigns(:au).should be_a(Author)
+ assigns(:au).should be_persisted
end
context 'html形式' do
- it 'comicsテンプレートを描画する' do
- get :comics, :id => @author.id
- response.should render_template("comics")
+ it 'ステータスコード302 Foundを返す' do
+ Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr
+ response.status.should eq 302
+ end
+ it 'トップページへ遷移する' do
+# Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr
+ response.should redirect_to(root_path)
end
end
context 'json形式' do
- it 'jsonデータを返す' do
- get :comics, :id => @author.id, :format => :json
+ it 'ステータスコード200 OKを返す' do
+# Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr, :format => :json
+ response.should be_success
+ end
+ it '作成された作家をjsonデータで返す' do
+ post :create, :author => @attr, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'データがリスト構造になっている' do
- get :comics, :id => @author.id, :format => :json
- json = JSON.parse response.body
- json.should have_at_least(3).items
+ it '作家モデルにjson単体出力オプションを問い合わせている' do
+ Author.should_receive(:show_json_opt).exactly(1)
+ post :create, :author => @attr, :format => :json
end
- it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯ã\82³ã\83\9fã\83\83ã\82¯ã\81£ã\81½ã\81\84ã\82\82ã\81®ã\81§ã\81\82ã\81£ã\81¦æ¬²ã\81\97ã\81\84' do
- get :comics, :id => @author.id, :format => :json
+ it 'ã\83\87ã\83¼ã\82¿ã\81\8cã\82¢ã\83¬ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\82\8b' do
+ post :create, :author => @attr, :format => :json
json = JSON.parse response.body
- json.first.has_key?("title").should be_true
+ json["name"].should match(/ken/)
end
end
end
- context '作家権限がないとき' do
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @new_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :author => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :author => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :author => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
before do
sign_out @user
+ sign_in @admin
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- get :comics, :id => @author.id
+ post :create, :author => @attr
response.status.should eq 302
end
it 'サインインページへ遷移する' do
- get :comics, :id => @author.id
- response.should redirect_to '/users/sign_in'
+ post :create, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ Author.any_instance.stub(:save).and_return(false)
+ end
+ it "未保存の作家を保持している" do
+ post :create, :author => @attr
+ assigns(:au).should be_a_new(Author)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, :author => @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, :author => @attr
+ response.should render_template("new")
end
end
context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ post :create, :author => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ post :create, :author => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ sign_in @user
+ Author.stub(:edit).and_return(@author)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @author.id
+ response.should be_success
+ end
+ it '作家モデルに編集取得を問い合わせている' do
+ Author.should_receive(:edit).exactly(1)
+ get :edit, :id => @author.id
+ end
+ #@authorだとログイン中のアカウントと干渉してしまう。
+ it '@auにデータを用意している' do
+ get :edit, :id => @author.id
+ assigns(:au).should eq @author
+ end
+ context 'html形式' do
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @author.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @author.id, :format => :js
+ response.should render_template("edit")
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @author.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @author.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
it 'ステータスコード401 Unauthorizedを返す' do
- get :comics, :id => @author.id, :format => :json
+ get :edit, :id => @author.id, :format => :js
response.status.should eq 401
end
it '応答メッセージにUnauthorizedを返す' do
- get :comics, :id => @author.id, :format => :json
+ get :edit, :id => @author.id, :format => :js
response.message.should match(/Unauthorized/)
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @author.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @author.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @other_user = FactoryGirl.create( :user_yas)
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @other_author.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :edit, :id => @other_author.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
end
-
- describe 'コマ一覧表示に於いて' do
- #指定作家のコマpage_size件を一覧形式で表示する。ただし、作者によって非公開にされたコミックのコマは含まない。
+
+ describe '更新に於いて' do
before do
- @comic = Factory :normal_comic, :author_id => @author.id
- @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
- Panel.stub(:list_by_author).and_return([@panel, @panel, @panel])
+ @attr = @author.attributes
+ @attr['name'] = 'ryu'
sign_in @user
end
- context '事前チェックする' do
- it '与えられたpageがセットされている' do
- get :panels, :id => @author.id, :page => 5
- assigns(:page).should eq 5
+ context '事前チェックしておく' do
+ it '作家モデルに編集取得を問い合わせている' do
+ Author.stub(:edit).with(any_args()).and_return @author
+ Author.should_receive(:edit).exactly(1)
+ put :update, :id => @author.id, :author => @attr
end
- it '省略されると@pageに1値が入る' do
- get :panels, :id => @author.id
- assigns(:page).should eq 1
+ it 'モデルにpostデータ転送を依頼する' do
+ Author.any_instance.stub(:attributes=).with(any_args)
+ Author.any_instance.should_receive(:attributes=).exactly(1)
+ put :update, :id => @author.id, :author => @attr
end
- it '与えられたpage_sizeがセットされている' do
- get :panels, :id => @author.id, :page_size => 15
- assigns(:page_size).should eq 15
+ it 'モデルに上書き補充を依頼する' do
+ Author.any_instance.stub(:overwrite).with(any_args)
+ Author.any_instance.should_receive(:overwrite).exactly(1)
+ put :update, :id => @author.id, :author => @attr
end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :panels, :id => @author.id
- assigns(:page_size).should eq Author.default_page_size
+ it 'モデルに更新を依頼する' do
+ Author.any_instance.stub(:save).with(any_args).and_return true
+ Author.any_instance.should_receive(:save).exactly(1)
+ put :update, :id => @author.id, :author => @attr
end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :panels, :id => @author.id, :page_size => 1500
- assigns(:page_size).should eq Author.max_page_size
+ it '@auにアレを取得している' do
+ put :update, :id => @author.id, :author => @attr
+ assigns(:au).should eq @author
end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :panels, :id => @author.id, :page_size => 0
- assigns(:page_size).should eq Author.default_page_size
+ end
+ context 'つつがなく終わるとき' do
+ it '更新される' do
+ put :update, :id => @author.id, :author => @attr
+ Author.find(@author.id).name.should eq 'ryu'
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 302
+ end
+ it '設定ページへ遷移する' do
+ put :update, :id => @author.id, :author => @attr
+ response.should redirect_to('/home/configure')
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.body.should match /./
+ end
end
end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @author.id, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @author.id, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @other_user = FactoryGirl.create( :user_yas)
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+ @author.destroy
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :update, :id => @other_author.id
+ response.status.should eq 302
+ end
+ it '作家登録ページへ遷移する' do
+ get :update, :id => @other_author.id
+ response.body.should redirect_to new_author_path
+ end
+ end
+ end
+ context '検証、保存に失敗したとき' do
+ before do
+ Author.any_instance.stub(:save).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @author.id, :author => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ Author.any_instance.stub(:save).and_return(false)
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ Author.stub(:list).and_return([@author, @author, @author])
+ sign_in @user
+ end
context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
- get :panels, :id => @author.id
+ get :index
response.should be_success
end
- it 'コマモデルに一覧を問い合わせている' do
- Panel.should_receive(:list_by_author).exactly(1)
- get :panels, :id => @author.id
+ 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
- it '@panelsにリストを取得している' do
- get :panels, :id => @author.id
- assigns(:panels).should have_at_least(3).items
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
end
context 'html形式' do
- it 'panelsテンプレートを描画する' do
- get :panels, :id => @author.id
- response.should render_template("panels")
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :panels, :id => @author.id, :format => :json
+ get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'データがリスト構造になっている' do
- get :panels, :id => @author.id, :format => :json
- json = JSON.parse response.body
- json.should have_at_least(3).items
+ end
+ end
+ end
+
+ describe '閲覧に於いて' do
+ before do
+ Author.stub(:show).and_return(@author)
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @author.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @author.id
+ response.should render_template("show")
end
- it 'リストの先頭くらいはコマっぽいものであって欲しい' do
- get :panels, :id => @author.id, :format => :json
- json = JSON.parse response.body
- json.first.has_key?("link").should be_true
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @author.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @author.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @author.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @author.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '作家数取得に於いて' do
+ before do
+ Author.should_receive(:visible_count).and_return(3)
+# sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :count, :format => :json
+ response.should be_success
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :count, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ @new_user = FactoryGirl.create( :user_yas)
+ sign_in @new_user
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'newテンプレートを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'new.jsテンプレートを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @new_user
+ end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- get :panels, :id => @author.id
+ get :new
response.status.should eq 302
end
it 'サインインページへ遷移する' do
- get :panels, :id => @author.id
- response.should redirect_to '/users/sign_in'
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :js
+ response.message.should match(/Unauthorized/)
end
end
context 'json形式' do
it 'ステータスコード401 Unauthorizedを返す' do
- get :panels, :id => @author.id, :format => :json
+ get :new, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ @new_user = FactoryGirl.create( :user_yas)
+ sign_in @new_user
+ @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr
+ response.status.should eq 302
+ end
+ it 'トップページへ遷移する' do
+# Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr
+ response.should redirect_to(root_path)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+# Author.any_instance.stub(:save).and_return(true)
+ post :create, :author => @attr, :format => :json
+ response.should be_success
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @new_user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, :author => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, :author => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, :author => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ sign_in @user
+ Author.stub(:edit).and_return(@author)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @author.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'editテンプレートを描画する' do
+ get :edit, :id => @author.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it 'edit.jsテンプレートを描画する' do
+ get :edit, :id => @author.id, :format => :js
+ response.should render_template("edit")
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @author.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @author.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @author.id, :format => :js
response.status.should eq 401
end
it '応答メッセージにUnauthorizedを返す' do
- get :panels, :id => @author.id, :format => :json
+ get :edit, :id => @author.id, :format => :js
response.message.should match(/Unauthorized/)
end
end
end
end
+
+ describe '更新に於いて' do
+ before do
+ @attr = @author.attributes
+ @attr['name'] = 'ryu'
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ it '更新される' do
+ put :update, :id => @author.id, :author => @attr
+ Author.find(@author.id).name.should eq 'ryu'
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 302
+ end
+ it '設定ページへ遷移する' do
+ put :update, :id => @author.id, :author => @attr
+ response.should redirect_to('/home/configure')
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ Author.any_instance.stub(:save).with(any_args()).and_return(true)
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @author.id, :author => @attr
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ put :update, :id => @author.id, :author => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @author.id, :author => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+end
end