# PUT /original_pictures/1.json
def update
@picture_data = set_image params[:original_picture][:file]
- @original_picture = OriginalPicture.show(params[:id], @author)
+ @original_picture = OriginalPicture.edit(params[:id], @author)
@original_picture.supply_default @artist
respond_to do |format|
# DELETE /original_pictures/1
# DELETE /original_pictures/1.json
def destroy
- @original_picture = OriginalPicture.find(params[:id], @author)
+ @original_picture = OriginalPicture.edit(params[:id], @author)
OriginalPicture.transaction do
@original_picture.destroy
end
# PUT /stories/1
# PUT /stories/1.json
def update
- @story = Story.show(params[:id], @author)
+ @story = Story.edit(params[:id], @author)
ot = @story.t
@story.attributes = params[:story]
@story.overwrite @author
# DELETE /stories/1.js
# DELETE /stories/1.json
def destroy
- @story = Story.show(params[:id], @author)
- @story.destroy_and_shorten
+ @story = Story.edit(params[:id], @author)
+ Story.transaction do
+ @story.destroy_and_shorten
+ end
respond_to do |format|
format.html { redirect_to story_path(@story.comic) }
format.json { head :ok }
pic
end
+ def self.edit cid, artist, opt = {}
+ pic = OriginalPicture.find(cid, :include => self.show_include_opt(opt))
+ raise ActiveRecord::Forbidden unless pic.own?(artist)
+ pic
+ end
+
def self.show_include_opt opt = {}
res = [:license, :resource_picture]
res.push(opt[:include]) if opt[:include]
self.author_id == author.id
end
- def self.show sid, au = nil
+ def self.edit sid, au
res = Story.find sid
- if au
- raise ActiveRecord::Forbidden unless res.own?(au)
- end
+ raise ActiveRecord::Forbidden unless res.own?(au)
res
end
describe '更新に於いて' do
before do
@pic = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
- OriginalPicture.stub(:show).with(any_args()).and_return(@pic)
+ OriginalPicture.stub(:edit).with(any_args()).and_return(@pic)
sign_in @user
end
context '事前チェックしておく' do
OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
end
it '原画モデルに単体取得を問い合わせている' do
- OriginalPicture.should_receive(:show).exactly(1)\r
+ OriginalPicture.should_receive(:edit).exactly(1)\r
put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
end
it 'モデルに更新を依頼する' do
sign_in @user
end
context 'つつがなく終わるとき' do
- it 'モデルに取得依頼する' do
- Story.stub(:show).with(any_args).and_return(@story)
- Story.should_receive(:show).exactly(1)
+ it 'モデルに編集取得依頼する' do
+ Story.stub(:edit).with(any_args).and_return(@story)
+ Story.should_receive(:edit).exactly(1)
put :update, :id => @story.id, :story => @attr
end
it 'POSTデータから、カラム値を復元している' do
end
end
+ describe '削除に於いて' do\r
+ before do\r
+ @story = Factory :story, :author_id => @author.id
+ sign_in @user
+ Story.stub(:edit).and_return(@story)\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ストーリーモデルに編集取得を問い合わせている' do\r
+ Story.should_receive(:edit).exactly(1)\r
+ delete :destroy, :id => @story.id\r
+ end\r
+ it '@storyにアレを取得している' do\r
+ delete :destroy, :id => @story.id\r
+ assigns(:story).id.should eq(@story.id)\r
+ end\r
+ it 'そのストーリーを一つのトランザクションで削除する' do\r
+ lambda {\r
+ delete :destroy, :id => @story.id\r
+ }.should change(Story, :count)\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ delete :destroy, :id => @story.id\r
+ response.status.should eq 302\r
+ end\r
+ it 'ストーリー一覧ページへ遷移する' do\r
+ delete :destroy, :id => @story.id\r
+ response.should redirect_to(story_path(@story.comic_id))\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード200 OKを返す' do\r
+ delete :destroy, :id => @story.id, :format => :json\r
+ response.should be_success\r
+ end\r
+ end\r
+ end\r
+ context '作家権限がないとき' do\r
+ before do\r
+ sign_out @user\r
+ end\r
+ context 'html形式' do\r
+ it 'ステータスコード302 Foundを返す' do\r
+ delete :destroy, :id => @story.id\r
+ response.status.should eq 302\r
+ end\r
+ it 'サインインページへ遷移する' do\r
+ delete :destroy, :id => @story.id\r
+ response.body.should redirect_to '/users/sign_in'\r
+ end\r
+ end\r
+ context 'json形式' do\r
+ it 'ステータスコード401 Unauthorizedを返す' do\r
+ delete :destroy, :id => @story.id, :format => :json\r
+ response.status.should eq 401\r
+ end\r
+ it '応答メッセージにUnauthorizedを返す' do\r
+ delete :destroy, :id => @story.id, :format => :json\r
+ response.message.should match(/Unauthorized/)\r
+ end\r
+ end\r
+ end\r
+=begin\r
+ context '対象ストーリーがないとき' do\r
+ end\r
+ context '他人のストーリーだったとき' do\r
+ end\r
+=end\r
+ end\r
+ \r
end
end
end
end
+ describe '編集取得に於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+ it '指定の原画を返す' do
+ pic = OriginalPicture.edit @op.id, @artist
+ pic.should eq @op
+ end
+ context '関連テーブルオプションがないとき' do
+ it 'ライセンスと素材を含んでいる' do
+ r = OriginalPicture.show_include_opt
+ r.should eq [:license, :resource_picture]
+ end
+ end
+ context '関連テーブルオプションで絵師を含ませたとき' do
+ it 'ライセンスと素材と作者データを含んでいる' do
+ r = OriginalPicture.show_include_opt(:include => :artist)
+ r.should eq [:license, :resource_picture, :artist]
+ end
+ end
+ context '他人の原画を開こうとしたとき' do
+ it '403Forbidden例外を返す' do
+ lambda{
+ pic = OriginalPicture.edit @op.id, @other_artist
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない原画を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ pic = OriginalPicture.edit 0, @artist
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
describe 'json単体出力オプションに於いて' do
it 'includeキーがライセンスと素材を含んでいる' do
r = OriginalPicture.show_json_include_opt
@panel = Factory :panel, :author_id => @author.id
@story = Factory :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
end
- context 'オーナー指定がないとき' do
- it '指定のストーリーを返す' do
- l = Story.show @story.id, @author
- l.should eq @story
- end
+ it '指定のストーリーを返す' do
+ l = Story.edit @story.id, @author
+ l.should eq @story
end
- context 'オーナー指定のとき' do
- it '指定のストーリーが自分のものならそれを返す' do
- l = Story.show @story.id, @author
- l.should eq @story
- end
- context '他人のストーリーを開こうとしたとき' do
- it '403Forbidden例外を返す' do
- Story.any_instance.stub(:own?).and_return(false)
- lambda{
- Story.show @story.id, @author
- }.should raise_error(ActiveRecord::Forbidden)
- end
+ context '他人のストーリーを開こうとしたとき' do
+ it '403Forbidden例外を返す' do
+ Story.any_instance.stub(:own?).and_return(false)
+ lambda{
+ Story.edit @story.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
end
end
context '存在しないストーリーを開こうとしたとき' do
it '404RecordNotFound例外を返す' do
lambda{
- Story.show 110, @author
+ Story.edit 110, @author
}.should raise_error(ActiveRecord::RecordNotFound)
end
end