@artist = if @author and @author.artist?
@author.artist
else
- Artist.new author_id: @author.id, email: @user.email, name: @author.name
+ nil
end
end
end
layout 'test' if MagicNumber['test_layout']
before_filter :authenticate_user!, :only => [:show, :credit, :md5]
before_filter :authenticate_artist, :only => [:md5]
+ before_filter :authenticate_admin!, :only => [:list, :browse]
def show
@picture = Picture.show(params[:id], @author)
end
end
+ def list
+ @pictures = Picture.all
+
+ respond_to do |format|
+ format.html { render layout: 'system' }# index.html.erb
+ format.json { render json: @pictures }
+ end
+ end
+
+ def browse
+ @picture = Picture.find(params[:id])
+
+ respond_to do |format|
+ format.html { render layout: 'system' } # show.html.erb
+ format.json { render json: @picture }
+ end
+ end
end
class ResourcePicturesController < ApplicationController
layout 'test' if MagicNumber['test_layout']
- before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update]
+ before_filter :authenticate_user!, :only => [:index, :show, :credit, :new, :create, :update, :destroy]
before_filter :authenticate_admin!, :only => [:list, :browse]
- before_filter :authenticate_artist, :only => [:new, :create]
+ before_filter :authenticate_artist, :only => [:new, :create, :destroy]
# GET /resource_pictures
# GET /resource_pictures.json
end
end
+ def destroy
+ @resource_picture = ResourcePicture.edit(params[:id], @artist)
+
+ respond_to do |format|
+ if @resource_picture.unpublish
+ format.html { redirect_to resource_pictures_path }
+ format.json { head :ok }
+ else
+ format.html { render resource_picture_path(@resource_picture) }
+ format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
def count
@resource_picture = {:count => ResourcePicture.visible_count}
respond_to do |format|
end
end
- def new
- respond_to do |format|
- format.html # new.html.erb
- end
- end
-
- # POST /system_pictures
- # POST /system_pictures.json
- def create
- @imager = PettanImager.load set_image params[:system_picture][:file]
-
- respond_to do |format|
- @system_picture = SystemPicture.store @imager
- if @system_picture
- format.html { redirect_to @system_picture, notice: 'system picture was successfully created.' }
- format.json { render json: @system_picture.to_json(SystemPicture.show_json_opt), status: :created, location: @system_picture }
- else
- format.html { render action: "new" }
- format.json { render json: {}, status: :unprocessable_entity }
- end
- end
- end
-
end
end
def opt_img_tag
+ {:src => self.url, :width => self.width, :height => self.height}
+ end
+
+ def tmb_opt_img_tag
tw, th = PettanImager.thumbnail_size(self.width, self.height)
{:src => self.url, :width => tw, :height => th}
end
self.revision = self.new_revision #Do not move to attr. new_revision reffernces self.original_picture_id
end
- def own? author
- return false
+ def own? ar
+ if ar.is_a?(Author)
+ self.artist_id == ar.artist.id
+ elsif ar.is_a?(Artist)
+ self.artist_id == ar.id
+ else
+ false
+ end
+ end
+
+ def visible? ar
+ return true
end
- def visible? author
- true
+ def showable? ar
+ return false unless ar.is_a?(Artist)
+ return true if self.own?(ar)
+ self.enable? and self.head?
end
def filename
end
def opt_img_tag
+ {:src => self.url, :width => self.width, :height => self.height}
+ end
+
+ def tmb_opt_img_tag
tw, th = PettanImager.thumbnail_size(self.width, self.height)
{:src => self.url, :width => tw, :height => th}
end
Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
end
- def head?
- r = self.resource_picture
+ def enable?
+ r = self.head.resource_picture
r ? true : false
end
+ def head
+ Picture.find(:first, :conditions => ['original_picture_id = ?', self.original_picture_id], :order => 'pictures.revision desc')
+ end
+
+ def head?
+ self == head
+ end
+
def to_gif?
self.ext == 'png' and self.flag_gif_convert >= 0
end
validates :classname, :presence => true, :length => {:maximum => 50}
validates :picture_id, :presence => true, :numericality => true, :existence => true
- before_destroy :destroy_with_file
-
- def destroy_with_file
- PictureIO.resource_picture_io.delete self.filename
- PictureIO.resource_picture_io.class.subdirs.each do |d|
- next if d.empty?
- PictureIO.resource_picture_io.delete(self.filename, d) if PictureIO.resource_picture_io.exist?(self.filename, d)
- end
- end
-
def supply_default
end
self.attributes = attr
end
- def own? author
- return false
+ def own? ar
+ return false unless ar.is_a?(Artist)
+ ar.id == self.artist_id
end
def visible? au
{:include => {:license => {}, :artist => {}, :picture => {}} }
end
+ def self.edit rid, ar
+ opt = {}
+ opt.merge!(self.show_opt)
+ r = ResourcePicture.find(rid, opt)
+ raise ActiveRecord::Forbidden unless r.own?(ar)
+ r
+ end
+
def new_picture imager
pc = Picture.new
pc.supply_default
PictureIO.resource_picture_io.get self.filename, subdir
end
+ def unpublish
+ r = true
+ ResourcePicture.transaction do
+ self.destroy
+ PictureIO.resource_picture_io.delete(self.filename)
+ PictureIO.resource_picture_io.delete(self.filename, 'full')
+ end
+ r
+ end
+
def self.visible_count
ResourcePicture.count
end
'/system_pictures/' + filename
end
+ def opt_img_tag
+ {:src => self.url, :width => self.width, :height => self.height}
+ end
+
+ def tmb_opt_img_tag
+ tw, th = PettanImager.thumbnail_size(self.width, self.height)
+ {:src => self.url, :width => tw, :height => th}
+ end
+
def self.default_page_size
25
end
<table class="no-border">
<tr>
<td>
- <%= link_to(tag(:img, picture.opt_img_tag), picture_path(picture.id)) -%>
+ <%= link_to(tag(:img, picture.tmb_opt_img_tag), picture_path(picture.id)) -%>
</td>
<td>
<%= render picture.credit_template, :picture => picture %>
</div>
<tr>
<td>
- <%= link_to tag(:img, original_picture.opt_img_tag), original_picture %>
+ <%= link_to tag(:img, original_picture.tmb_opt_img_tag), original_picture %>
</td>
<td><%= original_picture.pictures.empty? ? '' : original_picture.history.first.revision %></td>
<td><%= original_picture.filename %></td>
</td>
</tr>
</table>
+<%= link_to 'destroy', resource_picture_path(@original_picture.resource_picture), :method => :delete %>
<%= link_to 'Back', original_pictures_path %>
-<h2>revision:<%= picture.revision %></h2>
-<img src="<%= picture.url -%>">
-<h2>credit</h2>
-<%= render picture.full_credit_template, :picture => picture %>
-<h2>properties</h2>
-<div>
- <%= picture.ext %>
-</div>
-<div>
- <%= picture.width %>x<%= picture.height %>px
-</div>
-<div>
- <%= picture.filesize %>bytes
-</div>
+<table>
+ <tr>
+ <td>
+ <%= tag :img, picture.opt_img_tag -%>
+ <h2><%= t('pictures.credit.title') %></h2>
+ <%= render picture.full_credit_template, :picture => picture %>
+ </td>
+ <td>
+ <h2>properties</h2>
+ <h2>
+ <%= t_m 'Picture.revision' -%>:<%= picture.revision %>
+ </h2>
+ <div>
+ <%= t_m 'Picture.ext' -%>:<%= picture.ext %>
+ </div>
+ <div>
+ <%= t_m 'Picture.width' -%>:<%= picture.width %> px
+ </div>
+ <div>
+ <%= t_m 'Picture.height' -%>:<%= picture.height %> px
+ </div>
+ <div>
+ <%= t_m 'Picture.filesize' -%>:<%= picture.filesize %>bytes
+ </div>
+ </td>
+ </tr>
+</table>
-この画像は既に改訂されています <%= link_to 'Head', resource_picture_path(picture.resource_picture ) %>
-<div>revision:<%= picture.revision %></div>
+<table>
+ <tr>
+ <td>
+ <%= tag :img, :src => asset_path('error.png'), :width => picture.width, :height => picture.height -%>
+ </td>
+ <td>
+ <h2>
+ <%= t_m 'Picture.revision' -%>:<%= picture.revision %>
+ </h2>
+ <div>
+ <%= t_m 'Picture.ext' -%>:<%= picture.ext %>
+ </div>
+ <div>
+ <%= t_m 'Picture.width' -%>:<%= picture.width %> px
+ </div>
+ <div>
+ <%= t_m 'Picture.height' -%>:<%= picture.height %> px
+ </div>
+ <div>
+ <%= t_m 'Picture.filesize' -%>:<%= picture.filesize %>bytes
+ </div>
+ <div>
+ <%= t_m 'Picture.md5' -%>:<%= picture.md5 %>
+ </div>
+ <div>
+ <%= t_m 'Picture.artist_id' -%>:<%= link_to h(picture.artist.name), artist_path(picture.artist) %>
+ </div>
+ <div>
+ <%= t_m 'Picture.license_id' -%>:<%= link_to h(picture.license.caption), license_path(picture.license) %>
+ </div>
+ <div>
+ <%= t_m 'Picture.artist_name' -%>:<%= h picture.artist_name %>
+ </div>
+ </td>
+ </tr>
+</table>
--- /dev/null
+<h1><%= t '.title' -%></h1>
+<p id="notice"><%= notice %></p>
+
+<%= link_to tag(:img, @picture.opt_img_tag), @picture.url %>
+<p>
+ <b><%= t_m 'Picture.id' -%>:</b>
+ <%= @picture.id %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.original_picture_id' -%>:</b>
+ <%= link_to @picture.original_picture_id, browse_original_picture_path(@picture.original_picture) %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.revision' -%>:</b>
+ <%= @picture.revision %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.ext' -%>:</b>
+ <%= @picture.ext %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.width' -%>:</b>
+ <%= @picture.width %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.height' -%>:</b>
+ <%= @picture.height %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.filesize' -%>:</b>
+ <%= @picture.filesize %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.md5' -%>:</b>
+ <%= @picture.md5 %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.license_id' -%>:</b>
+ <%= link_to @picture.license_id, browse_license_path(@picture.license) %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.artist_id' -%>:</b>
+ <%= link_to @picture.artist_id, browse_artist_path(@picture.artist) %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.artist_name' -%>:</b>
+ <%= h @picture.artist_name %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.classname' -%>:</b>
+ <%= h @picture.classname %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.credit' -%>:</b>
+ <%= h @picture.credit %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.settings' -%>:</b>
+ <%= h @picture.settings %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.created_at' -%>:</b>
+ <%= @picture.created_at %>
+</p>
+
+<p>
+ <b><%= t_m 'Picture.updated_at' -%>:</b>
+ <%= @picture.updated_at %>
+</p>
+
+ %= link_to t('link.back'), :action => :list %>
--- /dev/null
+<h1><%= t '.title' -%></h1>
+
+<table>
+ <tr>
+ <th></th>
+ <th><%= t_m 'Picture.id' -%></th>
+ <th><%= t_m 'Picture.original_picture_id' -%></th>
+ <th><%= t_m 'Picture.revision' -%></th>
+ <th><%= t_m 'Picture.ext' -%></th>
+ <th><%= t_m 'Picture.width' -%></th>
+ <th><%= t_m 'Picture.height' -%></th>
+ <th><%= t_m 'Picture.filesize' -%></th>
+ <th><%= t_m 'Picture.md5' -%></th>
+ <th><%= t_m 'Picture.artist_id' -%></th>
+ <th><%= t_m 'Picture.license_id' -%></th>
+ <th><%= t_m 'Picture.artist_name' -%></th>
+ <th><%= t_m 'Picture.classname' -%></th>
+ <th><%= t_m 'Picture.credit' -%></th>
+ <th><%= t_m 'Picture.settings' -%></th>
+ <th><%= t_m 'Picture.created_at' -%></th>
+ <th><%= t_m 'Picture.updated_at' -%></th>
+ </tr>
+
+<% @pictures.each do |picture| %>
+ <tr>
+ <td><%= link_to tag(:img, picture.tmb_opt_img_tag), picture.url %></td>
+ <td><%= link_to picture.id, browse_picture_path(picture) %></td>
+ <td><%= link_to picture.original_picture_id, browse_original_picture_path(picture.original_picture) %></td>
+ <td><%= picture.revision %></td>
+ <td><%= h picture.ext %></td>
+ <td><%= picture.width %></td>
+ <td><%= picture.height %></td>
+ <td><%= picture.filesize %></td>
+ <td><%= h(truncate(picture.md5, :length => 8)) %></td>
+ <td><%= link_to picture.artist_id, browse_artist_path(picture.artist) %></td>
+ <td><%= link_to picture.license_id, browse_license_path(picture.license) %></td>
+ <td><%= h(truncate(picture.artist_name, :length => 8)) %></td>
+ <td><%= h(truncate(picture.classname, :length => 8)) %></td>
+ <td><%= h(truncate(picture.credit, :length => 8)) %></td>
+ <td><%= h(truncate(picture.settings, :length => 8)) %></td>
+ <td><%= l picture.created_at %></td>
+ <td><%= l picture.updated_at %></td>
+ </tr>
+<% end %>
+</table>
-<% if @picture.head? %>
+<h1><%= t('.title') %></h1>
+<div>
+ <% if @picture.enable? %>
+ <% if @picture.head? %>
+ <p>
+ <%= t 'pictures.show.announce.head' -%>
+ <%= link_to tag(:img, @picture.tmb_opt_img_tag), resource_picture_path(@picture.resource_picture) %>
+ </p>
+ <% else %>
+ <p>
+ <%= t 'pictures.show.announce.tail' -%>
+ <%= link_to tag(:img, @picture.head.tmb_opt_img_tag), resource_picture_path(@picture.head.resource_picture) %>
+ </p>
+ <% end %>
+ <% else %>
+ <p>
+ <%= t 'pictures.show.announce.disable' -%>
+ </p>
+ <% end %>
+ <% if @picture.own? @artist %>
+ <p>
+ <%= t 'pictures.show.announce.owner' -%>
+ <%= link_to tag(:img, @picture.original_picture.tmb_opt_img_tag), original_picture_path(@picture.original_picture) %>
+ </p>
+ <% end %>
+</div>
+
+<% if @picture.showable? @artist %>
<%= render 'head', :picture => @picture %>
<% else %>
<%= render 'tail', :picture => @picture %>
<% end %>
-
</tr>
<tr>
<td>
+ <%= link_to 'pictures', list_pictures_path %>
+ </td>
+ </tr>
+ <tr>
+ <td>
<%= link_to 'resource_pictures', :controller => 'resource_pictures', :action => :list %>
</td>
</tr>
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= link_to tag(:img, :src => @system_picture.url), @system_picture.url %>
+<%= link_to tag(:img, @system_picture.opt_img_tag), @system_picture.url %>
<p>
<b><%= t_m 'SystemPicture.id' -%>:</b>
<%= @system_picture.id %>
<% @system_pictures.each do |system_picture| %>
<tr>
- <td><%= link_to tag(:img, :src => system_picture.url), system_picture.url %>(<%= link_to system_picture.id, system_picture_path(system_picture) %>)</td>
+ <td><%= link_to tag(:img, system_picture.tmb_opt_img_tag), system_picture.url %>(<%= link_to system_picture.id, system_picture_path(system_picture) %>)</td>
<td><%= h system_picture.ext %></td>
<td><%= system_picture.width %>x<%= system_picture.height %></td>
<td><%= system_picture.filesize %></td>
<% @system_pictures.each do |system_picture| %>
<tr>
- <td><%= link_to tag(:img, :src => system_picture.url), system_picture.url %></td>
+ <td><%= link_to tag(:img, system_picture.tmb_opt_img_tag), system_picture.url %></td>
<td><%= link_to system_picture.id, browse_system_picture_path(system_picture) %></td>
<td><%= h system_picture.ext %></td>
<td><%= system_picture.width %></td>
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= link_to tag(:img, :src => @system_picture.url), @system_picture.url %>
+<%= link_to tag(:img, @system_picture.opt_img_tag), @system_picture.url %>
<p>
<b><%= t_m 'SystemPicture.ext' -%>:</b>
browse:
title: 原画 生単票
pictures:
- index:
- title: 実素材一覧
show:
title: 実素材詳細
+ announce:
+ disable: この素材は配布を中止しています。素材として利用できません。
+ head: 素材として利用できます。
+ tail: この画像は既に改訂されています。素材として利用するなら、こちら(最新版)が利用できます。
+ owner: あなたの画像です。原画を管理するなら、こちらを利用してください。
+ md5:
+ title: 実素材MD5検索一覧
+ credit:
+ title: クレジット
list:
title: 実素材 生一覧
browse:
get :count
post :create
get :list
- get :browse
end
member do
put :update
delete :destroy
+ get :browse
end
end
resources :artists do
get :count
post :create
get :list
- get :browse
end
member do
put :update
delete :destroy
+ get :browse
end
end
resources :speech_balloon_templates do
resources :speeches do
collection do
get :list
- get :browse
end
member do
+ get :browse
end
end
resources :balloons do
collection do
get :list
- get :browse
end
member do
+ get :browse
end
end
resources :speech_balloons do
collection do
get :list
- get :browse
end
member do
+ get :browse
end
end
resources :panel_pictures do
get :index
get :show
get :list
- get :browse
end
member do
+ get :browse
end
end
resources :pictures do
collection do
get :show
+ get :credit
get :md5
+ get :list
end
member do
get :credit
+ get :browse
end
end
resources :resource_pictures do
post :create
get :count
get :list
- get :browse
end
member do
+ delete :destroy
get :credit
+ get :browse
end
end
resources :original_pictures do
get :history
post :create
get :list
- get :browse
end
member do
get :edit
put :update
delete :destroy
+ get :browse
end
end
resources :original_picture_license_groups do
get :list
end
member do
+ get :browse
end
end
resources :panel_colors do
get :index
end
member do
+ get :browse
end
end
resources :ground_colors do
get :index
end
member do
+ get :browse
end
end
resources :ground_pictures do
get :index
end
member do
+ get :browse
end
end
resources :panels do
get :count
post :create
get :list
- get :browse
end
member do
put :update
delete :destroy
+ get :browse
end
end
resources :stories do
get :show
post :create
get :list
- get :browse
end
member do
put :update
delete :destroy
+ get :browse
end
end
resources :comics do
get :count
post :create
get :list
- get :browse
end
member do
get :edit
put :update
delete :destroy
+ get :browse
end
end
resources :licenses do
get :index
get :show
get :list
+ end
+ member do
get :browse
end
end
get :index
get :show
get :list
+ end
+ member do
get :browse
+ delete :destroy
end
end
resources :system_pictures do
get :index
assigns(:artist).should eq @artist
end
- it 'ただし、絵師登録されてなければ新規の絵師をセットしている' do
+ it 'ただし、絵師登録されてなければnilをセットしている' do
get :index
- assigns(:artist).should be_a_new(Artist)
+ assigns(:artist).should be_nil
end
end
context 'userがサインインしていないなら' do
=end
end
- describe '新規作成フォーム表示に於いて' do
- before do
- sign_in @user
- sign_in @admin
- end
- context 'つつがなく終わるとき' do
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- get :new
- response.should be_success
- end
- it 'ページテンプレートnewを描画する' do
- get :new
- response.should render_template("new")
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @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 '/admins/sign_in'
- end
- end
- end
- end
-
- describe '新規作成に於いて' do
- before do
- sign_in @admin
- sign_in @user
- @attr = {:system_picture => {:file => "abc\ndef\nghi"}}
- @imager = ImagerTest.load("abc\ndef\nghi")
- end
- context '事前チェックしておく' do
- before do
- PettanImager.stub(:load).with(any_args).and_return(@imager)
- SystemPicture.any_instance.stub(:store).with(@imager).and_return(true)
- end
- it "画像ライブラリをロードしている" do
- PettanImager.should_receive(:load).with(any_args).exactly(1)
- post :create, @attr
- end
- it 'システム画像モデルに保存依頼する' do
- SystemPicture.should_receive(:store).with(@imager).exactly(1)
- post :create, @attr
- end
- end
- context 'つつがなく終わるとき' do
- before do
- PettanImager.stub(:load).with(any_args).and_return(@imager)
- SystemPicture.stub(:store).with(@imager).and_return(@sp)
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, @attr
- response.status.should eq 302
- end
- it '作成されたシステム画像の表示ページへ遷移する' do
- post :create, @attr
- response.should redirect_to(SystemPicture.last)
- end
- end
- context 'json形式' do
- before do
- @attr.merge!({:format => :json})
- end
- it 'ステータスコード200 OKを返す' do
- post :create, @attr
- response.should be_success
- end
- it '作成されたシステム画像をjsonデータで返す' do
- post :create, @attr
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
- it 'システム画像モデルにjson単体出力オプションを問い合わせている' do
- SystemPicture.should_receive(:show_json_opt).exactly(1)
- post :create, @attr
- end
- it 'データがアレになっている' do
- post :create, @attr
- json = JSON.parse response.body
- json["ext"].should match(/png/)
- json["md5"].should be_true
- json["width"].should be_true
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, @attr
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- post :create, @attr
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'json形式' do
- before do
- @attr.merge!({:format => :json})
- end
- it 'ステータスコード401 Unauthorizedを返す' do
- post :create, @attr
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- post :create, @attr
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '検証、保存に失敗した' do
- before do
- SystemPicture.stub(:store).and_return(nil)
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- post :create, @attr
- response.status.should eq 200
- end
- it '新規ページを描画する' do
- post :create, @attr
- response.should render_template("new")
- end
- end
- context 'json形式' do
- before do
- @attr.merge!({:format => :json})
- end
- it 'ステータスコード422 unprocessable_entity を返す' do
- post :create, @attr
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- post :create, @attr
- response.message.should match(/Unprocessable/)
- end
- end
- end
- end
end
end
end
- describe '画像タグオプションに於いて' do
+ describe 'サムネイル画像タグオプションに於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
end
it 'サムネイル画像の幅高さ取得を依頼している' do
PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
- @op.opt_img_tag
+ @op.tmb_opt_img_tag
+ end
+ it '戻り値はHashで返す' do
+ r = @op.tmb_opt_img_tag
+ r.is_a?(Hash).should be_true
+ end
+ it 'srcキーを含んでいる' do
+ r = @op.tmb_opt_img_tag
+ r.has_key?(:src).should be_true
+ r[:src].should eq '/original_pictures/3.gif'
+ end
+ it 'widthキーを含んでいる' do
+ r = @op.tmb_opt_img_tag
+ r.has_key?(:width).should be_true
+ r[:width].should eq 40
+ end
+ it 'heightキーを含んでいる' do
+ r = @op.tmb_opt_img_tag
+ r.has_key?(:height).should be_true
+ r[:height].should eq 30
+ end
+ end
+
+ describe '画像タグオプションに於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
end
it '戻り値はHashで返す' do
r = @op.opt_img_tag
it 'widthキーを含んでいる' do
r = @op.opt_img_tag
r.has_key?(:width).should be_true
- r[:width].should eq 40
+ r[:width].should eq @op.width
end
it 'heightキーを含んでいる' do
r = @op.opt_img_tag
r.has_key?(:height).should be_true
- r[:height].should eq 30
+ r[:height].should eq @op.height
end
end
end
describe 'json一覧出力オプションに於いて' do
before do
- @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
- @sbt = FactoryGirl.create :speech_balloon_template\r
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @sbt = FactoryGirl.create :speech_balloon_template
@comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
@panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
@story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
@op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
@op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
@op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
- OriginalPicture.stub(:default_page_size).and_return(2)\r
+ OriginalPicture.stub(:default_page_size).and_return(2)
end
it '通常は全件(5件)を返す' do
r = OriginalPicture.mylist @artist, 5, 0
end
describe 'json単体出力オプションに於いて' do
before do
- @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
- @sbt = FactoryGirl.create :speech_balloon_template\r
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @sbt = FactoryGirl.create :speech_balloon_template
@comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
@panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
@story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
describe 'デフォルト値補充に於いて' do
it 'defined' do
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
@p.supply_default
end
end
:artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id,
:artist_name => 'tester', :classname => 'Tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}
@rp = FactoryGirl.build :resource_picture, attr
- @p = FactoryGirl.build :picture, :original_picture_id => nil, :license_id => nil, :artist_id => nil, :revision => nil\r
+ @p = FactoryGirl.build :picture, :original_picture_id => nil, :license_id => nil, :artist_id => nil, :revision => nil
end
it 'width, height, ext, filesize, md5, original_picture_idが設定されている' do
@p.overwrite @rp
describe '所持判定に於いて' do
before do
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
end
- it '実素材を更新することはないので、Falseを返す' do
- @p.own?(@author).should == false
+ context 'パラメータが作家のとき' do
+ it '自作の実素材ならyes' do
+ @p.own?(@author).should == true
+ end
+ it '他人のならno' do
+ @p.own?(@other_author).should == false
+ end
+ end
+ context 'パラメータが絵師のとき' do
+ it '自作の実素材ならyes' do
+ @p.own?(@artist).should == true
+ end
+ it '他人のならno' do
+ @p.own?(@other_artist).should == false
+ end
+ end
+ context 'それ以外のとき' do
+ it 'no' do
+ @p.own?(nil).should == false
+ end
end
end
-
describe '閲覧許可に於いて' do
before do
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ end
+ it 'Trueを返す。' do
+ r = @p.visible?(@artist)
+ r.should be_true
+ end
+ end
+
+ describe '詳細閲覧許可に於いて' do
+ before do
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ end
+ it '自作の実素材ならyes' do
+ Picture.any_instance.stub(:own?).with(any_args).and_return(true)
+ @p.showable?(@artist).should == true
+ end
+ context '他人の実素材のとき' do
+ before do
+ Picture.any_instance.stub(:own?).with(any_args).and_return(false)
+ end
+ it '自身にhead判定と有効性判定を問い合わせ、両者がTrueならTrueを返す。' do
+ Picture.any_instance.stub(:head?).with(any_args).and_return(true)
+ Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
+ r = @p.showable?(@artist)
+ r.should be_true
+ end
+ it 'head判定がFalseならFalseを返す。' do
+ Picture.any_instance.stub(:head?).with(any_args).and_return(false)
+ Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
+ r = @p.showable?(@artist)
+ r.should be_false
+ end
+ it '有効性判定がFalseならFalseを返す。' do
+ Picture.any_instance.stub(:enable?).with(any_args).and_return(false)
+ Picture.any_instance.stub(:head?).with(any_args).and_return(true)
+ r = @p.showable?(@artist)
+ r.should be_false
+ end
end
- it '必ず許可となる' do\r
- r = @p.visible?(@author)
- r.should == true
- end\r
end
describe 'ファイル名に於いて' do
before do
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'id+拡張子のフォーマットで返す' do
r = @p.filename
describe 'gifファイル名に於いて' do
before do
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'gif'\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'gif'
end
it 'id.gifのフォーマットで返す' do
r = @p.filename
describe 'MimeTypeに於いて' do
before do
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'image/拡張子のフォーマットで返す' do
r = @p.mime_type
describe 'ファイルのurlに於いて' do
before do
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
Picture.any_instance.stub(:filename).and_return('3.gif')
end
it 'ファイル名取得を依頼している' do
end
end
- describe 'head判定に於いて' do
+ describe '有効性判定に於いて' do
before do
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+ Picture.any_instance.stub(:head).and_return(@p)
end
- context '自身とリンクした素材があるとき' do
+ context 'è\87ªèº«ã\81®headã\81¨ã\83ªã\83³ã\82¯ã\81\97ã\81\9fç´ æ\9d\90ã\81\8cã\81\82ã\82\8bã\81¨ã\81\8d' do
before do
- @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+ Picture.any_instance.stub(:resource_picture).and_return(@rp)
end
it 'trueを返す' do
- res = @p.head?
+ res = @p.enable?
res.should be_true
end
end
- context '自身とリンクした素材がないとき' do
+ context 'è\87ªèº«ã\81®headã\81¨ã\83ªã\83³ã\82¯ã\81\97ã\81\9fç´ æ\9d\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
- @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
- @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 1
+ Picture.any_instance.stub(:resource_picture).and_return(nil)
+ end
+ it 'falseを返す' do
+ res = @p.enable?
+ res.should be_false
+ end
+ end
+ end
+
+ describe 'head取得に於いて' do
+ before do
+ #旧版
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op.id, :md5 => 'a' * 32
+ #最新版
+ @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op.id, :md5 => 'b' * 32
+ #除外すべき無関係画像
+ @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op2.id, :md5 => 'C' * 32
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ #素材は有効
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
end
+ it '最新版を返す' do
+ res = @p.head
+ res.should eq @p2
+ end
+ end
+ context '無効な素材(素材とリンクしてない)とき' do
+ it '同じく最新版を返す' do
+ res = @p.head
+ res.should eq @p2
+ end
+ end
+ end
+
+ describe 'head判定に於いて' do
+ before do
+ #旧版
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op.id, :md5 => 'a' * 32
+ #最新版
+ @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op.id, :md5 => 'b' * 32
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p2.id
+ end
+ context '旧版のとき' do
it 'falseを返す' do
res = @p.head?
res.should be_false
end
end
+ context '最新版のとき' do
+ it 'trueを返す' do
+ res = @p2.head?
+ res.should be_true
+ end
+ end
end
- describe 'フォーマット変換対象判定に於いて' do\r
- before do\r
+ describe 'フォーマット変換対象判定に於いて' do
+ before do
@p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
- end\r
- context '変換するケース' do\r
- it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
- Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
- @p.ext = 'png'\r
- @p.to_gif?.should be_true\r
- end\r
- end\r
- context '変換しないケース' do\r
- it '画像フォーマットがpngでない' do\r
- Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
- @p.ext = 'gif'\r
- @p.to_gif?.should be_false\r
- end\r
- it '変換禁止フラグが無効' do\r
- Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
- @p.ext = 'png'\r
- @p.to_gif?.should be_false\r
- end\r
- end\r
- end\r
- \r
- describe 'サブディレクトリリストに於いて' do\r
- before do\r
+ end
+ context '変換するケース' do
+ it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do
+ Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
+ @p.ext = 'png'
+ @p.to_gif?.should be_true
+ end
+ end
+ context '変換しないケース' do
+ it '画像フォーマットがpngでない' do
+ Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
+ @p.ext = 'gif'
+ @p.to_gif?.should be_false
+ end
+ it '変換禁止フラグが無効' do
+ Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
+ @p.ext = 'png'
+ @p.to_gif?.should be_false
+ end
+ end
+ end
+
+ describe 'サブディレクトリリストに於いて' do
+ before do
@p = FactoryGirl.build :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id
- end\r
- it '配列で返す' do\r
- Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
- r = @p.subdirs\r
- r.is_a?(Array).should be_true\r
- end\r
- it '本画像(ベースディレクトリ)を含んでいる' do\r
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)\r
- r = @p.subdirs\r
- r.include?('').should be_true\r
- end\r
- context '反転が許可されているとき' do\r
- it '垂直・水平・垂直水平反転ディレクトリも返す' do\r
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)\r
- r = @p.subdirs\r
- r.include?('v').should be_true\r
- r.include?('h').should be_true\r
- r.include?('vh').should be_true\r
- end\r
- end\r
- context '反転が許可されていないとき' do\r
- it '本画像(ベースディレクトリ)だけを返す' do\r
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)\r
- r = @p.subdirs\r
- r.size.should eq 1\r
- end\r
- end\r
- end\r
- \r
+ end
+ it '配列で返す' do
+ Picture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
+ r = @p.subdirs
+ r.is_a?(Array).should be_true
+ end
+ it '本画像(ベースディレクトリ)を含んでいる' do
+ Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
+ r = @p.subdirs
+ r.include?('').should be_true
+ end
+ context '反転が許可されているとき' do
+ it '垂直・水平・垂直水平反転ディレクトリも返す' do
+ Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
+ r = @p.subdirs
+ r.include?('v').should be_true
+ r.include?('h').should be_true
+ r.include?('vh').should be_true
+ end
+ end
+ context '反転が許可されていないとき' do
+ it '本画像(ベースディレクトリ)だけを返す' do
+ Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
+ r = @p.subdirs
+ r.size.should eq 1
+ end
+ end
+ end
+
describe 'md5検索に於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
describe '単体取得に於いて' do
before do
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
end
context 'つつがなく終わるとき' do
it '閲覧許可を問い合わせている' do
Picture.any_instance.stub(:save).with(any_args).and_return(true)
Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it '自身を保存している' do
Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
#すべての処理を正常パターンで通過させ、保存機能をチェックする。
Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Trueを返す' do
r = @p.store(@imager)
#すべての処理を正常パターンで通過させ、保存機能をチェックする。
Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Trueを返す' do
r = @p.store(@imager)
context '自身の保存に失敗したとき' do
before do
Picture.any_instance.stub(:save).with(any_args).and_return(false)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Falseを返す' do
r = @p.store(@imager)
context '画像の保存に失敗したとき' do
before do
Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Falseを返す' do
r = @p.store(@imager)
Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
ImagerTest.stub(:load).with(any_args).and_return(false)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Falseを返す' do
r = @p.store(@imager)
Picture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)
Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
Picture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
it 'Falseを返す' do
r = @p.store(@imager)
PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
- @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'\r
+ @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :ext => 'png'
end
context '事前チェック' do
before do