# GET /original_pictures/1
# GET /original_pictures/1.json
def show
- @original_picture = OriginalPicture.show(params[:id])
+ @original_picture = OriginalPicture.show(params[:id], @author)
# if params[:subdir] == 'refresh'
# refresh
# return
# end
respond_to do |format|
- if @original_picture.own?(@author)
- opt = {:type => @original_picture.mime_type, :disposition=>"inline"}
- format.png { send_data(@original_picture.restore, opt ) }
- format.gif { send_data(@original_picture.restore, opt ) }
- format.jpeg { send_data(@original_picture.restore, opt ) }
- format.html # show.html.erb
- format.json { render json: @original_picture}
- else
- raise ActiveRecord::Forbidden
- end
+ opt = {:type => @original_picture.mime_type, :disposition=>"inline"}
+ format.png { send_data(@original_picture.restore, opt ) }
+ format.gif { send_data(@original_picture.restore, opt ) }
+ format.jpeg { send_data(@original_picture.restore, opt ) }
+ format.html # show.html.erb
+ format.json { render json: @original_picture}
end
end
# GET /original_pictures/1/edit
def edit
- @original_picture = OriginalPicture.show(params[:id])
- raise ActiveRecord::Forbidden unless @original_picture.own?(@author)
+ @original_picture = OriginalPicture.show(params[:id], @author)
respond_to do |format|
format.html
format.js
# PUT /original_pictures/1
# PUT /original_pictures/1.json
def update
- @original_picture = OriginalPicture.show(params[:id])
- raise ActiveRecord::Forbidden unless @original_picture.own?(@author)
+ @original_picture = OriginalPicture.show(params[:id], @author)
img = set_image params
respond_to do |format|
# DELETE /original_pictures/1
# DELETE /original_pictures/1.json
def destroy
- @original_picture = OriginalPicture.find(params[:id])
- raise ActiveRecord::Forbidden unless @original_picture.own?(@author)
+ @original_picture = OriginalPicture.find(params[:id], @author)
OriginalPicture.transaction do
@original_picture.destroy
end
{:include => [:resource_picture, :artist, :license]}
end
- def self.show cid, opt = {}
- Comic.find(cid, :include => self.show_include_opt(opt))
+ def self.show cid, author, opt = {}
+ pic = OriginalPicture.find(cid, :include => self.show_include_opt(opt))
+ raise ActiveRecord::Forbidden unless pic.own?(author)
+ pic
end
def self.show_include_opt opt = {}
- res = [:author]
+ res = [:license]
res.push(opt[:include]) if opt[:include]
res
end
def self.show_json_include_opt
- {:include => :author}
+ {:include => :license}
end
def destroy_with_file
end
end
end
+=begin
context '対象原画がないとき' do
before do
OriginalPicture.unstub(:show)
end
end
end
+=end
end
describe '新規作成フォーム表示に於いて' do
end
end
end
- context '対象コミックがないとき' do
- before do
- OriginalPicture.unstub(:show)
- end
- context 'html形式' do
- it '例外404 not_foundを返す' do
- lambda{
- get :edit, :id => 0
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- context 'js形式' do
- it '例外404 not_foundを返す' do
- lambda{
- get :edit, :id => 0, :format => :js
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- end
- context '他人の原画を見ようとしたとき' do
- before do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
- end
- context 'html形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- get :edit, :id => @pic.id
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- context 'js形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- get :edit, :id => @pic.id, :format => :js
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- end
end
describe '更新に於いて' do
end
end
end
- context '対象原画がないとき' do
- before do
- end
- context 'html形式' do
- it '例外404 not_foundを返す' do
- lambda{
- put :update, :id => 0, :original_picture => Factory.attributes_for(:original_picture)
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- context 'json形式' do
- it '例外404 not_foundを返す' do
- lambda{
- put :update, :id => 0, :original_picture => Factory.attributes_for(:original_picture), :format => :json
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- end
- context '他人の原画を見ようとしたとき' do
- before do
- OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
- end
- context 'html形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- context 'json形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- end
context '検証、保存に失敗した' do
before do
OriginalPicture.any_instance.stub(:save).and_return(false)