--- /dev/null
+// Place all the styles related to the LicenseGroup controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+// Place all the styles related to the OriginalPictureLicenseGroups controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+// Place all the styles related to the ResourcePictureLicense controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+// Place all the styles related to the StandardLicenses controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@new_comics = Comic.find(:all,
:include => :author, :conditions => ['visible > 0'], :order => 'updated_at desc', :limit => 5
)
- @new_pictures = OriginalPicture.find(:all,
- :include => [:artist, :license, :resource_picture], :order => 'updated_at', :limit => 5
- )
+ @new_pictures = OriginalPicture.list @artist.id
respond_to do |format|
format.html # index.html.erb
--- /dev/null
+class LicenseGroupsController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_admin!, :only => [:list, :browse]
+
+ # GET /license_groups
+ # GET /license_groups.json
+ def index
+ @license_groups = LicenseGroup.list({})
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @license_groups.to_json(LicenseGroup.list_json_opt) }
+ end
+ end
+
+ # GET /license_groups/1
+ # GET /license_groups/1.json
+ def show
+ @license_group = LicenseGroup.show(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @license_group.to_json(LicenseGroup.show_json_include_opt) }
+ end
+ end
+
+ def list
+ @license_groups = LicenseGroup.all
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
+
+ def browse
+ @license_group = LicenseGroup.find(params[:id])
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
+end
class LicensesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
before_filter :authenticate_admin!, :only => [:list, :browse]
# GET /licenses
# GET /licenses.json
def index
- @page = License.page params[:page]
- @page_size = License.page_size params[:page_size]
- @licenses = License.list({}, @page, @page_size)
+ @licenses = License.list({})
respond_to do |format|
format.html # index.html.erb
--- /dev/null
+class OriginalPictureLicenseGroupsController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_user!, :only => [:new, :create]
+ before_filter :authenticate_artist, :only => [:new, :create]
+
+ private
+
+ def authenticate_artist
+ if @author.artist?
+ true
+ else
+ respond_to do |format|
+ format.html { redirect_to new_artist_path, :status => :found }
+ format.js { render "artists/new" }
+ format.json {
+ raise ActiveRecord::Forbidden
+ }
+ end
+ false
+ end
+ end
+
+ public
+
+ # GET /original_picture_license_groups/new
+ # GET /original_picture_license_groups/new.js
+ def new
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new()
+ @original_picture_license_group.supply_default @original_picture.id
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ end
+ end
+
+ # POST /original_picture_license_groups
+ # POST /original_picture_license_groups.js
+ def create
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @ctl = @license_group.classname.tableize
+
+ respond_to do |format|
+ if @original_picture_license_group.valid?
+ format.html { render :template => "#{@ctl}/new" }
+ format.js { render :template => "#{@ctl}/new" }
+ else
+ format.html { render action: "new" }
+ format.js { render action: "new" }
+ end
+ end
+ end
+
+end
class OriginalPicturesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
before_filter :authenticate_user!, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
before_filter :authenticate_admin!, :only => [:list, :browse]
before_filter :authenticate_artist, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
# GET /original_pictures/1.json
def show
@original_picture = OriginalPicture.show(params[:id], @artist)
-
+
respond_to do |format|
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.html {
+ #ライセンス付与のために原画ライセンスグループ作成準備
+ @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @original_picture.id
+ render
+ }
format.json { render json: @original_picture.to_json(OriginalPicture.show_json_include_opt)}
end
end
@original_picture.supply_default @artist
respond_to do |format|
- if @original_picture.store(@picture_data, @artist, params[:original_picture][:license_id])
+ if @original_picture.store(@picture_data, @artist)
format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' }
format.json { render json: @original_picture, status: :created, location: @original_picture }
else
@original_picture.supply_default @artist
respond_to do |format|
- if @original_picture.store(@picture_data, @artist, params[:original_picture][:license_id])
+ if @original_picture.store(@picture_data, @artist)
format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' }
format.json { render json: @original_picture, status: :created, location: @original_picture }
else
class PanelPicturesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
before_filter :authenticate_user!, :only => [:index, :show]
before_filter :authenticate_admin!, :only => [:list, :browse]
--- /dev/null
+class PicturesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ def credit
+ @picture = Picture.show(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @picture.to_json(Picture.list_json_opt)}
+ end
+ end
+
+end
--- /dev/null
+class ResourcePictureLicenseController < ApplicationController
+end
class ResourcePicturesController < ApplicationController
- before_filter :authenticate_user!, :only => [:index, :show]
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :update]
before_filter :authenticate_admin!, :only => [:list, :browse]
# GET /resource_pictures
format.json { render :json => @resource_picture.to_json(ResourcePicture.list_json_opt)}
end
end
+
+ def credit
+ @resource_picture = ResourcePicture.show(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @resource_picture.to_json(ResourcePicture.list_json_opt)}
+ end
+ end
+
+ def new
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @resource_picture = @original_picture.resource_picture || ResourcePicture.new(params[:resource_picture])
+ @license = @resource_picture.license
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ end
+ end
+
+ def create
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @resource_picture = ResourcePicture.new(params[:resource_picture])
+ @license = @resource_picture.license
+ respond_to do |format|
+ if @resource_picture.store
+ format.html { redirect_to @resource_picture }
+ format.js { render json: @resource_picture, status: :created, location: @resource_picture }
+ else
+ format.html { render action: "new" }
+ format.js { render action: "new" }
+ end
+ end
+ end
+
+ def update
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @resource_picture = @original_picture.resource_picture
+ @resource_picture.attributes = params[:resource_picture]
+ @license = @resource_picture.license
+
+ respond_to do |format|
+ if @resource_picture.store
+ format.html { redirect_to @resource_picture }
+ format.js { render json: @resource_picture, status: :created, location: @resource_picture }
+ else
+ format.html { render action: "new" }
+ format.js { render action: "new" }
+ end
+ end
+ end
+
def count
@resource_picture = {:count => ResourcePicture.visible_count}
respond_to do |format|
--- /dev/null
+class StandardLicensesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_user!, :only => [:new, :create]
+ before_filter :authenticate_artist, :only => [:new, :create]
+
+ private
+
+ def authenticate_artist
+ if @author.artist?
+ true
+ else
+ respond_to do |format|
+ format.html { redirect_to new_artist_path, :status => :found }
+ format.js { render "artists/new" }
+ format.json {
+ raise ActiveRecord::Forbidden
+ }
+ end
+ false
+ end
+ end
+
+ public
+
+ # GET /standard_licenses/new
+ # GET /standard_licenses/new.js
+ def new
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new(params[:original_picture_license_group])
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @standard_license = StandardLicense.new
+ @standard_license.supply_default @artist
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ end
+ end
+
+ # POST /standard_licenses
+ # POST /standard_licenses.js
+ def create
+ @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+ @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+ @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+ @standard_license = StandardLicense.new params[:standard_license]
+ @license = License.show @standard_license.license_id
+ @resource_picture = @original_picture.resource_picture || ResourcePicture.new
+ @resource_picture.attributes = {
+ :original_picture_id => @original_picture.id, :license_id => @license.id,
+ :artist_name => @standard_license.artist_name, :classname => @license_group.classname,
+ :credit => @standard_license.credit, :settings => @license.settings
+ }
+ respond_to do |format|
+ if @standard_license.valid?
+ format.html { render :template => "resource_pictures/new" }
+ format.js { render :template => "resource_pictures/new" }
+ else
+ format.html { render action: "new" }
+ format.js { render action: "new" }
+ end
+ end
+ end
+
+end
--- /dev/null
+module LicenseGroupsHelper
+end
--- /dev/null
+module OriginalPictureLicenseGroupsHelper
+end
--- /dev/null
+module PicturesHelper
+end
--- /dev/null
+module ResourcePictureLicenseHelper
+end
--- /dev/null
+module StandardLicensesHelper
+end
+#
class License < ActiveRecord::Base
- has_one :original_license
- has_one :common_license
+ belongs_to :license_group
+ belongs_to :system_picture
+
+ validates :license_group_id, :presence => true, :numericality => true, :existence => true
validates :name, :presence => true, :length => {:maximum => 50}
- validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:allow_blank => true}
+ validates :caption, :presence => true, :length => {:maximum => 30}
+ validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => true #{:allow_blank => true}
+ validates :system_picture_id, :presence => true, :numericality => true, :existence => true
- def self.update_license cl
- l = License.find_by_url cl.url
- l = License.new unless l
- l.attributes = {
- :name => cl.name, :url => cl.url, :cc_by => cl.cc_by, :cc_sa => cl.cc_sa, :cc_nd => cl.cc_nd, :cc_nc => cl.cc_nc,
- :no_resize => cl.no_resize, :no_flip => cl.no_flip, :no_convert => cl.no_convert, :keep_aspect_ratio => cl.keep_aspect_ratio
- }
- if cl.new_record? and l.new_record? == false
- l.errors.add :base, 'dupulicate url'
+ def self.store name, attr
+ r = License.replace_system_picture attr
+ l = License.modify_object name, attr
+ if r == false
+ l.errors.add :base, 'system picture can not create'
+ else
+ l.save
end
l
end
- def self.default_page_size
- 25
- end
-
- def self.max_page_size
- 100
- end
-
- def self.page prm = nil
- page = prm.to_i
- page = 1 if page < 1
- page
- end
-
- def self.page_size prm = self.default_page_size
- page_size = prm.to_i
- page_size = self.max_page_size if page_size > self.max_page_size
- page_size = self.default_page_size if page_size < 1
- page_size
- end
-
- def self.offset cnt, prm = nil
- offset = prm.to_i
- offset = cnt - 1 if offset >= cnt
- offset = cnt - offset.abs if offset < 0
- offset = 0 if offset < 0
- offset
+ def self.stores attrs, lg_id
+ res = 0
+ return 0 unless attrs.is_a?(Hash)
+ attrs.each do |name, attr|
+ attr["license_group_id"] = lg_id
+ l = License.store name, attr
+ res += 1 unless l.valid?
+ end
+ res
end
- def self.list opt = {}, page = 1, page_size = self.default_page_size
+ def self.list opt = {}
opt.merge!(self.list_opt) unless opt[:include]
- opt.merge!({:order => 'name', :limit => page_size, :offset => (page -1) * page_size})
+ opt.merge!({:order => 'name'})
License.find(:all, opt)
end
def self.list_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
def self.list_json_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
def self.show rid, opt = {}
end
def self.show_include_opt opt = {}
- res = [:common_license, :original_license]
+ res = [:license_group]
res.push(opt[:include]) if opt[:include]
res
end
def self.show_json_include_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
end
--- /dev/null
+#ライセンスグループ
+class LicenseGroup < ActiveRecord::Base
+ has_many :licenses
+
+ validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
+ validates :classname, :presence => true, :length => {:maximum => 50}
+ validates :caption, :presence => true, :length => {:maximum => 30}
+ validates :url, :presence => true, :length => {:maximum => 200}, :url => true
+
+ def self.store name, attr
+ #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく
+ lattr = attr["licenses_attributes"]
+ attr.delete "licenses_attributes"
+ #ライセンスグループを先に保存してidを決める
+ r = LicenseGroup.modify_object name, attr
+ r.save
+ #取っておいたライセンスデータとidでライセンス作成
+ if (c = License.stores(lattr, r.id)) > 0
+ r.errors.add :base, 'licenses can not create'
+ end
+ r
+ end
+
+ def self.import filename
+ LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
+ end
+
+ def self.list opt = {}
+ opt.merge!(self.list_opt) unless opt[:include]
+ opt.merge!({:order => 'license_groups.name asc'})
+ LicenseGroup.find(:all, opt)
+ end
+
+ def self.list_opt
+ {:include => {:licenses => {}}}
+ end
+
+ def self.list_json_opt
+ {:include => {:licenses => {}}}
+ end
+
+ def self.show rid, opt = {}
+ r = LicenseGroup.find(rid, :include => self.show_include_opt(opt))
+# raise ActiveRecord::Forbidden unless c.visible?(au)
+ r
+ end
+
+ def self.show_include_opt opt = {}
+ res = {:licenses => {}}
+ res.push(opt[:include]) if opt[:include]
+ res
+ end
+
+ def self.show_json_include_opt
+ {:include => {:licenses => {}}}
+ end
+
+end
class OriginalPicture < ActiveRecord::Base
belongs_to :artist
- belongs_to :license
has_one :resource_picture
validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}\r
validates :height, :presence => true, :numericality => true, :natural_number => true
validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
validates :artist_id, :presence => true, :numericality => true, :existence => true
- validates :license_id, :presence => true, :numericality => true, :existence => true
before_destroy :destroy_with_file
def supply_default art
- self.license_id = art.default_license_id if self.license_id.blank?
end
def self.default_page_size
end
def self.list_opt
- {:include => [:license, :resource_picture]}
+ {:include => {:resource_picture => {}}}
end
def self.list_json_opt
- {:include => [:license, :resource_picture]}
+ {:include => {:resource_picture => {}}}
end
def self.show cid, artist, opt = {}
end
def self.show_include_opt opt = {}
- res = [:license, :resource_picture]
- res.push(opt[:include]) if opt[:include]
+ res = {:resource_picture => {}}
+ res.merge!(opt[:include]) if opt[:include]
res
end
def self.show_json_include_opt
- {:include => [:license, :resource_picture]}
+ {:include => {:resource_picture => {}}}
end
def destroy_with_file
mgk
end
- def store(picture_data, art, lid = nil)
+ def store(picture_data, art)
mgk = data_to_mgk picture_data
return false unless mgk
res = false
self.attributes = {:ext => mgk.format.downcase, :width => mgk.columns, :height => mgk.rows,
- :filesize => mgk.filesize, :artist_id => art.id,
- :license_id => lid.blank? ? art.default_license_id : lid.to_i
+ :filesize => mgk.filesize, :artist_id => art.id
}
OriginalPicture.transaction do
if res = self.save
if res = PictureIO.original_picture_io.put(picture_data, self.filename)
- rp = ResourcePicture.update_picture(self)
- unless rp.store(mgk)
- res = false
- PictureIO.original_picture_io.delete(self.filename)
- self.errors.add :base, 'resource picture copying error'
- raise ActiveRecord::Rollback
- end
res = true
else
self.errors.add :base, 'original picture io does not work'
--- /dev/null
+class OriginalPictureLicenseGroup < ActiveRecord::Base
+ belongs_to :original_picture
+ belongs_to :license_group
+
+ validates :original_picture_id, :presence => true, :numericality => true, :existence => true
+ validates :license_group_id, :presence => true, :numericality => true, :existence => true
+
+ def supply_default oid
+ self.original_picture_id = oid
+ end
+
+end
belongs_to :resource_picture
validates :panel_id, :numericality => {:allow_blank => true}
- validates :resource_picture_id, :presence => true, :numericality => true, :existence => true
validates :link, :length => {:maximum => 200}
validates :x, :presence => true, :numericality => true
validates :y, :presence => true, :numericality => true
--- /dev/null
+#実素材
+class Picture < ActiveRecord::Base
+ belongs_to :original_picture
+ belongs_to :license
+ belongs_to :artist
+ has_one :resource_picture
+
+ validates :original_picture_id, :presence => true, :numericality => true, :existence => true
+ validates :revision, :presence => true, :numericality => true
+ validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
+ validates :width, :presence => true, :numericality => true, :natural_number => true
+ validates :height, :presence => true, :numericality => true, :natural_number => true
+ validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
+ validates :license_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_name, :presence => true
+ validates :classname, :presence => true, :length => {:maximum => 50}
+
+ def dext
+ self.ext.downcase
+ end
+
+ def filename
+ "#{self.id}.#{self.dext}"
+ end
+
+ def mime_type
+ "image/#{self.dext}"
+ end
+
+ def new_revision
+ Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
+ end
+
+ def v(rimg)
+ rimg.flip.to_blob
+ end
+
+ def h(rimg)
+ rimg.flop.to_blob
+ end
+
+ def vh(rimg)
+ rimg.flip.flop.to_blob
+ end
+
+ def to_gif?
+ self.dext == 'png' and self.flag_gif_convert >= 0
+ end
+
+ def self.png_to_gif(data)
+ res = nil
+ begin
+ mgk = Magick::Image.from_blob(data).shift
+ mgk.format = 'gif'
+ res = mgk
+ rescue
+ res = false
+ end
+ res
+ end
+
+ def subdirs
+ flag_reverse < 0 ? [''] : ['', 'v', 'h', 'vh']
+ end
+
+ def copy_data(rp)
+ attr = {:width => rp.width, :height => rp.height, :ext => rp.ext, :filesize => rp.filesize,
+ :original_picture_id => rp.original_picture_id, :license_id => rp.license_id, :artist_id => rp.artist_id,
+ :artist_name => rp.artist_name, :classname => rp.classname, :credit => rp.credit, :settings => rp.settings
+ }
+ self.attributes = attr
+ end
+
+ def store(mgk)
+ res = false
+ self.revision = self.new_revision
+ if res = self.save
+ if res = self.store_picture(mgk)
+ if self.to_gif?
+ if gifmgk = Picture.png_to_gif(mgk.to_blob)
+ res = self.store_picture(gifmgk)
+ else
+ res = false
+ end
+ end
+ end
+ end
+ res
+ end
+
+ def store_picture(mgk)
+ res = false
+ subdirs.each do |d|
+ picdata = d.empty? ? mgk.to_blob : self.__send__(d, mgk)
+ res = PictureIO.picture_io.put(picdata, "#{self.id}.#{mgk.format}", d)
+ break unless res
+ end
+ res
+ end
+
+ def restore(subdir = nil)
+ PictureIO.resource_picture_io.get self.filename, subdir
+ end
+
+ def credit_template
+ "#{self.classname.tableize}/credit"
+ end
+
+ def credit_data
+ begin
+ @credit_data = JSON.parse(self.credit) unless @credit_data
+ rescue
+ end
+ @credit_data
+ end
+
+ def flags
+ begin
+ @flags = JSON.parse(self.settings) unless @flags
+ rescue
+ end
+ @flags
+ end
+
+ def flags=(s)
+ @flags = s
+ end
+
+ def flag_open
+ @flag_open = flags["open"] unless @flag_open
+ @flag_open
+ end
+
+ def flag_commercial
+ @flag_commercial = flags["commercial"] unless @flag_commercial
+ @flag_commercial
+ end
+
+ def flag_official
+ @flag_official = flags["official"] unless @flag_official
+ @flag_official
+ end
+
+ def flag_attribution
+ @flag_attribution = flags["attribution"] unless @flag_attribution
+ @flag_attribution
+ end
+
+ def flag_derive
+ @flag_derive = flags["derive"] unless @flag_derive
+ @flag_derive
+ end
+
+ def flag_thumbnail
+ @flag_thumbnail = flags["thumbnail"] unless @flag_thumbnail
+ @flag_thumbnail
+ end
+
+ def flag_gif_convert
+ @flag_gif_convert = flags["gif_convert"] unless @flag_gif_convert
+ @flag_gif_convert
+ end
+
+ def flag_reverse
+ @flag_reverse = flags["reverse"] unless @flag_reverse
+ @flag_reverse
+ end
+
+ def flag_resize
+ @flag_resize = flags["resize"] unless @flag_resize
+ @flag_resize
+ end
+
+ def flag_sync_vh
+ @flag_sync_vh = flags["sync_vh"] unless @flag_sync_vh
+ @flag_sync_vh
+ end
+
+ def flag_overlap
+ @flag_overlap = flags["overlap"] unless @flag_overlap
+ @flag_overlap
+ end
+
+end
+#素材
class ResourcePicture < ActiveRecord::Base
belongs_to :artist
belongs_to :license
+ belongs_to :picture
has_many :panel_pictures
belongs_to :original_picture
- validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}\r
+ validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
validates :artist_id, :presence => true, :numericality => true, :existence => true
validates :license_id, :presence => true, :numericality => true, :existence => true
validates :original_picture_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_name, :presence => true
+ validates :classname, :presence => true, :length => {:maximum => 50}
+ validates :picture_id, :presence => true, :numericality => true, :existence => true
before_destroy :destroy_with_file
"image/#{self.dext}"
end
- def v(rimg)
- rimg.flip.to_blob
- end
-
- def h(rimg)
- rimg.flop.to_blob
- end
-
- def vh(rimg)
- rimg.flip.flop.to_blob
- end
-
def url subdir = nil
'/resource_pictures/' + (subdir.to_s.empty? ? '' : subdir.to_s + '/' ) + filename
end
ResourcePicture.resize(rimg.to_blob, tw, th).to_blob
end
- def self.update_picture(op)
- res = op.resource_picture || ResourcePicture.new
- res.attributes = {:width => op.width, :height => op.height, :ext => op.ext, :filesize => op.filesize,
- :original_picture_id => op.id, :artist_id => op.artist_id, :license_id => op.license_id
+ def copy_data(op)
+ attr = {:width => op.width, :height => op.height, :ext => op.ext, :filesize => op.filesize,
+ :original_picture_id => op.id, :artist_id => op.artist_id
}
- res
+ self.attributes = attr
+ end
+
+ def data_to_mgk picture_data
+ begin
+ mgk = Magick::Image.from_blob(picture_data).shift
+ rescue
+ self.errors.add :base, 'magick failed'
+ return false
+ end
+ mgk
+ end
+
+ def op_mgk
+ d = self.original_picture.restore
+ return false unless d
+ self.data_to_mgk d
+ end
+
+ def new_picture mgk
+ pc = Picture.new
+ pc.copy_data self
+ pc.store mgk
+ pc
end
+
def to_gif?
- self.dext == 'png' and self.license.no_convert == 0
+ self.dext == 'png' and self.flag_gif_convert >= 0
end
def self.png_to_gif(data)
res
end
- def store(mgk)
+ def store
res = false
- if res = self.save
- if res = self.store_picture(mgk)
- if self.to_gif?
- if gifmgk = ResourcePicture.png_to_gif(mgk.to_blob)
- res = self.store_picture(gifmgk)
- else
- res = false
- end
+ self.copy_data self.original_picture
+ mgk = self.op_mgk
+ return false unless mgk
+ OriginalPicture.transaction do
+ pc = self.new_picture mgk
+ if res = pc.valid?
+ self.picture_id = pc.id
+ if res = self.save
+ res = self.store_picture_with_gif(mgk)
end
+ else
+ self.errors.add :base, 'picture does not create'
end
+ raise ActiveRecord::Rollback unless res
end
res
end
- def store_picture(mgk)
- res = false
- PictureIO.resource_picture_io.class.subdirs.each do |d|
- picdata = d.empty? ? mgk.to_blob : self.__send__(d, mgk)
- res = PictureIO.resource_picture_io.put(picdata, "#{self.id}.#{mgk.format}", d)
- break unless res
+ def store_picture_with_gif(mgk)
+ if res = self.store_picture(mgk)
+ if self.to_gif?
+ if gifmgk = ResourcePicture.png_to_gif(mgk.to_blob)
+ res = self.store_picture(gifmgk)
+ else
+ self.errors.add :base, 'picture data can not conv to gif'
+ res = false
+ end
+ end
+ else
+ self.errors.add :base, 'resource picture io does not work'
end
res
end
+ def store_picture(mgk)
+ res = false
+ tdata = self.flag_thumbnail >= 0 ? thumbnail(mgk) : mgk.to_blob
+ fdata = mgk.to_blob
+ return false unless PictureIO.resource_picture_io.put(tdata, "#{self.id}.#{mgk.format}")
+ PictureIO.resource_picture_io.put(fdata, "#{self.id}.#{mgk.format}", 'full')
+ end
+
def restore(subdir = nil)
PictureIO.resource_picture_io.get self.filename, subdir
end
ResourcePicture.count
end
+ def credit_template
+ "#{self.classname.tableize}/credit"
+ end
+
+ def credit_data
+ begin
+ @credit_data = JSON.parse(self.credit) unless @credit_data
+ rescue
+ end
+ @credit_data
+ end
+
+ def flags
+ begin
+ @flags = JSON.parse(self.settings) unless @flags
+ rescue
+ end
+ @flags
+ end
+
+ def flags=(s)
+ @flags = s
+ end
+
+ def flag_open
+ @flag_open = flags["open"] unless @flag_open
+ @flag_open
+ end
+
+ def flag_commercial
+ @flag_commercial = flags["commercial"] unless @flag_commercial
+ @flag_commercial
+ end
+
+ def flag_official
+ @flag_official = flags["official"] unless @flag_official
+ @flag_official
+ end
+
+ def flag_attribution
+ @flag_attribution = flags["attribution"] unless @flag_attribution
+ @flag_attribution
+ end
+
+ def flag_derive
+ @flag_derive = flags["derive"] unless @flag_derive
+ @flag_derive
+ end
+
+ def flag_thumbnail
+ @flag_thumbnail = flags["thumbnail"] unless @flag_thumbnail
+ @flag_thumbnail
+ end
+
+ def flag_gif_convert
+ @flag_gif_convert = flags["gif_convert"] unless @flag_gif_convert
+ @flag_gif_convert
+ end
+
+ def flag_reverse
+ @flag_reverse = flags["reverse"] unless @flag_reverse
+ @flag_reverse
+ end
+
+ def flag_resize
+ @flag_resize = flags["resize"] unless @flag_resize
+ @flag_resize
+ end
+
+ def flag_sync_vh
+ @flag_sync_vh = flags["sync_vh"] unless @flag_sync_vh
+ @flag_sync_vh
+ end
+
+ def flag_overlap
+ @flag_overlap = flags["overlap"] unless @flag_overlap
+ @flag_overlap
+ end
+
end
--- /dev/null
+class ResourcePictureLicense < ActiveRecord::Base
+end
--- /dev/null
+class StandardLicense < ActiveRecord::Base
+ belongs_to :license
+
+ validates :license_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_name, :presence => true
+
+ def supply_default ar
+ self.artist_name = ar.name
+ end
+
+ def credit
+ {
+ :system_picture_id => self.license.system_picture_id
+ }.to_json.to_s
+ end
+
+end
class SystemPicture < ActiveRecord::Base
has_many :balloons
has_many :balloon_templates
+ has_many :licenses
validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
validates :width, :presence => true, :numericality => true, :natural_number => true
--- /dev/null
+<div>
+<p>
+<div>id</div>
+<%= @license_group.id %>
+</p>
+<p>
+<%= h @license_group.name %>
+</p>
+<p>
+<div>name</div>
+<%= h @license_group.name %>
+</p>
+<p>
+<div>classname</div>
+<%= h @license_group.classname %>
+</p>
+<p>
+<div>caption</div>
+<%= h @license_group.caption %>
+</p>
+<p>
+<div>url</div>
+<%= h @license_group.url %>
+</p>
+<p>
+<%= @license_group.created_at %>
+</p>
+<p>
+<%= @license_group.updated_at %>
+</p>
+</div>
+<h1>Listing licenses</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>license_group_id</th>
+ <th>name</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
+ <th>created_at</th>
+ <th>updated_at</th>
+ </tr>
+
+<% @license_group.licenses.each do |license| %>
+ <tr>
+ <td><%= link_to license.id, :action => :browse, :id => license.id %></td>
+ <td><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %></td>
+ <td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
+ <td><%= h license.url %></td>
+ <td><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %></td>
+ <td><%= h license.settings %></td>
+ <td><%= license.created_at %></td>
+ <td><%= license.updated_at %></td>
+ </tr>
+<% end -%>
+</table>
+
+<%= link_to 'Back', :action => :list %>
--- /dev/null
+<h1>Listing license Groups</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>name</th>
+ <th>caption</th>
+ </tr>
+
+<% @license_groups.each do |lg| %>
+ <tr>
+ <td><%= link_to lg.id, license_group_path(lg) %></td>
+ <td><%= h lg.name %></td>
+ <td><%= content_tag(:a, h(lg.caption), :href => lg.url) %></td>
+ </tr>
+<% end -%>
+</table>
--- /dev/null
+<h1>Listing license Groups</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>name</th>
+ <th>classname</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>created_at</th>
+ <th>updated_at</th>
+ </tr>
+
+<% @license_groups.each do |lg| %>
+ <tr>
+ <td><%= link_to lg.id, :action => :browse, :id => lg.id %></td>
+ <td><%= h lg.name %></td>
+ <td><%= h lg.classname %></td>
+ <td><%= h lg.caption %></td>
+ <td><%= h lg.url %></td>
+ <td><%= lg.created_at %></td>
+ <td><%= lg.updated_at %></td>
+ </tr>
+<% end -%>
+</table>
--- /dev/null
+<p id="notice"><%= notice %></p>
+
+<p>
+<%= h @license_group.name %>
+</p>
+<p>
+<%= h @license_group.classname %>
+</p>
+<p>
+<%= h @license_group.caption %>
+</p>
+<p>
+<%= h @license_group.url %>
+</p>
+<p>
+<%= @license_group.created_at %>
+</p>
+<p>
+<%= @license_group.updated_at %>
+</p>
+
+<%= link_to 'Back', license_groups_path %>
+ <th>license_group_id</th>
+ <th>name</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
<div>
-<% if @license.common_license -%>
- <%= link_to 'to common_licenses', :controller => 'common_licenses', :action => :browse, :id => @license.common_license.id %>
-<% else -%>
- <%= link_to 'to original_licenses', :controller => 'original_licenses', :action => :browse, :id => @license.original_license.id %>
-<% end -%>
+<p>
+<div>id</div>
+<%= @license.id %>
+</p>
+<p>
+<div>license_group_id</div>
+<%= h @license.license_group_id %>
+</p>
+<p>
+<div>name</div>
+<%= h @license.name %>
+</p>
+<p>
+<div>caption</div>
+<%= h @license.caption %>
+</p>
+<p>
+<div>url</div>
+<%= h @license.url %>
+</p>
+<div>system_picture_id</div>
+<%= @license.system_picture_id %>
+</p>
+<div>settings</div>
+<%= h @license.settings %>
+</p>
+<p>
+<%= @license.created_at %>
+</p>
+<p>
+<%= @license.updated_at %>
+</p>
</div>
<%= link_to 'Back', :action => :list %>
<table>
<tr>
<th>name</th>
+ <th>caption</th>
<th>url</th>
- <th>cc_by</th>
- <th>cc_sa</th>
- <th>cc_nd</th>
- <th>cc_nc</th>
- <th>no_resize</th>
- <th>no_flip</th>
- <th>no_convert</th>
- <th>keep_aspect_ratio</th>
+ <th>created_at</th>
+ <th>updated_at</th>
<th></th>
</tr>
<% @licenses.each do |license| %>
<tr>
<td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
<td><%= h license.url %></td>
- <td><%= license.cc_by %></td>
- <td><%= license.cc_sa %></td>
- <td><%= license.cc_nd %></td>
- <td><%= license.cc_nc %></td>
- <td><%= license.no_resize %></td>
- <td><%= license.no_flip %></td>
- <td><%= license.no_convert %></td>
- <td><%= license.keep_aspect_ratio %></td>
- <td>
- <% if license.common_license -%>
- <%= link_to 'Show', license.common_license %>
- <% else -%>
- <%= link_to 'Show', license.original_license %>
- <% end -%>
- </td>
+ <td><%= license.created_at %></td>
+ <td><%= license.updated_at %></td>
</tr>
<% end -%>
</table>
-<%= link_to 'new original license', new_original_license_path %>
<table>
<tr>
<th>id</th>
+ <th>license_group_id</th>
<th>name</th>
+ <th>caption</th>
<th>url</th>
- <th>cc_by</th>
- <th>cc_sa</th>
- <th>cc_nd</th>
- <th>cc_nc</th>
- <th>no_resize</th>
- <th>no_flip</th>
- <th>no_convert</th>
- <th>keep_aspect_ratio</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
<th>created_at</th>
<th>updated_at</th>
- <th></th>
</tr>
<% @licenses.each do |license| %>
<tr>
<td><%= link_to license.id, :action => :browse, :id => license.id %></td>
+ <td><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %></td>
<td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
<td><%= h license.url %></td>
- <td><%= license.cc_by %></td>
- <td><%= license.cc_sa %></td>
- <td><%= license.cc_nd %></td>
- <td><%= license.cc_nc %></td>
- <td><%= license.no_resize %></td>
- <td><%= license.no_flip %></td>
- <td><%= license.no_convert %></td>
- <td><%= license.keep_aspect_ratio %></td>
+ <td><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %></td>
+ <td><%= h license.settings %></td>
<td><%= license.created_at %></td>
<td><%= license.updated_at %></td>
</tr>
--- /dev/null
+<%= form_for(@original_picture_license_group) do |f| %>
+ <% if @original_picture_license_group.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@original_picture_license_group.errors.count, "error") %> prohibited this comic from being saved:</h2>
+
+ <ul>
+ <% @original_picture_license_group.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :license_group_id %><br />
+ <%= f.collection_select :license_group_id, LicenseGroup.list.map {|l| [l.name, l.id] }, :last, :first %>
+ <%= f.hidden_field :original_picture_id %>
+ </div>
+ <%= hidden_field_tag :original_picture_id, @original_picture.id %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
--- /dev/null
+<%= render 'form' %>
--- /dev/null
+$("#oplg").html("<%= escape_javascript(render('form')) -%>");
<% if @author.artist? -%>
<%= form_tag( {:controller => 'original_pictures',:action => "create"} , { :multipart => true }) do %>
<label for="file">File to Upload</label> <%= file_field_tag "original_picture[file]" %>
- license
- <%= collection_select :original_picture, :license_id, License.all.map {|l| [l.name, l.id] }, :last, :first, :html => {:selected => @author.artist.default_license_id} %>
<%= submit_tag 'upload' -%>
<% end -%>
<% else -%>
<%= @original_picture.artist_id %>
</p>
-<p>
- <b>license_id:</b>
- <%= @original_picture.license_id %>
-</p>
-
<img src="<%= @original_picture.url -%>">
<p>
<h1>Listing original_pictures</h1>
<%= render 'uploader' %>
+<table>
+ <tr>
+ <th>picture</th>
+ <th>filename</th>
+ <th>Width</th>
+ <th>Height</th>
+ <th>filesize</th>
+ </tr>
<% @original_pictures.each do |original_picture| %>
<div>
- <%= original_picture.filename %>
- <img src="<%= original_picture.resource_picture.url('thumbnail') -%>">
- <%= original_picture.width %>x<%= original_picture.height %>
- <%= original_picture.filesize %>bytes
- 画:<%= h original_picture.artist.name %>
- license:<%= h License.find(original_picture.license_id || 1).name %>
</div>
+ <tr>
+ <td>
+ <%= link_to tag(:img, :src => original_picture.url, :width => 50, :height => 50), original_picture %>
+ </td>
+ <td><%= original_picture.filename %></td>
+ <td><%= original_picture.width %></td>
+ <td><%= original_picture.height %></td>
+ <td><%= original_picture.filesize %></td>
+ </tr>
<% end %>
+</table>
<%= link_to 'open form', new_original_picture_path, :remote => true %>
<div id="uploader">
uploader
<th>Height</th>
<th>filesize</th>
<th>artist</th>
- <th>license_id</th>
<th>created_at</th>
<th>updated_at</th>
<th></th>
<td><%= original_picture.height %></td>
<td><%= original_picture.filesize %></td>
<td><%= link_to original_picture.artist_id, :controller => 'artists', :action => :browse, :id => original_picture.artist_id %></td>
- <td><%= link_to original_picture.license_id, :controller => 'licenses', :action => :browse, :id => original_picture.license_id %></td>
<td><%= original_picture.created_at %></td>
<td><%= original_picture.updated_at %></td>
<td>
<a href="<%= @original_picture.url %>">browse picture</a>
</p>
<p>
-<%= link_to '再生成', :action => :refresh, :id => @original_picture.id %>
+Select License
</p>
-<% if @original_picture.own? @author -%>
+<div>
+ <%= render 'original_picture_license_groups/form' %>
+</div>
<p>
Replace picture
</p>
- <%= form_for(@original_picture, :html => { :multipart => true }) do |f| %>
- <label for="file">File to Upload</label> <%= f.file_field "file" %>
- <div class="actions">
- <%= f.submit 'replace' %>
- </div>
- <% end %>
-<% end -%>
+<%= form_for(@original_picture, :html => { :multipart => true }) do |f| %>
+ <label for="file">File to Upload</label> <%= f.file_field "file" %>
+ <div class="actions">
+ <%= f.submit 'replace' %>
+ </div>
+<% end %>
<%= link_to 'Back', original_pictures_path %>
--- /dev/null
+<%= render @picture.credit_template %>
--- /dev/null
+<%= form_for(@resource_picture) do |f| %>
+
+ <%= hidden_field_tag :original_picture_id, @original_picture.id %>
+
+ <%= hidden_field_tag 'original_picture_license_group[original_picture_id]', @original_picture_license_group.original_picture_id %>
+ <%= hidden_field_tag 'original_picture_license_group[license_group_id]', @original_picture_license_group.license_group_id %>
+
+ <%= f.hidden_field :original_picture_id %>
+ <%= f.hidden_field :license_id %>
+ <%= f.hidden_field :artist_name %>
+ <%= f.hidden_field :classname %>
+ <%= f.hidden_field :credit %>
+ <%= f.hidden_field :settings %>
+
+ <div>
+ <%= link_to h(@license_group.caption), license_group_path(@license_group) %>
+ <%= link_to h(@license.caption), license_path(@license) %>
+ </div>
+ <div>
+ artist name:<%= @resource_picture.artist_name %>
+ </div>
+
+ <%= render @resource_picture.classname.tableize + '/confirm' %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
--- /dev/null
+<%= render @resource_picture.credit_template %>
<h1>Listing resource_pictures</h1>
<% @resource_pictures.each do |resource_picture| %>
+ <% @resource_picture = resource_picture %>
<div>
- <%= resource_picture.filename %>
- <img src="<%= resource_picture.url('thumbnail') -%>">
+ <%= link_to resource_picture.filename, resource_picture_path(resource_picture) %>
+ <img src="<%= resource_picture.url -%>">
<%= resource_picture.width %>x<%= resource_picture.height %>
<%= resource_picture.filesize %>bytes
- 画:<%= h resource_picture.original_picture.artist.name %>
+ <%= render resource_picture.credit_template %>
</div>
<% end %>
--- /dev/null
+<%= render 'resource_pictures/form' %>
--- /dev/null
+$("#oplg").html("<%= escape_javascript(render('form')) -%>");
<p id="notice"><%= notice %></p>
-
+<%= render @resource_picture.classname.tableize + '/credit' %>
<p>
<a href="<%= @resource_picture.url %>">ノーマル</a>
<img src="<%= @resource_picture.url -%>">
</p>
<p>
- <a href="<%= @resource_picture.url :v %>">垂直反転</a>
- <img src="<%= @resource_picture.url :v -%>">
-</p>
-<p>
- <a href="<%= @resource_picture.url :h %>">水平反転</a>
- <img src="<%= @resource_picture.url :h -%>">
-</p>
-<p>
- <a href="<%= @resource_picture.url :vh%>">垂直水平反転</a>
- <img src="<%= @resource_picture.url :vh -%>">
-</p>
-<p>
<a href="<%= @resource_picture.url :thumbnail%>">サムネ</a>
- <img src="<%= @resource_picture.url :thumbnail -%>">
+ <img src="<%= @resource_picture.url :full -%>">
</p>
<%= link_to 'Back', resource_pictures_path %>
--- /dev/null
+<% @sp = SystemPicture.find(@resource_picture.credit_data["system_picture_id"]) %>
+<%= content_tag(:a,
+ tag(:img, :src => @sp.url, :alt => h(@license_group.caption.to_s + '[' + @license.caption.to_s + ']')),
+ :href => @license.url )
+%>
--- /dev/null
+<div>
+<%= content_tag(:a,
+ tag(:img, :src => @resource_picture.license.system_picture.url, :alt => h(@resource_picture.license.license_group.caption.to_s + '[' + @resource_picture.license.caption.to_s + ']')),
+ :href => @resource_picture.license.url )
+%>
+</div>
+著作者:<%= link_to h(@resource_picture.artist_name), :controller => 'artists', :action => :show, :id => @resource_picture.artist.id %>
--- /dev/null
+<%
+ unless @standard_license
+ @standard_license = StandardLicense.new
+ @standard_license.supply_default @artist
+ end
+ %>
+<%= form_for(@standard_license) do |f| %>
+ <% if @standard_license.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@standard_license.errors.count, "error") %> prohibited this comic from being saved:</h2>
+
+ <ul>
+ <% @standard_license.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :license_id %><br />
+ <%= f.collection_select :license_id, @license_group.licenses.map {|l| [l.name, l.id] }, :last, :first %>
+ <%= f.text_field :artist_name %>
+ </div>
+ <%= hidden_field_tag :original_picture_id, @original_picture.id %>
+ <%= hidden_field_tag 'original_picture_license_group[original_picture_id]', @original_picture_license_group.original_picture_id %>
+ <%= hidden_field_tag 'original_picture_license_group[license_group_id]', @original_picture_license_group.license_group_id %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
--- /dev/null
+<%= render 'standard_licenses/form' %>
--- /dev/null
+$("#oplg").html("<%= escape_javascript(render('form')) -%>");
</tr>
<tr>
<td>
- <%= link_to 'lesences', :controller => 'licenses', :action => :list %>
+ <%= link_to 'licenses', :controller => 'licenses', :action => :list %>
</td>
</tr>
<tr>
<td>
- <%= link_to 'common lesences', :controller => 'common_licenses', :action => :list %>
- </td>
- </tr>
- <tr>
- <td>
- <%= link_to 'original lesences', :controller => 'original_licenses', :action => :list %>
+ <%= link_to 'license_groups', :controller => 'license_groups', :action => :list %>
</td>
</tr>
<tr>
PictureIO.setup do |config|
config.original_picture_io = pio.new y[Rails.env]["original_picture"]
config.resource_picture_io = pio.new y[Rails.env]["resource_picture"]
+ config.picture_io = pio.new y[Rails.env]["picture"]
config.system_picture_io = pio.new y[Rails.env]["system_picture"]
end
module ActiveRecord
io: LocalPicture
original_picture: /pettanr/dev/o/
resource_picture: /pettanr/dev/r/
+ picture: /temp/p/p/
system_picture: /pettanr/dev/s/
test:
io: LocalPicture
original_picture: /pettanr/test/o/
resource_picture: /pettanr/test/r/
+ picture: /temp/p/tp/
system_picture: /pettanr/test/s/
production:
collection do
get :index
get :show
+ get :new
+ post :create
get :count
get :list
get :browse
end
- member do
- end
end
resources :original_pictures do
new do
delete :destroy
end
end
+ resources :original_picture_license_groups do
+ collection do
+ get :new
+ post :create
+ end
+ end
+ resources :standard_licenses do
+ collection do
+ get :new
+ post :create
+ end
+ end
resources :panels do
collection do
get :index
get :browse
end
end
+ resources :license_groups do
+ collection do
+ get :index
+ get :show
+ get :list
+ get :browse
+ end
+ end
resources :original_licenses do
collection do
get :index
--- /dev/null
+{\r
+ "PublicDomaina": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "licenses_attributes": {\r
+ "PublicDomain": {\r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "system_picture": "Data"\r
+ }\r
+ }\r
+ },\r
+ "Unknowna": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/",\r
+ "licenses_attributes": {\r
+ "UnknownF1": {\r
+ "caption": "Unknown Flag1", \r
+ "url": "http://test.com/f1",\r
+ "system_picture": "Dataf1"\r
+ },\r
+ "UnknownF2": {\r
+ "caption": "Unknown Flag2", \r
+ "url": "http://test.com/f2",\r
+ "system_picture": "Dataf2"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+class CreateLicenseGroups < ActiveRecord::Migration
+ def change
+ create_table :license_groups do |t|
+ t.string :name, :null => false, :limit => 50
+ t.string :classname, :null => false, :limit => 50
+ t.string :caption, :null => false, :limit => 30
+ t.string :url, :null => false
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class CreateResourcePictureLicenses < ActiveRecord::Migration
+ def change
+ create_table :resource_picture_licenses do |t|
+ t.integer :resource_picture_id, :null => false
+ t.integer :license_id, :null => false
+ t.string :artist_name, :null => false
+ t.string :credit
+ t.string :settings
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class ChangeLicense < ActiveRecord::Migration
+ def up
+ remove_index :licenses, :column => [:url]
+ drop_table :licenses
+ create_table :licenses do |t|
+ t.integer :license_group_id, :null => false, :default => 0
+ t.string :name, :null => false, :limit => 50, :default => 'Default'
+ t.string :caption, :null => false, :limit => 30, :default => 'no name'
+ t.integer :system_picture_id, :null => false, :default => 0
+ t.string :url, :null => false\r
+ t.string :settings
+ t.timestamps
+ end
+ add_index :licenses, [:name], :unique => true
+ add_index :licenses, [:url], :unique => true
+ end
+
+ def down
+ remove_index :licenses, :column => [:name]
+ remove_index :licenses, :column => [:url]
+ drop_table :licenses
+ create_table :licenses do |t|
+ t.string :name, :null => false\r
+ t.string :url, :null => false\r
+ t.integer :cc_by, :null => false, :default => 0\r
+ t.integer :cc_sa, :null => false, :default => 0\r
+ t.integer :cc_nd, :null => false, :default => 0\r
+ t.integer :cc_nc, :null => false, :default => 0\r
+ t.integer :no_resize, :null => false, :default => 0\r
+ t.integer :no_flip, :null => false, :default => 0\r
+ t.integer :no_convert, :null => false, :default => 0\r
+ t.integer :keep_aspect_ratio, :null => false, :default => 0\r
+
+ t.timestamps
+ end
+ add_index :licenses, [:url], :unique => true
+ end
+end
--- /dev/null
+class RmLidOnOp < ActiveRecord::Migration
+ def up
+ remove_column :original_pictures, :license_id
+ end
+
+ def down
+ add_column :original_pictures, :license_id, :integer, :null => false, :default => 0
+ end
+end
--- /dev/null
+class CreateOriginalPictureLicenseGroups < ActiveRecord::Migration
+ def change
+ create_table :original_picture_license_groups do |t|
+ t.column :original_picture_id, :integer, :null => false, :default => 0\r
+ t.column :license_group_id, :integer, :null => false, :default => 0
+ \r
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class CreateStandardLicenses < ActiveRecord::Migration
+ def change
+ create_table :standard_licenses do |t|
+ t.column :license_id, :integer, :null => false, :default => 0
+ t.column :artist_name, :string, :null => false, :default => 'unknown'
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class RpJoinRpLicense < ActiveRecord::Migration
+ def up
+ add_column :resource_pictures, :artist_name, :string, :null => false, :default => 'unknown'
+ add_column :resource_pictures, :credit, :string
+ add_column :resource_pictures, :settings, :string
+ add_column :resource_pictures, :picture_id, :integer, :null => false, :default => 0
+ end
+
+ def down
+ remove_column :resource_pictures, :artist_name
+ remove_column :resource_pictures, :credit
+ remove_column :resource_pictures, :settings
+ remove_column :resource_pictures, :picture_id
+ end
+end
--- /dev/null
+class CreatePictures < ActiveRecord::Migration
+ def change
+ create_table :pictures do |t|
+ t.integer :original_picture_id, :null => false, :default => 0
+ t.integer :revision, :null => false, :default => 1
+ t.string :ext, :null => false
+ t.integer :width, :null => false
+ t.integer :height, :null => false
+ t.integer :filesize, :null => false
+ t.integer :artist_id, :null => false, :default => 0
+ t.integer :license_id, :null => false, :default => 0
+ t.string :artist_name, :null => false, :default => 'unknown'
+ t.string :credit
+ t.string :settings
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class AddCreditData < ActiveRecord::Migration
+ def up
+ add_column :resource_pictures, :classname, :string, :null => false, :limit => 50, :default => 'StandardLicense'
+ add_column :pictures, :classname, :string, :null => false, :limit => 50, :default => 'StandardLicense'
+ end
+
+ def down
+ remove__column :resource_pictures, :classname
+ remove__column :pictures, :classname
+ end
+end
--- /dev/null
+{\r
+ "StandardLicense": {\r
+ "classname": "StandardLicense", \r
+ "caption": "Standard License", \r
+ "url": "http://test.com/standard_license",\r
+ "licenses_attributes": {\r
+ "StandardLicenseA": {\r
+ "caption": "Flag A", \r
+ "url": "http://test.com/standard_license/a",\r
+ "system_picture": "iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAIAAAAlV+npAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIYSURBVGhD7ZtNkoIwFIS5D+WOY7hxzw1ceQPdsfMSuvMO7ixvMseYAUMS8vJDEvLAqWrLjSUgfK+701RhdT7/4h1JoIrcDpv1BAArwViABVg8QUyV9X7+4C0I2DENWF5xAFaCbwALsHhyFsqCsqCszRsMbAgbwoawYYILAAuweCLjvyrruq/mX/t7mcvrWvFbu+Mr+oCvUy1PsL48Cg0vszp8OyzJVwA7dGXMngnLnPD9ME6xvRaaoXH8dGXRWRbS+FqwzFFXtjVulx0x9nCFEzdNv51xlhxe3chjlpniCrA8F1w1p9vojsexcSVgv0EWrIkSlcSKOJEdlgKh41mpTAhEacrQS68OSTPNhorvZ3fyW8tSghuWcoSxJMmBm9fjS5YkWBS9ye6rYalTN0EouQ3usNKKVoQUWLaQHdLORcasLJLrVjKJKHFnlnJlAiyXjtw2zykTzLDsNc7kNc1du7uNEouHFTeb6GZLgTLDesrMCjSdrqVLlbpmsRf56DfRfFVeVri4YU0sRk9UrneCxfRbIiWtl3Bd8ndjLfBFhYsdlrdYDoTM1ZAkmm4SikLwdi8kQN3XlhSuFWB9nO8KL33eVtZY98wmL0eDn8Gh15AF99VFYOWsLNkpu+GOgJUwacACrNyOHvY4lAVlQVkbroN48i/BgIDFAAt/DggQwHPweA5+nefgYUPYMMFrgAVYPMEEZZVR1h8aqGKZ0anY3gAAAABJRU5ErkJggg==",\r
+ "settings": "{\"open\": 1, \"commercial\": 1, \"official\": 0, \"attribution\": 1, \"derive\": 1, \"thumbnail\": 1, \"gif_convert\": 1, \"reverse\": 1, \"resize\": 1, \"sync_vh\": 1, \"overlap\": 1}"\r
+ },\r
+ "StandardLicenseB": {\r
+ "caption": "Flag B", \r
+ "url": "http://test.com/standard_license/b",\r
+ "system_picture": "iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAIAAAAlV+npAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAANFSURBVGhD7ZjPaxpBFMc3/Ssq2gbBQqF4C2hyKXpqITkIgge9JocaChIk3oynGkT2klzsVQ+BBQ8K6UnpoVXBmwiFBtKWFftftLM7sz/txnm7k4DNWzyo+31vZj7z3pu3u3V29kfCi4/AEz4ZqjQCCAsQBwgLYQEIAKRbrgL/5vVvgPV/Lf30+alrfZiGgA1HWAgLQAAgxchCWAACAClGFsICEABIMbIQFoAAQIqRhbAABABSjCyEBSAAkHK9dRg1Q6X+Oqf7nfFJep2I4/6knKy0iS5e/PoxG+Uw0CWG1ao+U1+eJnjd2HWP8a1DtxJKNgd+aK3YcNWs3ZPleGh+OhnmpSBbfy7FhFXwNb2qKeas6gXmry9fLYK7vqd38CQpUiHrc9xSXVNdtA7tAvJd2/zbq+MQzUFyzS73mIdVc86FJ94a+8ppsEbGFVmQoRwLZobzajZ1YO6tqhwkC9WZy6mgzfeY6svnYcgiPLSCYanKe3muDUXKM8tclgtT+YMeX4tW7XKqKez5MqSpHc1dLMdG7lgeLo4ivlaqKnJXN4wX3+368uAyEgtr0DFAVM2DLNGQ9/VB570vpHCo31lMRWM2BOnTYS8nYvMlLYpZBcjqkyGnIeBUvZOpUFiLmxs6mAOE9Gx7R/93+oOEVuRFnGr6eVqSDpVbEbvu6UM7DVOh84mAQYTCMqPGAEFx0B1mV/ioWqTs2MUKue8q7oLgyO6lYozVrZRHgXEJhWVGzZ3TimR7pJyx3DSV82rtHkIski0ZB+K3X4G7B6GwwrEYXTzp5u0tmPFd66QnZZoRVu9mVPTZT0c+un4GDgsBDoTCktJ5GvYkDd1N8+Dc6B68Wur4tvPhpn8dPHFGzTw9ECVJQPfA9Wzo3BSybDoD0sE3Vo5k0mft0e5h5doptXs5lT36ue+SWsNaBNO/IbFueUeH97OhbqMPDTxtH+DZUO+V2jV25NlWl6nr0000zE7KvKm1VFYzRdoI84lKQO7oNQFM6p8D+4gsEQvYBB8PEFmbgMHvHMUWeL+z2BA7hAXYKISFsAAEAFKMLIQFIACQYmQBYLmbUoDp45NiZAH2HGEhLAABgBQjC2EBCACkGFkIC0AAIP0Las1F1VY+UUMAAAAASUVORK5CYII=",\r
+ "settings": "{\"open\": 1, \"commercial\": 1, \"official\": 0, \"attribution\": 1, \"derive\": 1, \"thumbnail\": 0, \"gif_convert\": 1, \"reverse\": 1, \"resize\": 1, \"sync_vh\": 1, \"overlap\": 1}"\r
+ }\r
+ }\r
+ }\r
+}\r
@base = b
end
- def self.subdirs
- ['', 'v', 'h', 'vh', 'thumbnail']
- end
-
def dir(subdir = nil)
sd = if subdir.to_s.empty?
self.base
class PictureIO
- @@resource_picture_io #= LocalPicture.new
- @@original_picture_io #= LocalPicture.new Rails.root + 'original'
- @@system_picture_io #= LocalPicture.new Rails.root + 'system'
def self.original_picture_io
@@original_picture_io
@@resource_picture_io = pclass
end
+ def self.picture_io
+ @@picture_io
+ end
+
+ def self.picture_io=(pclass)
+ @@picture_io = pclass
+ end
+
def self.system_picture_io
@@system_picture_io
end
@io = PictureIO::LocalPicture.new @path
end
- describe 'サブディレクトリに於いて' do
- it '配列が返る' do
- PictureIO::LocalPicture.subdirs.is_a?(Array).should be_true
- end
-
- it 'カレント、サムネ、水平反転、垂直反転、水平垂直反転が返る' do
- PictureIO::LocalPicture.subdirs.size.should eq 5
- PictureIO::LocalPicture.subdirs.include?('').should eq true
- PictureIO::LocalPicture.subdirs.include?('v').should eq true
- PictureIO::LocalPicture.subdirs.include?('h').should eq true
- PictureIO::LocalPicture.subdirs.include?('vh').should eq true
- PictureIO::LocalPicture.subdirs.include?('thumbnail').should eq true
- end
- end
-
describe 'ファイル存在確認に於いて' do
before do
end
"height": 200,\r
"visible": 3\r
},\r
- "auth_token": "Qr2cveaLKqMHA8dME7CN"\r
+ "auth_token": "vX7rc33zxVJSQPKjp2vc"\r
}
\ No newline at end of file
"original_picture": {\r
"file": \r
"iVBORw0KGgoAAAANSUhEUgAAAWIAAAF7CAYAAADohYEpAAAcW0lEQVR4nO3dTW4cx7KG4ewLz0gYGgmCVsGleBEeHJ+zAQ489IArEDS4i7hL4SoIgSPBIMd9BzolF4tVWfkTmRGR+T4AAdkkm93183V0VGbW5Xq9BgCAnv/RfgIAMDuCGACUEcQAoIwgBgBlBDEAKCOI0d3lcrnydfwVQgj/+eMPhjNN5MLwNbSyhAr6ul6vF+3ngDwEMUQRvrYQyj4QxKhC8PpAINtGECMZoTsGQtkeghiHCN7xEco2EMT4qXfw3t/f9/xzbjw8PHT/mwSyLoJ4Uj1Cl6Dt5+/v30MIIXz5+rX4MQhjPQTxJKh2x7eEcQgh/PrhQ3FlTSD3RxAPSKO3S/DaQSD7QxAPgGoXW+sw3sppXxDGfRDEDhG8SHUUyISxLQSxcbQZIGUbyoSxHQSxMVS7aEWiXUEgt0EQG9ErgAneucXCOIS0QCaM5f2i/QRm1zKACV1s/frhw2kYn7lcLlfCWBYVsYJW4UvwIhVtClsI4s4kQ5jgRamUqpg2RT8EcUc1IUzoogWJQCaM69Ej7qAkgAle9EDP2AYq4oZSA/jf//rXz3//+uFDs+cD7EkN4lhlTBDX4eahjRDC8CL1uFsfq1usXV2HilhYzgG5HNgEMCygMtZDj1hISQCHQAjDDvrFeqiIBZS0IUIghGETIyn6I4grUAVjVIRxXwRxIS7GYXS1YUwQpyOIMxHAmAlh3AcX6zLkhjABjNlx8S4N44gTEcLAvtj44hAYY5yC1kSClAOJVgRGJTG+OATaFDEE8YmzEF7WhFgOVkIYo8kZW0wYlyGID6RUwff39+9uXQ6MSCqMCeJ99Ih3EMLAWznH91nPGO8RxBuEMLBP4ji/XC5XLt69RxCvEMKADEZS5KFH/F+5IUwAY1b0i+VNP6EjZ2gaIQzIrNIWApM91mhNnGDFNKAcF+7STNuayJ2kEQIhDKzRopAzZUVcEsIA3pIa0saFuwmDuDSEqYYBtDJVEBPCgCyqYhnT9IjPdnTsICGIgTj6xXWmqIhLQ/jXDx8IYSAB50mdKYI4JhbCAOTRonhv+CCedccCvVG8lBs6iEtaErQjgPYYHvrWsEFcGsIAynEOlRk2iGN4NwZgyZBBXNIX5p0ckFF7Ls14XWfIccSxHckoCVjy8PDQ9PGXeypqSBlbzJjiH4ZbBrMkhIHeWgfw9u9oBnKpmZbJHKoirpm4AbTWK3xjegZy6mw7quKBgnjmKcwSJ7jHismL2P55eXlp+rdvb28Pv9djn9OeSDNFEJ+1JDwG8ci9RUty70SxHEtn+6d1AG9pBjJhfG6IIK7tC3sKYu2PtxZOWstigdI7fPccBXLL/UqL4tzQQew9hFNDV+IEj1VMLY1yAdV6AO/Z7nPLYTx6ELsfRzzqmMOUj7bLl4T14/UMji9fv0ZDzIO956+xLXNtn5/2p62YUc/zhfuKeMRqWPPizpnWlbO3Cnkbwtr7p9R6v7aqjGlRHHMdxKP1hrcB7PWkznEU7B4CeR0YI+wrD2FMEBtUUw2HYCeI9yrgEU7sHHuBbDWMR6mC91gJ49mC2O3MutqeESFsy/Ka10GwPhmthPLIIQw9biti720JAjjOYstiphBetj9VcR8ug1hiPQmtICaA01kK49H6wWcstChmumjnfvjaGiE8lqMhYL2Hu80WwiH0eZ1n56GVdlQP7oLY43jCh4eH3RERs5zUErbbq1cYzxjCWy3HF5cWRR5zIMZda6J2pEQIfSviGYektbZtWbSqnAjhPi2KEOJtihlaFO4qYi+OqmDU69GqIITtmKFFMV0Q96iGaUO0p903nkWvKdCz3z3dVRBLtCVaowrup9UbHNXwW5a3wSi9Ylc9Yg8z6ZYgtnzwjmjdy6x5Y5YM4Zubm6rfz/X6+trssekVt+WmIvZYDUNHaZtCIoRvbm5+fvW2/tvSz6Fni2JGboIYiJH8BFLyWFrhe6ZVMGuIFV3eWxQEsZB1lUBbwp/SKtpbwO1VzdZeQ6wqtvQJWJKLIPbQllgQwnpKJ3yUtiQshZeEs0DuuYh8SYvCc1XsIoitozfsFyH8nrUKeWvEFoX5IPZUDUNfj2nQlkNK0l7bwsOtlTyGsfkgBnK1DONZQnhrHcgW2m+jFWKmg9hbNWzhAEW63LbErCG8tgTyMv9Asyq2mgMl3N6hwwqrH896hkbLiQSlXl5efk5C+PL1a/SkPQthAjju4eGh6SSPGZgNYm/VsDbNsNj72xbCeR3GW0s1HAthAjjuer2Gy8X1hDYzTLcmrNMeO2xxDOjCynNb9su6DZHSN9Z+3t5Y/WTohdmKGPs8BoSVNsm2RXH05ulxG8M3KuJCvaphq7OfrDobchVrSbCN860XDaMqLmcyiD31h1uHMMrlDLliW5cjjOuZDOIWJFd1an2wUZnJ2m7P6/XKJw1hhHEdc0HsqRpugVBo53q9Bk/rb3ujEcZHueBtdp25IPZEui1BCANzIogztXqnJ4SBeZkK4lnbEoQwRrFu/9ArTmcqiD2RuJ8ZF4owOs0w9tQnNjOhw0M1LHFQEbwAtqaoiK3ckJAQxix6jlCxVKyVmiKILSCEMZtlQSB6xecI4g4IYcyIMdvpTASxh/7wGvc2A/JQFceZCGIPSg4kQhiz6zXbzvsMO4IYAJQRxI1QDQM/sCDQOYK4AUIYQA6CGACUEcTCqIaB92hPxBHEgghh4Bjjio8RxAlS7k9HCAPpqIrfIogBdENVvI8gFkA1DOSjKv4HQVyJEAZs8Dy7jiCuQAgDkEAQA4NalqFM+bnly4q/v3/XfgpdmblDhzdUw7BqHajLv/cuku0Fb+zn0Q5BnIkARqnL5ZIVcNugTPndo6o2N2BznyvqEMRAY6kV6t7P7/3/o99NaS0sAWupDQF6xEAzsb5r7v/P/ZmWvw95BDHQQGqg7lXLqY9f+rspaEv0RWsCEJYbijX9WAJ4DFTEgAGt2gU5wTpCCHud1EEQA4JaVKi1AZny+5ZCeLYxxCEQxDDA4oSCErHnXxuoJb+//vnY71oK4VnRI4aa0SYUHA0L2wZizRtO6u/vbT8P23TGajgEghgN1QTOKBMKjgKxNEzX///oMUbYbrMhiCFOqsXgMYxTn+9ZGHvr66IOPeIE9/f3P//tvY/ZmvT2GaF3fOSs4sU8TATx9XrdPdO+fP3a+6m4lRtY6wtkEhfLWgfmyGG8/cJ8aE04tw2o2vUIjn6/dRCm9E09tiqAFCYqYg+W9oSXIIiNSEj9/V7DypZtWrO6GOAZQZzJUs8ytbpN+dmW9j5+H30U5+M5anmcXUcQZ7BUFefefUEDoQqkIYgLWKqKrZKYlut1UgKQy0wQM3IindSbQKur9dKPxYgCjM5MEHuh3Z6QDOG9/3e2JkHKF4A8DF8rpLUmwtl6BjVTZ1O/D1jm8VM0FXEB7ap4K3WVrZTvA+hviiButaKT1kW7s1YAbQPMKlYNH12HssBFEHv8qAEAqVwEsQTpqthaewLwrvYc9VoNh2AsiK1vrD2MKQbqzbog/MJUEMdItCdm39nAqDxXwyEYDGIPG21BewKoR4FkMIhD8DfLjvYEUEYihL1XwyEYDeKWuGiHUkeL6Usvso/5uAtiqmJoYN/aNEI1HMKkU5z//v49/PrhQ9HvPjw8RL/v+Xbw2FcawtxR5L3//PGH9lMw6WL5QIkt5Hy0+HOOnDA+C+Ajlrcvzq1DeH0T2bWjY4N9v2+9TWvO41Gq4RAmrYh7oiry6yyE9wKYfY0SpnvEsXe1nuOKS6vhBf1Ff1Iq4TXW8uhrpGo4BAcV8fV6vbS811RNvzgHlbEP2zfNlEqY/Zru9fVV+ymYZLoiXrQeVxyrjGur4TUqY9tSQniLEE4nFcKjVcMhOKiIe8mtjB8fHw+/d3d3d/g9KmObUkN4/cbMfkzXI4Q9c1ERx0jumG1lXFoNx0I6BCpja7b94NzREYjrFcJeq+EQqIjfKe0Zf/z86c1/Pz1/C58/fjr4aVhQ0opYUA2noRJO46Yi7vlu9/f379HqZ1vxbkN48fT87fAxqIp15YYwLYl8PUPYczUcgqMgjun5bnnWdshBGOvYBgQhLI8QzuOqNREbyvbl61eR2XbLY0k5a1Fw8U5PSitiHcIvLy/h9fU13NzctHxaCOnn4AghHMIgFXEvpdVwrEUBPX/++Wf0+0ftKcbCxrF98rkL4taz7XIf46g/DNteXl6qfp6w2SexXXLOwcvlcl2+qv+wIndB7HWDUxXbdFQVpwxVI4zfktoepS1Gz4HsKohTNnKrC3eSF+lgyzaMtyEcq54JY3m157DHMHYTxDkbd/Qxhyh3Fpw5IZz6mDOwNl7YW3XsIohLNihhjBx7LYqcPvLMYWwthNe8hLH5IO65IQnvudVOYX59fZ0ukHuH8NPzt/D0/C2rVeghjE0H8dkGfHx8jO4QqWClPzyHl5eXN1+lZgnjniG8BPDz04+vEM7P/zXrYWw2iFNCeO/fW1S5gF2pIbwO4MXHz5/Cx8+ffob0GcthbDKISzYYYQxLRm5T9Hxtj4+PbwJ4Cd+98fuew9hkEJ+hVQAvRgvjnq9nfZ4fhe+W1zA2F8SxjXTWE6IqBtrRDOEcHsPYXBDXIowBeT1bETUhvEjtG1thKojPqmHAI+/tCcnnf3t7K/ZYKU7WBDdTFZsKYineqmLWJR6f9zDuIfWGC5KshLGZIKYaxug8jqToVQ23DGEPLQoTQdwihC1Wxdw6CSH4qY69PM8U1lsUJoK4FYthHEMYt2UpWCw9lz3Sz0+rGvZCPYhbtySshfHZxyTCuA2LwWe1VaEZwi1ZrorVg1gbYTw+i2G3Zun59QxhDVb7xapB3OsCnceLfYSxDEshF2PhebZ4DrmLJ83YlgghhIvmHYR7j5S4u7sr+r3Yc6k5cGJ3d15wh+c6FgIuh9Ydoltsp7NqeO+86hHEsfNO667QahWxxnA1a5Vx4lRMquNC3kI4BJ3nrPE3tUI4BJvtCZUg1myMewzjEGhVzKTnRbxWfyf3At2sLYmFuYt11oKyB8JYnsdqeKvla2gZ9tYu0HnQPYgtzKDLWdm/F8IYe1qEZcsALukLW6L1ab1rEGuP1duydlBk3Gmgw7Pxa4RqeE2yetWsgo/ON422hLU+sZnWhFYoWgvjENICmTCeT20gWwxhizQKxm5BbKElUfL3tZ9bDGH83mjV8J4lkHNea6vhabUhrHmRzlJV3CWIrbUk9lgMXNoUOJMSyBpjhBdWQ/hM78z6pfUfyLkbc47YTtze7dWzp+dvSRM/MEc1fKTna5doRVgJYSvnl2qPuEUIL9+X2tGls/Ek0S+GBRKtiBDshLAlTSviFn3hnJ348fOnYarjJYyP3r0vl0t4eXlRmyKrbeZquDWJNoRHl8vl2mvKc7MgtnJxbh3co4Tykdvb25+LrMwUyIRwGzkTM1LOaauVsIX2hJnhaylqd6TVAyFH6pXeWcJpltfZ2ywhfKbXRbsmFbF2S+LscUaujG9vb8P1ep0ioGZ4jRqkWxFeQ7in5qMm1rRDeP14nsM4tV9cE1TWWxuEsDzpKtgT7faEeBBLl/Kt3k29h3EI8YPn5uZGdBaW9WBGnVYX5KiG03SriC2+g458kCxVsZR1MGuHMtWwrBZTlEc+t1roEsRWWhIjilXF61EUkgjCMcw6LM0i0SCWaksQwEBbtCLeOypqeowndjV8DftiQ9pYpLvOMptslO2Y81pmCmFtYkFMNazL0kpSo/jrr7/e/LfnMM59MyGE+2reI87ZoezMNlr1ime0hJmH7Vn6xkEI99d1HHEMO7OexoW70d3f3//898PDw89/l2zPvWBssU8IYH/MBDFg3f39/bswtqbkOZWMiiCEZYn0iGv7w9Z3qoWlMFNx4a6t+/v7N1Vyrdp9sr6YSAj71XTUhLfxh7EQOwpj77PzEPfw8PCmCl5IhXFpa0JiJAchbMfleq0b7FCzwI/FnRqbb27pLrRnjl4HfeJ0Ep8gPPeA91g81iUdnTemxxGPFsIhUBXjHzUh+vLyIh7CNe0Hb59OZ8PFukwp/WLG9I5jCdOzAGz5SUOzAl5YLZxGUdyaqF1z2PqOlVgSTzuQaU/41uvi2xHr52gLWq0J8YqYj0D/+Pzxk3oYw5/cAJY+52YMYG1FQdzr9iGatBeKxly0q98QCOAQ9Bb+YdGfiFGrWcYT29Fz/G8MIawru0csdT86bzu+pDq2EORnz5t+cV8Sb4L0gduKnTOtqmKxHvHIveGUEPb6+tfBQCiXa/kpo9WxRQjv02hLMnztxNkO8RrAe2hZ2EL7YR4EccQIF+u46OiTVAgTvrJaXbQjiCuMVA1DH+FrR+8ChiA+MFNLArpYAwIEcQFvIUx7whYqX2wRxJm8hfCZ9evxtO6yNb2PC4shPMtM0hZ9YoJ4x6zV42hvMqOyFsLr82X59wiB3POTJDPrJkcV7MfHz59Mh3DK/8c+gjiD54pxhAplVhYDGLII4o0Z38mpiu1ZwtdyAM94rrRCjziR52oYflgO3rWzEOYTWB6CeCIMY7PJS/guCGF5tCYARYQwQqAifoNqEb14C+AQCOGWqIgT0B+GJEIYWwQxQgiMnOjB+iiIUoRwPVoT/zVLW4ILdv2MErqx44UQlkEQA4JGCd8UM4Rwr5uJEsQn6A+3NVNwecSnpz4I4kYIGLYBkIoghijCdxz0hvth1EQDXsOIkRNYEMJ9EcTCPISw9Ink4TVDzvPTtzdfqEdrQtCsgcTJOJZYNbx38Xq9/2c9B2pREeONmvYEJ+HYUkYQ8aZchopYiLcQYmIH9kgcE7Ew9nae9EJFLIRKAN7ltiRKjNRXvlwuV6nHIogBdOcpjHuMEiGIAXSphrc8hXFrBDEANYTxDwQxgEM91lohjAliAAbMHsYEMUQwLAm1Zg5jghiAGbOGMUGMalTDkDRjGBPEeIdV2IC+COKJSQxUpxoG6rHWBOAUa4WMgyAGnOkZwLltKu7xWIYgRjHaEn15qIDXwU0opyOIAeM8BPCeJZQJ5HMEMYpQDbfjNXiP3N3dEcYnCGLAiNECGOkIYkBZTQBLVpotx49TFccRxIASKwEs9ZhnQU4YHyOIAUdyJ+H0nC68hGwskAnjfcysAxTkVMNPz99+fuX6+PnTz69ezoKWKfTvUREDHaUGcIv7pB2FcYuq+fHx8bQyXn4OE1bEnz9+4up0AqoWWanHXWnlW2NdNUtWzikhy3H2wzRBvD0RCOQfep/0M9KsgktIBjIVb5ppgvgIYXyMaqVOzpu9lRBeI4z7mSKIz06G2cPYYgh4l3sxziqp6vgojAnpH6a4WPf0/G36sEUfowTw1sfPn6ov6hG6x6aoiIHWcq85eArhBeuLtDNNED89f+MdGU2UjAn2qveY5FlM0ZpYS5n9A6TyfDGuhkSr4uhxZyRWEVsPtu1BQ3WMGt5HREigOpYzXUUM1Jg9fPdIVcczh3p2EF+v18vlcrnufc/bgh60KZCDED42c4hKmOZiXYynNw/YNmMIo15REF+v18vR96guMaKzatj7aAjoKq6ICWPMIOWiHAGMWlNcrOu5ODbGQD8YPVX1iKmKMRpW5YOG6oo4NooC6Kl3gFINQyr71EZN0C6AFKpYeNc0iGlPoCUCGKMQCWJ6xeitZwDvtSBoS8yjx7HWZdSEtxl3sEsrgAneefVYz1ysNRGrigFvCF70JFoR565D8fz0jTnqSJZ6F2RAUuy4+/L7byJ/Y4oJHRgfAYzepEI4hAajJnJbFAxjQ4pYVUIIo5Ve1yS6jiM+GkFBGCOGIWqwRrIaDqFREJcMZyOMUYJqGK30LABMrUdsMYwZB62LlgR6e376Fs0i6Wo4hIZBXDrJQyuMOantIYTR25I/vQswUxXxQjqMU4bIWazGZ0ZfGD2tq2CNT8FNg9jb1Gdm/9nAQuzoaV2EnRVtLdoSIShXxD3DuHTiSGo4MzFFBpUwetqGcI/JG3uaT+g4W6+45zoUKbf9LnkuI4dwrzfL1CqXahhScirh1rrMrCtZPH7ZSNIbKCWMcx8P9Zi+jF72zv+z469lNRxCx9ZE6aJALS6iSYUnIdwPIQwJJXnSOoRDaFQRS986qcXiQKWVMeHbHxdRUSt2rlsYOFAUxNJBq7Ve8VmobnceIdwfIYxaNSHcoxoOIYRfuPHnMYJX1+PjI/sAVTyEcAiGlsHkLh42tTwY//2//9fssQEvIRyC0Zl1e5j5NpazEKYaRo2avOgdwiE4CuIQCONZ8MkIpc4W7AkhXg1rhHAIjVsTsRe1VxGltCe4vZJ/KS0J9jFS5RRoFkZI7KkKYq13D8J4XFTDSCX9CVkrz0II4fLl99/URk0cVUas79Df0cwi6YMzVg2v9zv7FjElIWyxJbFw1SPeomc8DkIYqaRD2AIzw9dKtVqTAvKsDFereQPnONNTut+sDVXb4z6IF/SNcUbiExTHWT8S+8t6JbwYJohRrscawKm94VYk21hHj0VA15FuNaaEsIVqOATlHvHRRvDyLja6HgdpyxBexpT2upbANYt8rfaRpxAOYbCKmH6xTT17w9phyDF4rvU+8hbCIRgeNVFTFWufjJ5o3ppIuhq2tN97V+PW9doeHkM4BAMV8Zfff2tSMbGEZR2LB2uM5cCbvUrusW+8BvBCPYh7mf1k2GP1Rp25IxMsh/Cal+fpjfcQDsFIa6LnRTs+Lv5gNYRzsC/ndnd3N0QIh2AkiGNajaCY+STWvlGihFn3HdIDOAQfx3IIhloTsV5xy0XjZ2tZjFAJS0s9qVmQSFduUeYlhEMwFMRnlp1AIJdLCWEPB69UNZx7Ysd+npBup+RTsYfjeE119bU9KSMoehz0owWyZgiXzKo72v4epr0SynVq94+3EA7BaRCH0Pdg9x7KFirh2iVPJfSesUkg56vZRx4DeGEuiEPIm4nV+2D3FMrPT9/MXFXWXGtCe8o8gRw3YwW8ZbJHvGzYlEBu3TveGu1q/QgHcYx2CC/PYdYwbrH9RzxmTVbEa6Wz7mY98BdWKuG13u0JyavsvdbLaHncWnhTqjFiAC/MB3EIdSfBjIFsMYRD6BvEOaFTsy2sLHY/upFDOASjrYmtnFbF1kwfC0cb5F6q5xvR+nEIZVmjH6drLoJ4URrIvfvIvfWq/jzQ/DRQUzDgrdGP0y0XrYkjs/ePvc00aj1ywlJLhjDOo31sanMdxIvZAtnrTKOz/VSzPyyF8NrsgWzhuPNgiCBeyz3wPYVx6VVvSydDizC2GsI5egS29W0wM1c94hS5fTov/WNvbYgeRgjghZfniTaGq4i3SioNjVCWHONp/aSWqIpHCmFg+CAOYY4+nbfQKV3ciSF6GNEUQbwYMZA9B06r/eF5m2BO5u/QIWm0E9T762nx/L1vE8xpqop4zXN1PFrYSO2L0bYL5jFtEC88BfLIQVOzH0beLpjD9EG8RyucZw+Uku0++zbDGAhimJITxoQwRjHchA74RrhiRlONmgAAiwhiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlBHEAKCMIAYAZQQxACgjiAFAGUEMAMoIYgBQRhADgDKCGACUEcQAoIwgBgBlBDEAKCOIAUAZQQwAyghiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlP0/Bxl7hN5Zu0EAAAAASUVORK5CYII=" },\r
- "auth_token": "Qr2cveaLKqMHA8dME7CN"\r
+ "auth_token": "vX7rc33zxVJSQPKjp2vc"\r
}
\ No newline at end of file
}\r
}\r
},\r
- "auth_token": "Qr2cveaLKqMHA8dME7CN"\r
+ "auth_token": "vX7rc33zxVJSQPKjp2vc"\r
}
\ No newline at end of file
"comic_id": 1,\r
"panel_id": 1\r
},\r
- "auth_token": "Qr2cveaLKqMHA8dME7CN"\r
+ "auth_token": "vX7rc33zxVJSQPKjp2vc"\r
}
\ No newline at end of file
before do
#要請の必要がない=管理者登録済み かつ ライセンス登録済み
Factory :admin
- Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it 'リクエスト通りのページを開く' do
get :index
#要請の必要がある=管理者がいない または ライセンスがない
context '管理者がいないとき' do
before do
- Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
context '本機能を開こうとしているなら' do
it '初期化要請ページに遷移する' do
describe ArtistsController do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
describe AuthorsController do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
# -*- encoding: utf-8 -*-\r
-require 'spec_helper'\r
-\r
-describe ComicsController do\r
- before do\r
- Factory :admin\r
- @license = Factory :license\r
+require 'spec_helper'
+
+describe ComicsController do
+ before do
+ Factory :admin
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory :user_yas\r
@author = @user.author #ユーザ作成時に連動して作成される\r
end\r
-# -*- encoding: utf-8 -*-
-#コモンライセンス
-require 'spec_helper'
-
-describe CommonLicensesController do
- before do
- @admin = Factory :admin
- @lc = Factory :license
- @cl = Factory :common_license, :license_id => @lc.id
- @user = Factory( :user_yas)
- @author = @user.author
- @artist = Factory :artist_yas, :author_id => @author.id
- end
-=begin
- describe '一覧表示に於いて' do
- before do
- sign_in @admin
- sign_in @user
- CommonLicense.stub(:list).and_return([@cl, @cl, @cl])
- end
- context 'パラメータpageについて' do
- it '@pageに値が入る' do
- get :index, :page => 5
- assigns(:page).should eq 5
- end
- it '省略されると@pageに1値が入る' do
- get :index
- assigns(:page).should eq 1
- end
- it '与えられたpage_sizeがセットされている' do
- get :index, :page_size => 15
- assigns(:page_size).should eq 15
- end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :index
- assigns(:page_size).should eq CommonLicense.default_page_size
- end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 1500
- assigns(:page_size).should eq CommonLicense.max_page_size
- end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 0
- assigns(:page_size).should eq CommonLicense.default_page_size
- end
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
- end
- it 'コモンライセンスモデルに一覧を問い合わせている' do
- CommonLicense.should_receive(:list).exactly(1)
- get :index
- end
- it '@common_licensesにリストを取得している' do
- get :index
- assigns(:common_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 'データがリスト構造になっている' 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?("url").should be_true
- end
- end
- end
- context '作家権限がないとき' do
- before do
- sign_out @user
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :index
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :index
- response.should redirect_to '/users/sign_in'
- end
- end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- get :index, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- get :index, :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- get :index, :format => :json
- response.should be_success
- end
- end
- end
- end
-
- describe '単体表示に於いて' do
- before do
- sign_in @admin
- sign_in @user
- CommonLicense.stub(:show).and_return(@cl)
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :show, :id => @cl.id
- response.should be_success
- end
- it 'コモンライセンスモデルに単体取得を問い合わせている' do
- CommonLicense.should_receive(:show).exactly(1)
- get :show
- end
- it '@common_licenseにアレを取得している' do
- get :show, :id => @cl.id
- assigns(:common_license).id.should eq(@cl.id)
- end
- context 'html形式' do
- it 'showテンプレートを描画する' do
- get :show, :id => @cl.id
- response.should render_template("show")
- end
- end
- context 'json形式' do
- it 'jsonデータを返す' do
- get :show, :id => @cl.id, :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
- it 'データがアレになっている' do
- get :show, :id => @cl.id, :format => :json
- json = JSON.parse response.body
- json["name"].should match(/peta/)
- end
- end
- end
- context '作家権限がないとき' do
- before do
- sign_out @user
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :show, :id => @cl.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :show, :id => @cl.id
- response.body.should redirect_to '/users/sign_in'
- end
- end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- get :show, :id => @cl.id, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- get :show, :id => @cl.id, :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- get :show, :id => @cl.id
- response.should be_success
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- get :show, :id => @cl.id, :format => :json
- response.should be_success
- end
- end
- end
- end
-=end
-
- describe 'インポートに於いて' do
- before do
- sign_in @admin
- sign_in @user
- #テストデータを用意してね
- @f = Rails.root + 'spec/json/common_license.json'
- @t = File.open(@f, 'r').read
- @j = JSON.parse @t
- @fs = Rails.root + 'spec/json/common_licenses.json'
- @ts = File.open(@fs, 'r').read
- @js = JSON.parse @ts
- @fes = Rails.root + 'spec/json/invalid_common_licenses.json'
- @tes = File.open(@fes, 'r').read
- @jes = JSON.parse @tes
- end
- context '事前チェックしておく' do
- before do
- #異常な行を返すから、正常の意味で空を返す
- CommonLicense.stub(:import).with(any_args()).and_return([])
- end
- it "@dataに渡したデータを保持している" do
- post :import, :file => @t
- assigns(:data).should_not be_nil
- end
- it 'モデルにインポート依頼する' do
- CommonLicense.should_receive(:import).with(any_args()).exactly(1)
- post :import, :file => @t
- end
- it "@errorsに結果を保持している" do
- post :import, :file => @t
- assigns(:errors).should eq []
- end
- end
- context 'つつがなく終わるとき' do
- before do
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者向けコモンライセンス一覧ページへ遷移する' do
- post :import, :file => @t
- response.should redirect_to('/common_licenses/list')
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t, :format => :json
- response.should be_success
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者サインインページへ遷移する' do
- post :import, :file => @t
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- post :import, :file => @t, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- post :import, :file => @t, :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '作家権限がないとき' do
- #必要なのは管理者権限であって作家権限ではない。成功を見届ける
- before do
- sign_out @user
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者向けコモンライセンス一覧ページへ遷移する' do
- post :import, :file => @t
- response.should redirect_to('/common_licenses/list')
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t, :format => :json
- response.should be_success
- end
- end
- end
- context '検証、保存に失敗した' do
- before do
- #異常な行を返す
- CommonLicense.stub(:import).with(any_args()).and_return(
- [CommonLicense.new(Factory.attributes_for(:common_license))]
- )
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t
- response.status.should eq 200
- end
- it 'resultページを描画する' do
- post :import, :file => @t
- response.should render_template("result")
- end
- end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- post :import, :file => @t, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- post :import, :file => @t, :format => :json
- response.message.should match(/Unprocessable/)
- end
- end
- end
- end
-end
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンスグループ
+require 'spec_helper'
+
+describe LicenseGroupsController do
+ before do
+ @admin = Factory :admin
+ @user = Factory( :user_yas)
+ @sp = Factory :system_picture
+ @lg = Factory :license_group, :name => 'peta'
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ end
+
+ describe '一覧表示に於いて' do
+ before do
+ sign_in @user
+ LicenseGroup.stub(:list).and_return([@lg, @lg, @lg])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ it 'ライセンスモデルに一覧を問い合わせている' do
+ LicenseGroup.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@license_groupsにリストを取得している' do
+ get :index
+ assigns(:license_groups).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 'データがリスト構造になっている' 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?("classname").should be_true
+ json.first.has_key?("caption").should be_true
+ json.first.has_key?("url").should be_true
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 okを返す' do
+ get :index
+ response.status.should eq 200
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ LicenseGroup.stub(:show).and_return(@lg)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @lg.id
+ response.should be_success
+ end
+ it 'ライセンスモデルに単体取得を問い合わせている' do
+ LicenseGroup.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@license_groupにアレを取得している' do
+ get :show, :id => @lg.id
+ assigns(:license_group).id.should eq(@lg.id)
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @lg.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @lg.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがアレになっている' do
+ get :show, :id => @lg.id, :format => :json
+ json = JSON.parse response.body
+ json["name"].should match(/peta/)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 okを返す' do
+ get :show, :id => @lg.id
+ response.status.should eq 200
+ end
+ end
+ end
+
+
+end
describe LicensesController do
before do
@admin = Factory :admin
- @lc = Factory :license
- @cl = Factory :common_license, :license_id => @lc.id
+ @lg = Factory :license_group
+ @sp = Factory :system_picture
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
describe '一覧表示に於いて' do
before do
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
sign_in @user
- License.stub(:list).and_return([@lc, @lc, @lc])
+ License.stub(:list).and_return([@l, @l, @l])
end
- context 'パラメータpageについて' do
- it '@pageに値が入る' do
- get :index, :page => 5
- assigns(:page).should eq 5
- end
- it '省略されると@pageに1値が入る' do
- get :index
- assigns(:page).should eq 1
- end
- it '与えられたpage_sizeがセットされている' do
- get :index, :page_size => 15
- assigns(:page_size).should eq 15
- end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :index
- assigns(:page_size).should eq License.default_page_size
- end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 1500
- assigns(:page_size).should eq License.max_page_size
- end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 0
- assigns(:page_size).should eq License.default_page_size
- end
- end
- context 'つつがなく終わるとき' do
+ context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
get :index
response.should be_success
describe '単体表示に於いて' do
before do
sign_in @user
- License.stub(:show).and_return(@lc)
+ @l = Factory :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 => @lc.id
+ get :show, :id => @l.id
response.should be_success
end
it 'ライセンスモデルに単体取得を問い合わせている' do
get :show
end
it '@licenseにアレを取得している' do
- get :show, :id => @lc.id
- assigns(:license).id.should eq(@lc.id)
+ get :show, :id => @l.id
+ assigns(:license).id.should eq(@l.id)
end
context 'html形式' do
it 'showテンプレートを描画する' do
- get :show, :id => @lc.id
+ get :show, :id => @l.id
response.should render_template("show")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :show, :id => @lc.id, :format => :json
+ get :show, :id => @l.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
it 'データがアレになっている' do
- get :show, :id => @lc.id, :format => :json
+ get :show, :id => @l.id, :format => :json
json = JSON.parse response.body
json["name"].should match(/peta/)
end
sign_out @user
end
it 'ステータスコード200 okを返す' do
- get :show, :id => @lc.id
+ get :show, :id => @l.id
response.status.should eq 200
end
end
-# -*- encoding: utf-8 -*-
-#オリジナルライセンス
-require 'spec_helper'
-
-describe OriginalLicensesController do
- before do
- @admin = Factory :admin
- @lc = Factory :license
- @user = Factory( :user_yas)
- @author = @user.author
- @artist = Factory :artist_yas, :author_id => @author.id
- end
- describe '一覧表示に於いて' do
- before do
- sign_in @user
- @ol = Factory :original_license, :license_id => @lc.id
- OriginalLicense.stub(:list).and_return([@ol, @ol, @ol])
- end
- context 'パラメータpageについて' do
- it '@pageに値が入る' do
- get :index, :page => 5
- assigns(:page).should eq 5
- end
- it '省略されると@pageに1値が入る' do
- get :index
- assigns(:page).should eq 1
- end
- it '与えられたpage_sizeがセットされている' do
- get :index, :page_size => 15
- assigns(:page_size).should eq 15
- end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :index
- assigns(:page_size).should eq OriginalLicense.default_page_size
- end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 1500
- assigns(:page_size).should eq OriginalLicense.max_page_size
- end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 0
- assigns(:page_size).should eq OriginalLicense.default_page_size
- end
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
- end
- it 'ライセンスモデルに一覧を問い合わせている' do
- OriginalLicense.should_receive(:list).exactly(1)
- get :index
- end
- it '@original_licensesにリストを取得している' do
- get :index
- assigns(:original_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 'データがリスト構造になっている' 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?("url").should be_true
- end
- end
- end
- context '作家権限がないとき' do
- before do
- sign_out @user
- end
- it 'ステータスコード200 okを返す' do
- get :index
- response.status.should eq 200
- end
- end
- end
-
- describe '単体表示に於いて' do
- before do
- sign_in @user
- @ol = Factory :original_license, :license_id => @lc.id
- OriginalLicense.stub(:show).and_return(@ol)
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :show, :id => @ol.id
- response.should be_success
- end
- it 'ライセンスモデルに単体取得を問い合わせている' do
- OriginalLicense.should_receive(:show).exactly(1)
- get :show
- end
- it '@original_licenseにアレを取得している' do
- get :show, :id => @ol.id
- assigns(:original_license).id.should eq(@ol.id)
- end
- context 'html形式' do
- it 'showテンプレートを描画する' do
- get :show, :id => @ol.id
- response.should render_template("show")
- end
- end
- context 'json形式' do
- it 'jsonデータを返す' do
- get :show, :id => @ol.id, :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
- it 'データがアレになっている' do
- get :show, :id => @ol.id, :format => :json
- json = JSON.parse response.body
- json["name"].should match(/peta/)
- end
- end
- end
- context '作家権限がないとき' do
- before do
- sign_out @user
- end
- it 'ステータスコード200 okを返す' do
- get :show, :id => @ol.id
- response.status.should eq 200
- end
- end
- end
-
- describe '新規作成フォーム表示に於いて' do
- before do
- sign_in @admin
- sign_in @user
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :new
- response.should be_success
- end
- it '@original_licenseに新規データを用意している' do
- get :new
- assigns(:original_license).should be_a_new(OriginalLicense)
- end
- it 'オリジナルライセンスモデルにデフォルト値補充を依頼している' do
- OriginalLicense.any_instance.should_receive(:supply_default).exactly(1)
- get :new
- 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
- 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
- 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
- end
- end
-
- describe '新規作成に於いて' do
- before do
- sign_in @admin
- sign_in @user
- end
- context 'つつがなく終わるとき' do
- it 'モデルに保存依頼する' do
- OriginalLicense.any_instance.should_receive(:store).exactly(1)
- post :create, :original_license => Factory.attributes_for(:original_license)
- end
- it "@original_licenseに作成されたオリジナルライセンスを保持していて、それがDBにある" do
- post :create, :original_license => Factory.attributes_for(:original_license)
- assigns(:original_license).should be_a(OriginalLicense)
- assigns(:original_license).should be_persisted
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- OriginalLicense.any_instance.stub(:store).and_return(true)
- post :create, :original_license => Factory.attributes_for(:original_license)
- response.status.should eq 302
- end
- it '作成されたオリジナルライセンスの表示ページへ遷移する' do
-# OriginalLicense.any_instance.stub(:save).and_return(true)
- post :create, :original_license => Factory.attributes_for(:original_license)
- response.should redirect_to(OriginalLicense.last)
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
-# OriginalLicense.any_instance.stub(:save).and_return(true)
- post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
- response.should be_success
- end
- it '作成されたオリジナルライセンスをjsonデータで返す' do
- post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
- it 'データがアレになっている' do
- post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
- json = JSON.parse response.body
- json["name"].should match(/peta/)
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, :original_license => Factory.attributes_for(:original_license)
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- post :create, :original_license => Factory.attributes_for(:original_license)
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '検証、保存に失敗した' do
- before do
- OriginalLicense.any_instance.stub(:save).and_return(false)
- end
- it "未保存のオリジナルライセンスを保持している" do
- post :create, :original_license => {}
- assigns(:original_license).should be_a_new(OriginalLicense)
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- post :create, :original_license => {}
- response.status.should eq 200
- end
- it '新規ページを描画する' do
- post :create, :original_license => {}
- response.should render_template("new")
- end
- end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- post :create, :original_license => {}, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- post :create, :original_license => {}, :format => :json
- response.message.should match(/Unprocessable/)
- end
- end
- end
- end
-
- describe '編集フォーム表示に於いて' do
- before do
- @ol = Factory :original_license, :license_id => @lc.id
- sign_in @admin
- sign_in @user
- OriginalLicense.stub(:show).and_return(@ol)
- end
- context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :edit, :id => @ol.id
- response.should be_success
- end
- it 'オリジナルライセンスモデルに単体取得を問い合わせている' do
- OriginalLicense.should_receive(:show).exactly(1)
- get :edit, :id => @ol.id
- end
- it '@original_licenseにデータを用意している' do
- get :edit, :id => @ol.id
- assigns(:original_license).should eq @ol
- end
- context 'html形式' do
- it 'editテンプレートを描画する' do
- get :edit, :id => @ol.id
- response.should render_template("edit")
- end
- end
- context 'js形式' do
- it 'edit.jsテンプレートを描画する' do
- get :edit, :id => @ol.id, :format => :js
- response.should render_template("edit")
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :edit, :id => @ol.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :edit, :id => @ol.id
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'js形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- get :edit, :id => @ol.id, :format => :js
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- get :edit, :id => @ol.id, :format => :js
- response.message.should match(/Unauthorized/)
- end
- end
- end
- end
-
- describe '更新に於いて' do
- before do
- @ol = Factory :original_license, :license_id => @lc.id
- sign_in @admin
- sign_in @user
- @attr = Factory.attributes_for(:original_license, :name => 'new lc')
- end
- context '事前チェックしておく' do
- it 'オリジナルライセンスモデルに単体取得を問い合わせている' do
- OriginalLicense.stub(:show).with(any_args()).and_return @ol
- OriginalLicense.should_receive(:show).exactly(1)
- put :update, :id => @ol.id, :original_license => @attr
- end
- it 'モデルに更新を依頼する' do
- OriginalLicense.any_instance.should_receive(:store).with(any_args)
- put :update, :id => @ol.id, :original_license => @attr
- end
- it '@original_licenseにアレを取得している' do
- put :update, :id => @ol.id, :original_license => @attr
- assigns(:original_license).id.should eq(@ol.id)
- end
- end
- context 'つつがなく終わるとき' do
- it '更新される' do
- put :update, :id => @ol.id, :original_license => @attr
- OriginalLicense.find(@ol.id).name.should eq 'new lc'
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
- put :update, :id => @ol.id, :original_license => @attr
- response.status.should eq 302
- end
- it '更新されたオリジナルライセンスの表示ページへ遷移する' do
- put :update, :id => @ol.id, :original_license => @attr
- response.should redirect_to(@ol)
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
- put :update, :id => @ol.id, :original_license => @attr, :format => :json
- response.should be_success
- end
- it 'ページ本体は特に返さない' do
- OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
- put :update, :id => @ol.id, :original_license => @attr, :format => :json
- response.body.should match /./
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- it 'ステータスコード302 Foundを返す' do
- put :update, :id => @ol.id, :original_license => @attr
- response.status.should eq 302
- end
- context 'html形式' do
- it 'サインインページへ遷移する' do
- put :update, :id => @ol.id, :original_license => @attr
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'json形式' do
- it '応答メッセージにUnauthorizedを返す' do
- put :update, :id => @ol.id, :original_license => @attr, :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '検証、保存に失敗したとき' do
- before do
- OriginalLicense.any_instance.stub(:store).and_return(false)
- end
- context 'html形式' do
- it 'ステータスコード200 Okを返す' do
- put :update, :id => @ol.id, :original_license => @attr
- response.status.should eq 200
- end
- it '編集ページを描画する' do
- put :update, :id => @ol.id, :original_license => @attr
- response.should render_template("edit")
- end
- end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- OriginalLicense.any_instance.stub(:store).and_return(false)
- put :update, :id => @ol.id, :original_license => @attr, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- put :update, :id => @ol.id, :original_license => @attr, :format => :json
- response.message.should match(/Unprocessable/)
- end
- end
- end
- end
-
- describe 'インポートに於いて' do
- before do
- sign_in @admin
- sign_in @user
- #テストデータを用意してね
- @f = Rails.root + 'spec/json/original_license.json'
- @t = File.open(@f, 'r').read
- @j = JSON.parse @t
- @fs = Rails.root + 'spec/json/original_licenses.json'
- @ts = File.open(@fs, 'r').read
- @js = JSON.parse @ts
- @fes = Rails.root + 'spec/json/invalid_original_licenses.json'
- @tes = File.open(@fes, 'r').read
- @jes = JSON.parse @tes
- end
- context '事前チェックしておく' do
- before do
- #異常な行を返すから、正常の意味で空を返す
- OriginalLicense.stub(:import).with(any_args()).and_return([])
- end
- it "@dataに渡したデータを保持している" do
- post :import, :file => @t
- assigns(:data).should_not be_nil
- end
- it 'モデルにインポート依頼する' do
- OriginalLicense.should_receive(:import).with(any_args()).exactly(1)
- post :import, :file => @t
- end
- it "@errorsに結果を保持している" do
- post :import, :file => @t
- assigns(:errors).should eq []
- end
- end
- context 'つつがなく終わるとき' do
- before do
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者向けオリジナルライセンス一覧ページへ遷移する' do
- post :import, :file => @t
- response.should redirect_to('/original_licenses/list')
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t, :format => :json
- response.should be_success
- end
- end
- end
- context '管理者権限がないとき' do
- before do
- sign_out @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者サインインページへ遷移する' do
- post :import, :file => @t
- response.body.should redirect_to '/admins/sign_in'
- end
- end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- post :import, :file => @t, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- post :import, :file => @t, :format => :json
- response.message.should match(/Unauthorized/)
- end
- end
- end
- context '作家権限がないとき' do
- #必要なのは管理者権限であって作家権限ではない。成功を見届ける
- before do
- sign_out @user
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :import, :file => @t
- response.status.should eq 302
- end
- it '管理者向けオリジナルライセンス一覧ページへ遷移する' do
- post :import, :file => @t
- response.should redirect_to('/original_licenses/list')
- end
- end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t, :format => :json
- response.should be_success
- end
- end
- end
- context '検証、保存に失敗した' do
- before do
- #異常な行を返す
- OriginalLicense.stub(:import).with(any_args()).and_return(
- [OriginalLicense.new(Factory.attributes_for(:original_license))]
- )
- end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- post :import, :file => @t
- response.status.should eq 200
- end
- it 'resultページを描画する' do
- post :import, :file => @t
- response.should render_template("result")
- end
- end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- post :import, :file => @t, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- post :import, :file => @t, :format => :json
- response.message.should match(/Unprocessable/)
- end
- end
- end
- end
-
-end
--- /dev/null
+# -*- encoding: utf-8 -*-
+#原画ライセンスグループ
+require 'spec_helper'
+
+describe OriginalPictureLicenseGroupsController do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group, :classname => 'OriginalPicture'
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @attr = {:original_picture_id => @op.id}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).with(any_args()).exactly(1)\r
+ get :new, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ get :new, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@original_picture_license_groupに新規データを用意している' do
+ get :new, @attr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ end
+ it '原画ライセンスグループモデルにデフォルト値補充を依頼している' do
+ OriginalPictureLicenseGroup.any_instance.should_receive(:supply_default).exactly(1)\r
+ get :new, @attr
+ end
+ context 'html形式' do
+ it 'ページテンプレートnewを描画する' do
+ get :new, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @attr = {:original_picture_id => @op.id}
+ @attrj = @attr.merge({:format => :js})
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ @attr = {:original_picture_id => @op.id}
+ @attrj = @attr.merge({:format => :js})
+ Author.any_instance.stub(:artist?).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :new, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 Okを返す' do
+ get :new, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録部分テンプレートartists/new.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it 'ライセンスグループモデルに単体取得を問い合わせている' do
+ LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
+ LicenseGroup.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:license_group).should eq @lg
+ end
+ it '@ctlにコントローラを用意している' do
+ post :create, @attr
+ assigns(:ctl).should eq 'original_pictures'
+ end
+ it '@original_picture_license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
+ end
+ it 'モデルに検証依頼する' do
+ OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
+ post :create, @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "検証が通る" do
+ post :create, @attr
+ assigns(:original_picture_license_group).valid?.should eq true
+ end
+ it "DBに変化がない" do
+ lambda {
+ post :create, @attr
+ }.should_not change OriginalPictureLicenseGroup, :count
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
+ post :create, @attr
+ response.should render_template("original_pictures/new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
+ post :create, @attrj
+ response.should render_template("original_pictures/new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
+ @attrj = @attr.merge({:format => :js})
+ 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 '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ Author.any_instance.stub(:artist?).and_return(false)
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
+ @attrj = @attr.merge({:format => :js})
+ 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 new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録ページへ遷移する' do
+ post :create, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ OriginalPictureLicenseGroup.any_instance.stub(:valid?).and_return(false)
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "未保存の原画ライセンスグループを保持している" do
+ post :create, @attr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ 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 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ end
+
+end
# -*- encoding: utf-8 -*-
+#原画
require 'spec_helper'
describe OriginalPicturesController do
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
describe '一覧表示に於いて' do
before do
- @op = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:list).and_return([@op, @op, @op])
end
describe '単体表示に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:show).and_return(@pic)
end
context 'つつがなく終わるとき' do
before do
OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
- assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id , :license_id => @license.id, :ext => 'jpeg')
+ assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
assigns(:original_picture).save
true
}
describe '編集フォーム表示に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
sign_in @user
OriginalPicture.stub(:show).and_return(@pic)
end
describe '更新に於いて' do
before do
- @pic = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
+ @pic = Factory :original_picture, :artist_id => @artist.id
OriginalPicture.stub(:edit).with(any_args()).and_return(@pic)
sign_in @user
end
context 'つつがなく終わるとき' do
before do
OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
- assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id , :license_id => @license.id, :ext => 'jpeg')
+ assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
assigns(:original_picture).save
true
}
describe PanelPicturesController do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
- @op = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
- @rp = Factory :resource_picture, :artist_id => @artist.id , :license_id => @license.id, :original_picture_id => @op.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @panel = Factory :panel, :author_id => @author.id
+ @attr = {:resource_picture_id => @rp.id, :panel_id => @panel.id}
end
describe '一覧表示に於いて' do
before do
- @pp = Factory :panel_picture, :resource_picture_id => @rp.id
+ @pp = Factory :panel_picture, @attr
sign_in @user
PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
end
describe PanelsController do\r
before do\r
Factory :admin\r
- @license = Factory :license\r
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory :user_yas\r
@author = @user.author #ユーザ作成時に連動して作成される\r
end\r
--- /dev/null
+require 'spec_helper'
+
+describe PicturesController do
+
+end
--- /dev/null
+require 'spec_helper'
+
+describe ResourcePictureLicenseController do
+
+end
describe ResourcePicturesController do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
- @op = Factory :original_picture, :artist_id => @artist.id , :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
end
describe '一覧表示に於いて' do
before do
- @rp = Factory :resource_picture, :artist_id => @artist.id , :license_id => @license.id, :original_picture_id => @op.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
sign_in @user
ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
end
describe '単体表示に於いて' do
before do
- @pic = Factory :resource_picture, :artist_id => @artist.id , :license_id => @license.id, :original_picture_id => @op.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @pic = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
sign_in @user
ResourcePicture.stub(:show).and_return(@pic)
end
before do
@admin = Factory :admin
- @sbt = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@sbt = Factory :speech_balloon_template
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンス選択
+require 'spec_helper'
+
+describe StandardLicensesController do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group, :classname => 'OriginalPicture'
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).with(any_args()).exactly(1)\r
+ get :new, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ get :new, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@original_picture_license_groupに新規データを用意している' do
+ get :new, @attr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ end
+ it 'ライセンスグループモデルに単体取得を問い合わせている' do
+ LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
+ LicenseGroup.should_receive(:show).with(any_args()).exactly(1)\r
+ get :new, @attr
+ end
+ it '@license_groupにデータを用意している' do
+ get :new, @attr
+ assigns(:license_group).should eq @lg
+ end
+ it '@standard_licenseにライセンス選択新規データを用意している' do
+ get :new, @attr
+ assigns(:standard_license).should be_a_new(StandardLicense)
+ end
+ it 'ライセンス選択にデフォルト値補充を依頼している' do
+ StandardLicense.any_instance.should_receive(:supply_default).exactly(1)\r
+ get :new, @attr
+ end
+ context 'html形式' do
+ it 'ページテンプレートnewを描画する' do
+ get :new, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ Author.any_instance.stub(:artist?).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :new, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 Okを返す' do
+ get :new, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録部分テンプレートartists/new.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@original_picture_license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
+ end
+ it 'ライセンスグループモデルに単体取得を問い合わせている' do
+ LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
+ LicenseGroup.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:license_group).should eq @lg
+ end
+ it '@standard_licenseにデータを用意している' do
+ post :create, @attr
+ assigns(:standard_license).should be_a_new StandardLicense
+ end
+ it '@licenseにデータを用意している' do
+ post :create, @attr
+ assigns(:license).should eq @license
+ end
+ it '@creditにデータを用意している' do
+ post :create, @attr
+ assigns(:credit).should eq nil
+ end
+ it 'モデルに検証依頼する' do
+ StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ StandardLicense.any_instance.should_receive(:valid?).exactly(1)
+ post :create, @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "検証が通る" do
+ post :create, @attr
+ assigns(:standard_license).valid?.should eq true
+ end
+ it "DBに変化がない" do
+ lambda {
+ post :create, @attr
+ }.should_not change StandardLicense, :count
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
+ post :create, @attr
+ response.should render_template("resource_pictures/new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
+ post :create, @attrj
+ response.should render_template("resource_pictures/new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ 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 '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ Author.any_instance.stub(:artist?).and_return(false)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ 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 new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録ページへ遷移する' do
+ post :create, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ StandardLicense.any_instance.stub(:valid?).and_return(false)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "未保存の原画ライセンスグループを保持している" do
+ post :create, @attr
+ assigns(:standard_license).should be_a_new(StandardLicense)
+ 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 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ end
+
+end
describe StoriesController do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory :user_yas
@author = @user.author #ユーザ作成時に連動して作成される
@comic = Factory :comic, :author_id => @user.author.id
# artist.association :author_yas
end
+Factory.define :license_group, :class => LicenseGroup do |license_group|
+ license_group.name 'pettan_public_01'
+ license_group.classname 'PettanPublicLicense'
+ license_group.caption 'pettan public 0.1'
+ license_group.url 'http://test.lc/'
+end
+
Factory.define :license, :class => License do |license|
+ license.license_group_id 1
license.name 'peta2.5'
+ license.caption 'flag'
license.url 'http://test.lc/'
- license.cc_by 0
- license.cc_sa 0
- license.cc_nd 0
- license.cc_nc 0
- license.no_resize 0
- license.no_flip 0
- license.no_convert 0
- license.keep_aspect_ratio 0
+ license.system_picture_id 1
end
Factory.define :common_license, :class => CommonLicense do |license|
op.height 111
op.filesize 100000
op.artist_id 1
- op.license_id 1
+end
+
+Factory.define :oplg, :class => OriginalPictureLicenseGroup do |oplg|
+ oplg.original_picture_id 1
+ oplg.license_group_id 1
+end
+
+Factory.define :standard_license, :class => StandardLicense do |sl|
+ sl.license_id 1
+ sl.artist_name 'no name'
end
Factory.define :resource_picture, :class => ResourcePicture do |rp|
rp.filesize 100000
rp.artist_id 1
rp.license_id 1
+ rp.classname 'StandardLicense'
rp.original_picture_id 1
end
+Factory.define :picture, :class => Picture do |p|
+ p.original_picture_id 1
+ p.revision 1
+ p.ext 'png'
+ p.width 222
+ p.height 111
+ p.filesize 100000
+ p.artist_id 1
+ p.license_id 1
+ p.artist_name 'no name'
+ p.classname 'StandardLicense'
+ p.credit ''
+ p.settings ''
+end
+
Factory.define :system_picture, :class => SystemPicture do |sp|
sp.ext 'png'
sp.width 222
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the LicenseGroupHelper. For example:
+#
+# describe LicenseGroupsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe LicenseGroupsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the OriginalPictureLicenseGroupsHelper. For example:
+#
+# describe OriginalPictureLicenseGroupsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe OriginalPictureLicenseGroupsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the PicturesHelper. For example:
+#
+# describe PicturesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe PicturesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ResourcePictureLicenseHelper. For example:
+#
+# describe ResourcePictureLicenseHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ResourcePictureLicenseHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the StandardLicensesHelper. For example:
+#
+# describe StandardLicensesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe StandardLicensesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "UnknownUrl": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner"\r
+ },\r
+ "UnknownClassname": {\r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/"\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "name": "PublicDomain", \r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "licenses_attributes": {\r
+ "PublicDomain": {\r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "system_picture": "Data"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "Unknown": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/",\r
+ "licenses_attributes": {\r
+ "UnknownF1": {\r
+ "caption": "Unknown Flag1", \r
+ "url": "http://test.com/f1",\r
+ "system_picture": "Dataf1"\r
+ },\r
+ "UnknownF2": {\r
+ "caption": "Unknown Flag2", \r
+ "url": "http://test.com/f2",\r
+ "system_picture": "Dataf2"\r
+ }\r
+ }\r
+ }\r
+}\r
Factory :admin
@user = Factory( :user_yas)
@author = @user.author
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
describe '検証に於いて' do
@user = Factory( :user_yas)\r
@author = @user.author\r
@artist = Factory :artist_yas, :author_id => @author.id\r
- @license = Factory :license\r
\r
@balloon = Factory :panel\r
@speech_balloon_template = Factory :speech_balloon_template\r
before do\r
@balloon = Factory.build :balloon, :speech_balloon_id => @speech_balloon.id, :system_picture_id => @system_picture.id\r
end\r
+ #ネストの保存はnilを許可しなければならないので数値チェックだけ
it 'テストデータの確認' do\r
@balloon.speech_balloon_id = @speech_balloon.id\r
@balloon.should be_valid\r
describe Comic do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
-# -*- encoding: utf-8 -*-
-#コモンライセンス
-require 'spec_helper'
-
-describe CommonLicense do
- before do
- #テストデータを用意してね
- @f = Rails.root + 'spec/json/common_license.json'
- @t = File.open(@f, 'r').read
- @j = JSON.parse @t
- @fs = Rails.root + 'spec/json/common_licenses.json'
- @ts = File.open(@fs, 'r').read
- @js = JSON.parse @ts
- @fes = Rails.root + 'spec/json/invalid_common_licenses.json'
- @tes = File.open(@fes, 'r').read
- @jes = JSON.parse @tes
- end
- describe '検証に於いて' do
- before do
- @l = Factory :license
- end
-
- it 'オーソドックスなデータなら通る' do
- @cl = Factory.build :common_license, :license_id => @l.id
- @cl.should be_valid
- end
-
- context 'nameを検証するとき' do
- before do
- @cl = Factory.build :common_license, :license_id => @l.id
- end
- it 'テストデータの確認' do
- @cl.name = 'CC by'
- @cl.should be_valid
- end
- it 'nullなら失敗する' do
- @cl.name = ''
- @cl.should_not be_valid
- end
- it '51文字以上なら失敗する' do
- @cl.name = 'a'*51
- @cl.should_not be_valid
- end
- end
- context 'urlを検証するとき' do
- before do
- @cl = Factory.build :common_license, :license_id => @l.id
- end
- it 'テストデータの確認' do
- @cl.url = 'CC by'
- @cl.should be_valid
- end
- it 'nullなら失敗する' do
- @cl.url = ''
- @cl.should_not be_valid
- end
- it '201文字以上なら失敗する' do
- @cl.url = 'a'*201
- @cl.should_not be_valid
- end
- it '重複していたら失敗する' do
- cl = Factory :common_license, :license_id => @l.id
- @cl.should_not be_valid
- end
- it 'url形式でなら失敗する' do
- @cl.url = ''
- pending
- end
- end
- context 'license_idを検証するとき' do
- before do
- @cl = Factory.build :common_license
- end
- it 'テストデータの確認' do
- @cl.license_id = @l.id
- @cl.should be_valid
- end
- it 'nullなら失敗する' do
- @cl.license_id = nil
- @cl.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @cl.license_id = 'a'
- @cl.should_not be_valid
- end
- it '存在するlicenseでなければ失敗する' do
- @cl.license_id = 0
- @cl.should_not be_valid
- end
- end
- end
-
- describe '対象コモンライセンスの取得に於いて' do
- before do
- @lc = Factory :license
- @cl = Factory :common_license, :license_id => @lc.id
- end
- context 'urlが一致するコモンライセンスがないとき' do
- it '新規コモンライセンスを準備して返す' do
- r = CommonLicense.update_common_license Factory.attributes_for(:common_license, :url => 'http://domain.no')
- r.should be_a_new CommonLicense
- end
- end
- context 'urlが一致するコモンライセンスがあるとき' do
- it '該当コモンライセンスを返す' do
- prm = Factory.attributes_for(:common_license)
- r = CommonLicense.update_common_license prm
- r.is_a?(CommonLicense).should be_true
- r.should_not be_a_new CommonLicense
- r[:url].should eq prm[:url]
- end
- end
- end
-
- describe 'コモンライセンス更新に於いて' do
- before do
- @lc = Factory :license
- @cl = Factory :common_license, :license_id => @lc.id
- @attr = Factory.attributes_for(:common_license, :name => 'exist case')
- @newattr = Factory.attributes_for(:common_license, :url => 'http://domain.no')
- end
- context 'つつがなく終わるとき' do
- it '対象コモンライセンスを問い合わせている' do
- CommonLicense.stub(:update_common_license).with(any_args).and_return(CommonLicense.new(@attr))
- CommonLicense.should_receive(:update_common_license).exactly(1)
- CommonLicense.store @attr
- end
- context '新規のとき' do
- it 'コモンライセンスを保存しようとしている' do
- CommonLicense.any_instance.should_receive(:save).exactly(1)
- CommonLicense.store @newattr
- end
- it 'コモンライセンスが作成されている' do
- lambda {
- CommonLicense.store @newattr
- }.should change CommonLicense, :count
- end
- context 'ライセンスとの連動' do
- it 'ライセンスが作成されている' do
- lambda {
- CommonLicense.store @newattr
- }.should change License, :count
- end
- it '両者がリンクされている' do
- r = CommonLicense.store @newattr
- l = License.find(r.license_id)
- l.should be_true
- end
- it '属性が一致している' do
- r = CommonLicense.store @newattr
- l = License.find(r.license_id)
- l.url.should eq r.url
- l.name.should eq r.name
- end
- end
- end
- context '更新のとき' do
- it 'コモンライセンスを保存しようとしている' do
- CommonLicense.any_instance.should_receive(:save).exactly(1)
- CommonLicense.store @attr
- end
- it 'コモンライセンスの数に変化がない' do
- lambda {
- CommonLicense.store @attr
- }.should_not change CommonLicense, :count
- end
- context 'ライセンスとの連動' do
- it 'ライセンスの数に変化がない' do
- lambda {
- CommonLicense.store @attr
- }.should_not change License, :count
- end
- it '両者がリンクされている' do
- r = CommonLicense.store @attr
- l = License.find(r.license_id)
- l.should be_true
- end
- it '属性が一致している' do
- r = CommonLicense.store @attr
- l = License.find(r.license_id)
- l.url.should eq r.url
- l.name.should eq r.name
- end
- end
- end
- it '属性が一致している' do
- r = CommonLicense.store @newattr
- r.url.should eq @newattr[:url]
- r.name.should eq @newattr[:name]
- end
- it '保存されたCommonLicenseオブジェクトを返す' do
- r = CommonLicense.store @newattr
- r.should_not be_a_new CommonLicense
- end
- end
- context 'ライセンスの作成に失敗するとき' do
- before do
- License.any_instance.stub(:save).with(any_args).and_return(false)
- end
- context '新規のとき' do
- it 'ライセンスに変化がない' do
- lambda {
- r = CommonLicense.store @newattr
- }.should_not change License, :count
- end
- it 'コモンライセンスに変化がない' do
- lambda {
- r = CommonLicense.store @newattr
- }.should_not change CommonLicense, :count
- end
- end
- context '更新のとき' do
- it 'コモンライセンス属性に変化がない' do
- lambda {
- r = CommonLicense.store @attr
- }.should_not change License.find(@cl.id), :name
- end
- it 'ライセンス属性に変化がない' do
- lambda {
- r = CommonLicense.store @attr
- }.should_not change License.find(@lc.id), :name
- end
- end
- end
- context 'コモンライセンスの作成に失敗するとき' do
- before do
- CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
- end
- context '新規のとき' do
- it 'ライセンスに変化がない' do
- lambda {
- r = CommonLicense.store @newattr
- }.should_not change License, :count
- end
- it 'コモンライセンスに変化がない' do
- lambda {
- r = CommonLicense.store @newattr
- }.should_not change CommonLicense, :count
- end
- end
- context '更新のとき' do
- it 'コモンライセンス属性に変化がない' do
- lambda {
- r = CommonLicense.store @attr
- }.should_not change License.find(@cl.id), :name
- end
- it 'ライセンス属性に変化がない' do
- lambda {
- r = CommonLicense.store @attr
- }.should_not change License.find(@lc.id), :name
- end
- end
- end
- end
-=begin
- describe '単体取得に於いて' do
- before do
- @cl = Factory.build :common_license
- @cl.store
- end
- it '指定のライセンスを返す' do
- l = CommonLicense.show @cl.id
- l.should eq @cl
- end
- context '関連テーブルオプションがないとき' do
- it 'ライセンスだけを含んでいる' do
- r = CommonLicense.show_include_opt
- r.should eq [:license]
- end
- end
- context '関連テーブルオプションでコマを含ませたとき' do
- it 'ライセンスと作家を含んでいる' do
- r = CommonLicense.show_include_opt(:include => :author)
- r.should eq [:license, :author]
- end
- end
- end
- describe '一覧取得に於いて' do
- before do
- @cl = Factory.build :common_license
- @cl.store
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- CommonLicense.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- CommonLicense.page().should eq 1
- end
- it '0以下の場合は1になる' do
- CommonLicense.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- CommonLicense.page_size('7').should eq 7
- end
- it 'nilの場合はCommonLicense.default_page_sizeになる' do
- CommonLicense.page_size().should eq CommonLicense.default_page_size
- end
- it '0以下の場合はCommonLicense.default_page_sizeになる' do
- CommonLicense.page_size('0').should eq CommonLicense.default_page_size
- end
- it 'CommonLicense.max_page_sizeを超えた場合はCommonLicense.max_page_sizeになる' do
- CommonLicense.page_size('1000').should eq CommonLicense.max_page_size
- end
- end
- it 'リストを返す' do
- l = CommonLicense.list
- l.should eq [@cl]
- end
- it '名前順で並んでいる' do
- n = Factory.build :common_license, :url => 'tes.to', :name => 'peta2.2'
- n.store
- l = CommonLicense.list
- l.should eq [@cl, n]
- end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- @license2 = Factory.build :common_license, :url => 'tes.to2', :name => 'peta2.2'
- @license2.store
- @license3 = Factory.build :common_license, :url => 'tes.to3', :name => 'peta2.3'
- @license3.store
- @license4 = Factory.build :common_license, :url => 'tes.to4', :name => 'peta2.4'
- @license4.store
- @license5 = Factory.build :common_license, :url => 'tes.to5', :name => 'peta2.5'
- @license5.store
- CommonLicense.stub(:default_page_size).and_return(2)
- end
- it '通常は2件を返す' do
- l = CommonLicense.list
- l.should have(2).items
- end
- it 'page=1なら末尾2件を返す' do
- #時系列で並んでいる
- l = CommonLicense.list({}, 1)
- l.should eq [@cl, @license2]
- end
- it 'page=2なら中間2件を返す' do
- l = CommonLicense.list({}, 2)
- l.should eq [@license3, @license4]
- end
- it 'page=3なら先頭1件を返す' do
- l = CommonLicense.list({}, 3)
- l.should eq [@license5]
- end
- end
- end
-=end
-
- describe 'Json解析に於いて' do
- before do
- end
- context 'テキストを渡されたとき' do
- it 'Json解析している' do
- JSON.should_receive(:parse).with(@t).exactly(1)
- r = CommonLicense.parse @t
- end
- it '単数データならHashで返す' do
- r = CommonLicense.parse @t
- r.is_a?(Hash).should be_true
- end
- it '複数データならArrayで返す' do
- r = CommonLicense.parse @ts
- r.is_a?(Array).should be_true
- end
- end
- context 'パース失敗したとき' do
- it 'Falseを返す' do
- JSON.should_receive(:parse).with(any_args).and_raise('StandardError')
- r = CommonLicense.parse @t
- r.should be_false
- end
- end
- end
-
- describe 'Jsonの繰り返し処理に於いて' do
- before do
- end
- context '単体データを渡されたとき' do
- it '一回処理' do
- r = []
- CommonLicense.each_license @j do |i|
- r << i
- end
- r.size.should eq 1
- end
- end
- context '複数を渡されたとき' do
- it '二回処理' do
- r = []
- CommonLicense.each_license @js do |i|
- r << i
- end
- r.size.should eq 2
- end
- end
- end
-
- describe 'テキスト取り込みに於いて' do
- #成功でTrue、パース失敗でFalse、失敗は保存エラーのモデルを配列で返す
- #Licenseとの連動が完成していること
- before do
- end
- context 'つつがなく終わるとき' do
- it 'Json解析を依頼する' do
- CommonLicense.should_receive(:parse).with(any_args).exactly(1)
- CommonLicense.stub(:parse).with(any_args).and_return(@j)
- CommonLicense.import(@t)
- end
- it '繰り返し処理を依頼する' do
- CommonLicense.should_receive(:each_license).with(any_args).exactly(1)
- CommonLicense.import(@t)
- end
- it 'ライセンス更新を一回依頼する' do
- CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
- CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
- CommonLicense.should_receive(:store).with(any_args).exactly(1)
- CommonLicense.import(@t)
- end
- it 'コモンライセンスが追加される' do
- lambda {
- CommonLicense.import(@t)
- }.should change CommonLicense, :count
- end
- it '[]を返す' do
- CommonLicense.import(@t).should eq []
- end
- end
- context '複数データがつつがなく終わるとき' do
- it 'ライセンス更新を二回依頼する' do
- CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
- CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
- CommonLicense.should_receive(:store).with(any_args).exactly(2)
- CommonLicense.import(@ts)
- end
- it 'コモンライセンスが二個追加される' do
- lambda {
- CommonLicense.import(@ts)
- }.should change(CommonLicense, :count).by 2
- end
- it '[]を返す' do
- CommonLicense.import(@ts).should eq []
- end
- end
- #例外ケース
- context 'Json解析に失敗したとき' do
- before do
- CommonLicense.stub(:parse).with(any_args).and_return(false)
- end
- it 'コモンライセンスの数に変化がない' do
- lambda {
- CommonLicense.import(@t)
- }.should_not change CommonLicense, :count
- end
- it 'Falseを返す' do
- CommonLicense.import(@t).should be_false
- end
- end
- context 'コモンライセンス作成に失敗したとき' do
- before do
- CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
- CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
- end
- it 'コモンライセンスの数に変化がない' do
- lambda {
- CommonLicense.import(@t)
- }.should_not change CommonLicense, :count
- end
- it '配列を返す' do
- r = CommonLicense.import(@t)
- r.is_a?(Array).should be_true
- end
- it '配列の中身は一件' do
- r = CommonLicense.import(@t)
- r.should have(1).items
- end
- it 'コモンライセンスオブジェクトが入っている' do
- r = CommonLicense.import(@t)
- r.first.is_a?(CommonLicense).should be_true
- end
- end
- context '複数のコモンライセンス作成に失敗したとき' do
- #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
- it 'コモンライセンスの数に変化がない' do
- lambda {
- CommonLicense.import(@tes)
- }.should_not change CommonLicense, :count
- end
- it '途中で保存に失敗しても全件更新依頼する' do
- CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
- CommonLicense.should_receive(:store).with(any_args).exactly(3)
- CommonLicense.import(@tes)
- end
- it '配列を返す' do
- r = CommonLicense.import(@tes)
- r.is_a?(Array).should be_true
- end
- it '配列の中身は2件' do
- r = CommonLicense.import(@tes)
- r.should have(2).items
- end
- it '配列の中身は失敗したコモンライセンスオブジェクトが入っている' do
- r = CommonLicense.import(@tes)
- r[0].is_a?(CommonLicense).should be_true
- r[0]["name"].should eq 'fail1'
- r[1].is_a?(CommonLicense).should be_true
- r[1]["name"].should eq 'fail2'
- end
- end
- end
-
- describe 'インポートエラーの表示に於いて' do
- end
-
- describe 'ファイル取り込みに於いて' do
- before do
- CommonLicense.stub(:import).with(any_args).and_return(true)
- end
- context 'つつがなく終わるとき' do
- before do
- CommonLicense.stub(:import).with(any_args).and_return(true)
- end
- it 'ファイルを開いてテキストを読む' do
- File.should_receive(:open).with(@f, 'r').exactly(1)
- CommonLicense.import_file(@f)
- end
- it 'テキスト取り込みを依頼する' do
- CommonLicense.should_receive(:import).with(any_args).exactly(1)
- CommonLicense.import_file(@f)
- end
- #テキスト取り込み成功でTrueが返る
- it 'Trueを返す' do
- CommonLicense.import_file(@f).should be_true
- end
- end
- context 'ファイルが開けないとき' do
- before do
- File.stub(:open).with(any_args).and_raise('StandardError')
- end
- it 'ファイルエラーのメッセージを出力する' do
- pending
- end
- it 'Falseを返す' do
- CommonLicense.import_file(@f).should be_false
- end
- end
- #失敗したときは、失敗したライセンスが配列で返る
- context 'テキスト取り込みが失敗したとき' do
- before do
- CommonLicense.stub(:import).with(any_args).and_return(false)
- end
- it '各コモンライセンスのエラーメッセージを出力する' do
- pending
- end
- it 'Falseを返す' do
- CommonLicense.import_file(@f).should be_false
- end
- end
- end
-
-end
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンスグループ
+require 'spec_helper'
+
+describe LicenseGroup do
+ before do
+ #テストデータを用意してね
+ @f = Rails.root + 'spec/json/license_group.json'
+ @t = File.open(@f, 'r').read
+ @j = JSON.parse @t
+ @fs = Rails.root + 'spec/json/license_groups.json'
+ @fes = Rails.root + 'spec/json/invalid_license_groups.json'
+ end
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @lg = Factory.build :license_group
+ @lg.should be_valid
+ end
+
+ context 'nameを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.name = 'a'*50
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.name = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.name = 'a'*51
+ @lg.should_not be_valid
+ end
+ it '重複していたら失敗する' do
+ l = Factory :license_group
+ @lg.should_not be_valid
+ end
+ end
+ context 'classnameを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.classname = 'a'*50
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.classname = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.classname = 'a'*51
+ @lg.should_not be_valid
+ end
+ end
+ context 'captionを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.caption = 'a'*30
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.caption = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.caption = 'a'*51
+ @lg.should_not be_valid
+ end
+ end
+ context 'urlを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.url = 'http://test.com/'
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.url = ''
+ @lg.should_not be_valid
+ end
+ it '201文字以上なら失敗する' do
+ @lg.url = 'a'*201
+ @lg.should_not be_valid
+ end
+ it 'url形式でないなら失敗する' do
+ @lg.url = 'aaaaaaa'
+ @lg.should_not be_valid
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @n = @j.keys.first
+ @a = @j.values.first
+ end
+ context 'つつがなく終わるとき' do
+ it 'データ更新準備を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:modify_object).with(any_args).exactly(1)
+ License.stub(:stores).with(any_args).and_return(0)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it 'ライセンスに複数の更新を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(0)
+ License.should_receive(:stores).with(any_args).exactly(1)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it '保存を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(0)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ LicenseGroup.any_instance.should_receive(:save).with(any_args).exactly(1)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it 'オブジェクトを返す' do
+ r = LicenseGroup.store(@n, @a)
+ r.is_a?(LicenseGroup).should be_true
+ r.name.should eq @n
+ r.url.should eq @a["url"]
+ end
+ it 'カラム値からlicenses_attributesが削除されている' do
+ @a["licenses_attributes"].should_not be_nil
+ r = LicenseGroup.store(@n, @a)
+ @a["licenses_attributes"].should be_nil
+ end
+ end
+ context 'ライセンス複数更新が失敗するとき' do
+ before do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(1)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ end
+ it '全体エラーメッセージがセットされている' do
+ r = LicenseGroup.store(@n, @a)
+ r.errors[:base].should_not be_blank
+ end
+ it 'ライセンスが作成されていない' do
+ lambda {
+ r = LicenseGroup.store(@n, @a)
+ }.should_not change License, :count
+ end
+ it 'ライセンスグループが作成されていない' do
+ lambda {
+ r = LicenseGroup.store(@n, @a)
+ }.should_not change LicenseGroup, :count
+ end
+ end
+ end
+
+ describe 'インポートに於いて' do
+ before do
+ end
+ context 'つつがなく終わるとき' do
+ it 'ファイルインポートを依頼する' do
+ LicenseGroup.should_receive(:import_file).with(any_args).exactly(1)
+ LicenseGroup.stub(:import_file).with(any_args).and_return([])
+ LicenseGroup.import(@f)
+ end
+ it 'ライセンスグループ更新を一回依頼する' do
+ LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:store).with(any_args).exactly(1)
+ LicenseGroup.import(@f)
+ end
+ it 'ライセンスグループが追加される' do
+ lambda {
+ LicenseGroup.import(@f)
+ }.should change LicenseGroup, :count
+ end
+ it 'ライセンスが追加される' do
+ lambda {
+ LicenseGroup.import(@f)
+ }.should change License, :count
+ end
+ it '[]を返す' do
+ r = LicenseGroup.import(@f)
+ r.should eq []
+ end
+ end
+ context '複数データがつつがなく終わるとき' do
+ it 'ライセンスグループ更新を二回依頼する' do
+ LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:store).with(any_args).exactly(2)
+ LicenseGroup.import(@fs)
+ end
+ it 'ライセンスグループが二個追加される' do
+ lambda {
+ r = LicenseGroup.import(@fs)
+ }.should change(LicenseGroup, :count).by 2
+ end
+ it 'ライセンスが追加される' do
+ lambda {
+ r = LicenseGroup.import(@fs)
+ }.should change(License, :count)
+ end
+ it '[]を返す' do
+ r = LicenseGroup.import(@fs)
+ r.should eq []
+ end
+ end
+ context 'ライセンスグループ作成に失敗したとき' do
+ before do
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(false)
+ LicenseGroup.any_instance.stub(:valid?).with(any_args).and_return(false)
+ end
+ it 'ライセンスグループの数に変化がない' do
+ lambda {
+ LicenseGroup.import(@f)
+ }.should_not change LicenseGroup, :count
+ end
+ it '配列を返す' do
+ r = LicenseGroup.import(@f)
+ r.is_a?(Array).should be_true
+ end
+ it '配列の中身は一件' do
+ r = LicenseGroup.import(@f)
+ r.should have(1).items
+ end
+ it 'ライセンスグループオブジェクトが入っている' do
+ r = LicenseGroup.import(@f)
+ r.first.is_a?(LicenseGroup).should be_true
+ end
+ end
+ context '複数のライセンスグループ作成に失敗したとき' do
+ #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
+ it 'ライセンスグループの数に変化がない' do
+ lambda {
+ LicenseGroup.import(@fes)
+ }.should_not change LicenseGroup, :count
+ end
+ it '途中で保存に失敗しても全件更新依頼する' do
+ LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:store).with(any_args).exactly(3)
+ LicenseGroup.import(@fes)
+ end
+ it '配列を返す' do
+ r = LicenseGroup.import(@fes)
+ r.is_a?(Array).should be_true
+ end
+ it '配列の中身は2件' do
+ r = LicenseGroup.import(@fes)
+ r.should have(2).items
+ end
+ it '配列の中身は失敗したライセンスグループオブジェクトが入っている' do
+ r = LicenseGroup.import(@fes)
+ r[0].is_a?(LicenseGroup).should be_true
+ r[0]["name"].should eq 'UnknownUrl'
+ r[1].is_a?(LicenseGroup).should be_true
+ r[1]["name"].should eq 'UnknownClassname'
+ end
+ end
+ end
+
+ describe '単体取得に於いて' do
+ before do
+ @lg = Factory :license_group
+ end
+ it '指定のコマを返す' do
+ l = LicenseGroup.show @lg.id
+ l.should eq @lg
+ end
+ end
+ describe '関連テーブルプションに於いて' do
+ context 'オプションがないとき' do
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_include_opt
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.show_json_include_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe '一覧取得に於いて' do
+ before do
+ @lg = Factory :license_group, :name => "1"
+ end
+ it 'リストを返す' do
+ l = LicenseGroup.list
+ l.should eq [@lg]
+ end
+ it '名前順で並んでいる' do
+ @lg2 = Factory :license_group, :name => "5", :url => 'http://test.ptn/10'
+ l = LicenseGroup.list
+ l.should eq [@lg, @lg2]
+ end
+ end
+ describe 'list関連テーブルプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_json_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+
+end
end
describe '検証に於いて' do
before do
- @l = Factory.build :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it 'オーソドックスなデータなら通る' do
@l.should be_valid
end
+ context 'license_group_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.license_group_id = @lg.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.license_group_id = ''
+ @l.should_not be_valid
+ end
+ it '数値でなければ失敗する' do\r
+ @l.license_group_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するライセンスグループでなければ失敗する' do\r
+ @l.license_group_id = 0\r
+ @l.should_not be_valid\r
+ end\r
+ end
context 'nameを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.name = 'a'*50\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.name = ''
@l.should_not be_valid
@l.name = 'a'*51
@l.should_not be_valid
end
+ it '重複していたら失敗する' do
+ lc = Factory :license
+ @l.should_not be_valid
+ end
+ end
+ context 'captionを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.caption = 'a'*30\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.caption = ''
+ @l.should_not be_valid
+ end
+ it '31文字以上なら失敗する' do
+ @l.caption = 'a'*31
+ @l.should_not be_valid
+ end
end
context 'urlを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 180
+ @l.save!\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.url = ''
@l.should_not be_valid
end
it '201文字以上なら失敗する' do
- @l.url = 'a'*201
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 181
@l.should_not be_valid
end
- it '重複していたら失敗する' do
- lc = Factory :license
+ it 'url形式でなら失敗する' do
+ @l.url = 'a'*200\r
+ @l.should_not be_valid\r
+ end
+ end
+ context 'system_picture_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.system_picture_id = @sp.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.system_picture_id = ''
@l.should_not be_valid
end
- it 'url形式でなら失敗する' do
- @l.url = ''
- pending
+ it '数値でなければ失敗する' do\r
+ @l.system_picture_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するシステム画像でなければ失敗する' do\r
+ @l.system_picture_id = 0\r
+ @l.should_not be_valid\r
+ end\r
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @lg = Factory :license_group
+ @f = Rails.root + 'spec/json/license_group.json'
+ @t = File.open(@f, 'r').read
+ @j = JSON.parse @t
+ @n = @j.keys.first
+ @a = @j.values.first
+ @attr = @a["licenses_attributes"]
+ @ln = @attr.keys.first
+ @la = @attr.values.first
+ @la["license_group_id"] = @lg.id
+ end
+ context 'つつがなく終わるとき' do
+ it 'システム画像置換を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.should_receive(:replace_system_picture).with(any_args).exactly(1)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ r = License.store(@ln, @la)
+ end
+ it 'データ更新準備を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.should_receive(:modify_object).with(any_args).exactly(1)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ r = License.store(@ln, @la)
+ end
+ it '保存を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ License.any_instance.should_receive(:save).with(any_args).exactly(1)
+ r = License.store(@ln, @la)
+ end
+ it 'オブジェクトを返す' do
+ r = License.store(@ln, @la)
+ r.is_a?(License).should be_true
+ r.name.should eq @ln
+ r.url.should eq @la["url"]
+ end
+ it 'ライセンスが作成されている' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should change License, :count
+ end
+ it 'システム画像が作成されている' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should change SystemPicture, :count
+ end
+ end
+ context 'システム画像置換が失敗するとき' do
+ before do
+ License.stub(:replace_system_picture).with(any_args).and_return(false)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ end
+ it '全体エラーメッセージがセットされている' do
+ r = License.store(@ln, @la)
+ r.errors[:base].should_not be_blank
+ end
+ it 'ライセンスが作成されていない' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should_not change License, :count
end
end
end
- describe '対象ライセンスの取得に於いて' do
+ describe '複数の更新に於いて' do
before do
- @lc = Factory :license
+ @lg = Factory :license_group
+ @fs = Rails.root + 'spec/json/license_groups.json'
+ @ts = File.open(@fs, 'r').read
+ @js = JSON.parse @ts
+ @n = @js.keys.last
+ @a = @js.values.last
+ @attr = @a["licenses_attributes"]
end
- context 'urlが一致するライセンスがないとき' do
- it '新規ライセンスを準備して返す' do
- cl = Factory.build(:common_license, :url => 'http://domain.no')
- r = License.update_license cl
- r.should be_a_new License
+ context '2件データでつつがなく終わるとき' do
+ it '更新を2回依頼する' do
+ License.stub(:store).with(any_args).and_return(License.new)
+ License.should_receive(:store).with(any_args).exactly(2)
+ License.any_instance.stub(:valid?).with(any_args).and_return(true)
+ r = License.stores(@attr, @lg.id)
+ end
+ it '失敗件数0を返す' do
+ License.stub(:store).with(any_args).and_return(License.new)
+ License.any_instance.stub(:valid?).with(any_args).and_return(true)
+ r = License.stores(@attr, @lg.id)
+ r.should eq 0
end
end
- context 'urlが一致するライセンスがあるとき' do
- it '該当ライセンスを返す' do
- r = License.update_license @lc
- r.is_a?(License).should be_true
- r.should_not be_a_new License
- r.url.should eq @lc.url
- r.name.should eq @lc.name
+ context '2件データで失敗するとき' do
+ it '更新を2回依頼する' do
+ License.stub(:store).with(any_args).and_return(License.new)
+ License.should_receive(:store).with(any_args).exactly(2)
+ License.any_instance.stub(:valid?).with(any_args).and_return(false)
+ r = License.stores(@attr, @lg.id)
+ end
+ it '失敗件数2を返す' do
+ License.stub(:store).with(any_args).and_return(License.new)
+ License.any_instance.stub(:valid?).with(any_args).and_return(false)
+ r = License.stores(@attr, @lg.id)
+ r.should eq 2
end
end
- #コモンライセンスとオリジナルライセンスをまたいだUrl重複チェックはここでやるよりない
- #コモンライセンスが新規オブジェクトなのにライセンスが取得できるのは、
- #そのUrlがオリジナルライセンスから登録されているということ
- context '新規でユニークチェックするとき' do
- it 'ライセンスの全体エラーに重複メッセージを入れて返す' do
- cl = Factory.build(:common_license, :url => 'http://domain.no')
- License.stub(:find_by_url).with(any_args).and_return(@lc)
- r = License.update_license cl
- r.errors[:base].should_not be_empty
+ context 'attrsがnilなどのHashでないとき' do
+ it '処理にかけず0を返す' do
+ r = License.stores(nil, @lg.id)
+ r.should eq 0
end
end
end
- #作成が
describe '単体取得に於いて' do
before do
- @lcl = Factory :license
- @cl = Factory :common_license, :license_id => @lcl.id
- @lol = Factory :license, :url => 'http://test.ptn/10'
- @ol = Factory :original_license, :license_id => @lol.id, :url => 'http://test.ptn/10'
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it '指定のコマを返す' do
- l = License.show @lcl.id
- l.should eq @lcl
+ l = License.show @l.id
+ l.should eq @l
end
end
describe '関連テーブルプションに於いて' do
context 'オプションがないとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_include_opt
- r.should eq [:common_license, :original_license]
+ r.should eq [:license_group]
end
end
- context 'オプションで原画を含ませたとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨å\8e\9fç\94»ã\83\87ã\83¼ã\82¿を含んでいる' do
- r = License.show_include_opt(:include => :original_picture)
- r.should eq [:common_license, :original_license, :original_picture]
+ context 'オプションで素材ライセンスを含ませたとき' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97ã\81¨ç´ æ\9d\90ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ r = License.show_include_opt(:include => :resource_picture_license)
+ r.should eq [:license_group, :resource_picture_license]
end
end
end
r = License.show_json_include_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.show_json_include_opt[:include]
- r.should have(2).items
+ r.should have(1).items
end
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_json_include_opt[:include]
- r.has_key?(:common_license).should be_true
- end
- it 'オリジナルライセンスを含んでいる' do
- r = License.show_json_include_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe '一覧取得に於いて' do
before do
- @lcl = Factory :license, :name => 'peta2.0'
- @cl = Factory :common_license, :license_id => @lcl.id
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- License.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- License.page().should eq 1
- end
- it '0以下の場合は1になる' do
- License.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- License.page_size('7').should eq 7
- end
- it 'nilの場合はLicense.default_page_sizeになる' do
- License.page_size().should eq License.default_page_size
- end
- it '0以下の場合はLicense.default_page_sizeになる' do
- License.page_size('0').should eq License.default_page_size
- end
- it 'License.max_page_sizeを超えた場合はLicense.max_page_sizeになる' do
- License.page_size('1000').should eq License.max_page_size
- end
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @lg2 = Factory :license_group, :name => 'pubdm'
end
it 'リストを返す' do
- pl = License.list
- pl.should eq [@lcl]
+ l = License.list
+ l.should eq [@l]
end
it '名前順で並んでいる' do
- @lol = Factory :license, :name => 'peta1.0', :url => 'http://test.ptn/10'
- @ol = Factory :original_license, :license_id => @lol.id, :name => 'peta1.0', :url => 'http://test.ptn/10'
+ @l2 = Factory :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @l3 = Factory :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
l = License.list
- l.should eq [@lol, @lcl]
- end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- @lol2 = Factory :license, :name => 'peta2.1', :url => 'http://test.ptn/21'
- @ol2 = Factory :original_license, :license_id => @lol2.id, :name => 'peta2.1', :url => 'http://test.ptn/21'
- @lol3 = Factory :license, :name => 'peta2.2', :url => 'http://test.ptn/22'
- @ol3 = Factory :original_license, :license_id => @lol3.id, :name => 'peta2.2', :url => 'http://test.ptn/22'
- @lol4 = Factory :license, :name => 'peta2.3', :url => 'http://test.ptn/23'
- @ol4 = Factory :original_license, :license_id => @lol4.id, :name => 'peta2.3', :url => 'http://test.ptn/23'
- @lol5 = Factory :license, :name => 'peta2.4', :url => 'http://test.ptn/24'
- @ol5 = Factory :original_license, :license_id => @lol5.id, :name => 'peta2.4', :url => 'http://test.ptn/24'
- License.stub(:default_page_size).and_return(2)
- end
- it '通常は2件を返す' do
- l = License.list
- l.should have(2).items
- end
- it 'page=1なら末尾2件を返す' do
- #名前順で並んでいる
- l = License.list( {}, 1)
- l.should eq [@lcl, @lol2]
- end
- it 'page=2なら中間2件を返す' do
- l = License.list({}, 2)
- l.should eq [@lol3, @lol4]
- end
- it 'page=3なら先頭1件を返す' do
- l = License.list({}, 3)
- l.should eq [@lol5]
- end
+ l.should eq [@l3, @l, @l2]
end
end
describe 'list関連テーブルプションに於いて' do
r = License.list_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_opt[:include]
- r.should have(2).items
+ r.should have(1).items
end
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_opt[:include]
- r.has_key?(:common_license).should be_true
- end
- it 'オリジナルライセンスを含んでいる' do
- r = License.list_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
r = License.list_json_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
- r = License.list_json_opt[:include]
- r.should have(2).items
- end
- it 'コモンライセンスを含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:common_license).should be_true
+ r.should have(1).items
end
- it 'ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
-# -*- encoding: utf-8 -*-
-#オリジナルライセンス
-require 'spec_helper'
-
-describe OriginalLicense do
- before do
- #テストデータを用意してね
- @f = Rails.root + 'spec/json/original_license.json'
- @t = File.open(@f, 'r').read
- @j = JSON.parse @t
- @fs = Rails.root + 'spec/json/original_licenses.json'
- @ts = File.open(@fs, 'r').read
- @js = JSON.parse @ts
- @fes = Rails.root + 'spec/json/invalid_original_licenses.json'
- @tes = File.open(@fes, 'r').read
- @jes = JSON.parse @tes
- end
- describe '検証に於いて' do
- before do
- @l = Factory :license
- end
-
- it 'オーソドックスなデータなら通る' do
- @ol = Factory.build :original_license, :license_id => @l.id
- @ol.should be_valid
- end
-
- context 'nameを検証するとき' do
- before do
- @ol = Factory.build :original_license, :license_id => @l.id
- end
- it 'テストデータの確認' do
- @ol.name = 'CC by'
- @ol.should be_valid
- end
- it 'nullなら失敗する' do
- @ol.name = ''
- @ol.should_not be_valid
- end
- it '51文字以上なら失敗する' do
- @ol.name = 'a'*51
- @ol.should_not be_valid
- end
- end
- context 'urlを検証するとき' do
- before do
- @ol = Factory.build :original_license, :license_id => @l.id
- end
- it 'テストデータの確認' do
- @ol.url = 'CC by'
- @ol.should be_valid
- end
- it 'nullなら失敗する' do
- @ol.url = ''
- @ol.should_not be_valid
- end
- it '201文字以上なら失敗する' do
- @ol.url = 'a'*201
- @ol.should_not be_valid
- end
- it '重複していたら失敗する' do
- cl = Factory :original_license, :license_id => @l.id
- @ol.should_not be_valid
- end
- it 'url形式でなら失敗する' do
- @ol.url = ''
- pending
- end
- end
- context 'license_idを検証するとき' do
- before do
- @ol = Factory.build :original_license
- end
- it 'テストデータの確認' do
- @ol.license_id = @l.id
- @ol.should be_valid
- end
- it 'nullなら失敗する' do
- @ol.license_id = nil
- @ol.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @ol.license_id = 'a'
- @ol.should_not be_valid
- end
- it '存在するlicenseでなければ失敗する' do
- @ol.license_id = 0
- @ol.should_not be_valid
- end
- end
- end
-
- describe '対象オリジナルライセンスの取得に於いて' do
- before do
- @lc = Factory :license
- @ol = Factory :original_license, :license_id => @lc.id
- end
- context 'urlが一致するオリジナルライセンスがないとき' do
- it '新規オリジナルライセンスを準備して返す' do
- r = OriginalLicense.update_original_license Factory.attributes_for(:original_license, :url => 'http://domain.no')
- r.should be_a_new OriginalLicense
- end
- end
- context 'urlが一致するオリジナルライセンスがあるとき' do
- it '該当オリジナルライセンスを返す' do
- prm = Factory.attributes_for(:original_license)
- r = OriginalLicense.update_original_license prm
- r.is_a?(OriginalLicense).should be_true
- r.should_not be_a_new OriginalLicense
- r[:url].should eq prm[:url]
- end
- end
- end
-
- describe 'オリジナルライセンス更新に於いて' do
- before do
- @lc = Factory :license
- @ol = Factory :original_license, :license_id => @lc.id, :url => @lc.url
- @attr = Factory.attributes_for(:original_license, :name => 'exist case', :url => @lc.url)
- @newattr = Factory.attributes_for(:original_license, :url => 'http://domain.no')
- end
- context 'つつがなく終わるとき' do
- it '対象オリジナルライセンスを問い合わせている' do
- OriginalLicense.stub(:update_original_license).with(any_args).and_return(OriginalLicense.new(@attr))
- OriginalLicense.should_receive(:update_original_license).exactly(1)
- OriginalLicense.store @attr
- end
- context '新規のとき' do
- it 'オリジナルライセンスを保存しようとしている' do
- OriginalLicense.any_instance.should_receive(:save).exactly(1)
- OriginalLicense.store @newattr
- end
- it 'オリジナルライセンスが作成されている' do
- lambda {
- OriginalLicense.store @newattr
- }.should change OriginalLicense, :count
- end
- context 'ライセンスとの連動' do
- it 'ライセンスが作成されている' do
- lambda {
- OriginalLicense.store @newattr
- }.should change License, :count
- end
- it '両者がリンクされている' do
- r = OriginalLicense.store @newattr
- l = License.find(r.license_id)
- l.should be_true
- end
- it '属性が一致している' do
- r = OriginalLicense.store @newattr
- l = License.find(r.license_id)
- l.url.should eq r.url
- l.name.should eq r.name
- end
- end
- end
- context '更新のとき' do
- it 'オリジナルライセンスを保存しようとしている' do
- OriginalLicense.any_instance.should_receive(:save).exactly(1)
- OriginalLicense.store @attr
- end
- it 'オリジナルライセンスの数に変化がない' do
- lambda {
- OriginalLicense.store @attr
- }.should_not change OriginalLicense, :count
- end
- context 'ライセンスとの連動' do
- it 'ライセンスの数に変化がない' do
- lambda {
- OriginalLicense.store @attr
- }.should_not change License, :count
- end
- it '両者がリンクされている' do
- r = OriginalLicense.store @attr
- l = License.find(r.license_id)
- l.should be_true
- end
- it '属性が一致している' do
- r = OriginalLicense.store @attr
- l = License.find(r.license_id)
- l.url.should eq r.url
- l.name.should eq r.name
- end
- end
- end
- it '属性が一致している' do
- r = OriginalLicense.store @newattr
- r.url.should eq @newattr[:url]
- r.name.should eq @newattr[:name]
- end
- it '保存されたOriginalLicenseオブジェクトを返す' do
- r = OriginalLicense.store @newattr
- r.should_not be_a_new OriginalLicense
- end
- end
- context 'ライセンスの作成に失敗するとき' do
- before do
- License.any_instance.stub(:save).with(any_args).and_return(false)
- end
- context '新規のとき' do
- it 'ライセンスに変化がない' do
- lambda {
- r = OriginalLicense.store @newattr
- }.should_not change License, :count
- end
- it 'オリジナルライセンスに変化がない' do
- lambda {
- r = OriginalLicense.store @newattr
- }.should_not change OriginalLicense, :count
- end
- end
- context '更新のとき' do
- it 'オリジナルライセンス属性に変化がない' do
- lambda {
- r = OriginalLicense.store @attr
- }.should_not change License.find(@ol.id), :name
- end
- it 'ライセンス属性に変化がない' do
- lambda {
- r = OriginalLicense.store @attr
- }.should_not change License.find(@lc.id), :name
- end
- end
- end
- context 'オリジナルライセンスの作成に失敗するとき' do
- before do
- OriginalLicense.any_instance.stub(:save).with(any_args).and_return(false)
- end
- context '新規のとき' do
- it 'ライセンスに変化がない' do
- lambda {
- r = OriginalLicense.store @newattr
- }.should_not change License, :count
- end
- it 'オリジナルライセンスに変化がない' do
- lambda {
- r = OriginalLicense.store @newattr
- }.should_not change OriginalLicense, :count
- end
- end
- context '更新のとき' do
- it 'オリジナルライセンス属性に変化がない' do
- lambda {
- r = OriginalLicense.store @attr
- }.should_not change License.find(@ol.id), :name
- end
- it 'ライセンス属性に変化がない' do
- lambda {
- r = OriginalLicense.store @attr
- }.should_not change License.find(@lc.id), :name
- end
- end
- end
- end
-
- describe '単体取得に於いて' do
- before do
- @ol = Factory.build :original_license
- @ol.store
- end
- it '指定のライセンスを返す' do
- l = OriginalLicense.show @ol.id
- l.should eq @ol
- end
- context '関連テーブルオプションがないとき' do
- it 'ライセンスだけを含んでいる' do
- r = OriginalLicense.show_include_opt
- r.should eq [:license]
- end
- end
- context '関連テーブルオプションで作家を含ませたとき' do
- it 'ライセンスと作家を含んでいる' do
- r = OriginalLicense.show_include_opt(:include => :author)
- r.should eq [:license, :author]
- end
- end
- end
- describe '一覧取得に於いて' do
- before do
- @ol = Factory.build :original_license
- @ol.store
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- OriginalLicense.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- OriginalLicense.page().should eq 1
- end
- it '0以下の場合は1になる' do
- OriginalLicense.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- OriginalLicense.page_size('7').should eq 7
- end
- it 'nilの場合はOriginalLicense.default_page_sizeになる' do
- OriginalLicense.page_size().should eq OriginalLicense.default_page_size
- end
- it '0以下の場合はOriginalLicense.default_page_sizeになる' do
- OriginalLicense.page_size('0').should eq OriginalLicense.default_page_size
- end
- it 'OriginalLicense.max_page_sizeを超えた場合はOriginalLicense.max_page_sizeになる' do
- OriginalLicense.page_size('1000').should eq OriginalLicense.max_page_size
- end
- end
- it 'リストを返す' do
- l = OriginalLicense.list
- l.should eq [@ol]
- end
- it '名前順で並んでいる' do
- n = Factory.build :original_license, :url => 'http://tes.to', :name => 'peta2.2'
- n.store
- l = OriginalLicense.list
- l.should eq [@ol, n]
- end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- @license2 = Factory.build :original_license, :url => 'http://tes.to2', :name => 'peta2.2'
- @license2.store
- @license3 = Factory.build :original_license, :url => 'http://tes.to3', :name => 'peta2.3'
- @license3.store
- @license4 = Factory.build :original_license, :url => 'http://tes.to4', :name => 'peta2.4'
- @license4.store
- @license5 = Factory.build :original_license, :url => 'http://tes.to5', :name => 'peta2.5'
- @license5.store
- OriginalLicense.stub(:default_page_size).and_return(2)
- end
- it '通常は2件を返す' do
- l = OriginalLicense.list
- l.should have(2).items
- end
- it 'page=1なら末尾2件を返す' do
- #時系列で並んでいる
- l = OriginalLicense.list({}, 1)
- l.should eq [@ol, @license2]
- end
- it 'page=2なら中間2件を返す' do
- l = OriginalLicense.list({}, 2)
- l.should eq [@license3, @license4]
- end
- it 'page=3なら先頭1件を返す' do
- l = OriginalLicense.list({}, 3)
- l.should eq [@license5]
- end
- end
- end
-
- describe 'Json解析に於いて' do
- before do
- end
- context 'テキストを渡されたとき' do
- it 'Json解析している' do
- JSON.should_receive(:parse).with(@t).exactly(1)
- r = OriginalLicense.parse @t
- end
- it '単数データならHashで返す' do
- r = OriginalLicense.parse @t
- r.is_a?(Hash).should be_true
- end
- it '複数データならArrayで返す' do
- r = OriginalLicense.parse @ts
- r.is_a?(Array).should be_true
- end
- end
- context 'パース失敗したとき' do
- it 'Falseを返す' do
- JSON.should_receive(:parse).with(any_args).and_raise('StandardError')
- r = OriginalLicense.parse @t
- r.should be_false
- end
- end
- end
-
- describe 'Jsonの繰り返し処理に於いて' do
- before do
- end
- context '単体データを渡されたとき' do
- it '一回処理' do
- r = []
- OriginalLicense.each_license @j do |i|
- r << i
- end
- r.size.should eq 1
- end
- end
- context '複数を渡されたとき' do
- it '二回処理' do
- r = []
- OriginalLicense.each_license @js do |i|
- r << i
- end
- r.size.should eq 2
- end
- end
- end
-
- describe 'テキスト取り込みに於いて' do
- #成功でTrue、パース失敗でFalse、失敗は保存エラーのモデルを配列で返す
- #Licenseとの連動が完成していること
- before do
- end
- context 'つつがなく終わるとき' do
- it 'Json解析を依頼する' do
- OriginalLicense.should_receive(:parse).with(any_args).exactly(1)
- OriginalLicense.stub(:parse).with(any_args).and_return(@j)
- OriginalLicense.import(@t)
- end
- it '繰り返し処理を依頼する' do
- OriginalLicense.should_receive(:each_license).with(any_args).exactly(1)
- OriginalLicense.import(@t)
- end
- it 'ライセンス更新を一回依頼する' do
- OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
- OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
- OriginalLicense.should_receive(:store).with(any_args).exactly(1)
- OriginalLicense.import(@t)
- end
- it 'オリジナルライセンスが追加される' do
- lambda {
- OriginalLicense.import(@t)
- }.should change OriginalLicense, :count
- end
- it '[]を返す' do
- OriginalLicense.import(@t).should eq []
- end
- end
- context '複数データがつつがなく終わるとき' do
- it 'ライセンス更新を二回依頼する' do
- OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
- OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
- OriginalLicense.should_receive(:store).with(any_args).exactly(2)
- OriginalLicense.import(@ts)
- end
- it 'オリジナルライセンスが二個追加される' do
- lambda {
- OriginalLicense.import(@ts)
- }.should change(OriginalLicense, :count).by 2
- end
- it '[]を返す' do
- OriginalLicense.import(@ts).should eq []
- end
- end
- #例外ケース
- context 'Json解析に失敗したとき' do
- before do
- OriginalLicense.stub(:parse).with(any_args).and_return(false)
- end
- it 'オリジナルライセンスの数に変化がない' do
- lambda {
- OriginalLicense.import(@t)
- }.should_not change OriginalLicense, :count
- end
- it 'Falseを返す' do
- OriginalLicense.import(@t).should be_false
- end
- end
- context 'オリジナルライセンス作成に失敗したとき' do
- before do
- OriginalLicense.any_instance.stub(:save).with(any_args).and_return(false)
- OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
- end
- it 'オリジナルライセンスの数に変化がない' do
- lambda {
- OriginalLicense.import(@t)
- }.should_not change OriginalLicense, :count
- end
- it '配列を返す' do
- r = OriginalLicense.import(@t)
- r.is_a?(Array).should be_true
- end
- it '配列の中身は一件' do
- r = OriginalLicense.import(@t)
- r.should have(1).items
- end
- it 'オリジナルライセンスオブジェクトが入っている' do
- r = OriginalLicense.import(@t)
- r.first.is_a?(OriginalLicense).should be_true
- end
- end
- context '複数のオリジナルライセンス作成に失敗したとき' do
- #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
- it 'オリジナルライセンスの数に変化がない' do
- lambda {
- OriginalLicense.import(@tes)
- }.should_not change OriginalLicense, :count
- end
- it '途中で保存に失敗しても全件更新依頼する' do
- OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
- OriginalLicense.should_receive(:store).with(any_args).exactly(3)
- OriginalLicense.import(@tes)
- end
- it '配列を返す' do
- r = OriginalLicense.import(@tes)
- r.is_a?(Array).should be_true
- end
- it '配列の中身は2件' do
- r = OriginalLicense.import(@tes)
- r.should have(2).items
- end
- it '配列の中身は失敗したオリジナルライセンスオブジェクトが入っている' do
- r = OriginalLicense.import(@tes)
- r[0].is_a?(OriginalLicense).should be_true
- r[0]["name"].should eq 'fail1'
- r[1].is_a?(OriginalLicense).should be_true
- r[1]["name"].should eq 'fail2'
- end
- end
- end
-
- describe 'ファイル取り込みに於いて' do
- before do
- OriginalLicense.stub(:import).with(any_args).and_return(true)
- end
- context 'つつがなく終わるとき' do
- before do
- OriginalLicense.stub(:import).with(any_args).and_return(true)
- end
- it 'ファイルを開いてテキストを読む' do
- File.should_receive(:open).with(@f, 'r').exactly(1)
- OriginalLicense.import_file(@f)
- end
- it 'テキスト取り込みを依頼する' do
- OriginalLicense.should_receive(:import).with(any_args).exactly(1)
- OriginalLicense.import_file(@f)
- end
- #テキスト取り込み成功でTrueが返る
- it 'Trueを返す' do
- OriginalLicense.import_file(@f).should be_true
- end
- end
- context 'ファイルが開けないとき' do
- before do
- File.stub(:open).with(any_args).and_raise('StandardError')
- end
- it 'ファイルエラーのメッセージを出力する' do
- pending
- end
- it 'Falseを返す' do
- OriginalLicense.import_file(@f).should be_false
- end
- end
- #失敗したときは、失敗したライセンスが配列で返る
- context 'テキスト取り込みが失敗したとき' do
- before do
- OriginalLicense.stub(:import).with(any_args).and_return(false)
- end
- it '各オリジナルライセンスのエラーメッセージを出力する' do
- pending
- end
- it 'Falseを返す' do
- OriginalLicense.import_file(@f).should be_false
- end
- end
- end
-
-end
--- /dev/null
+# -*- encoding: utf-8 -*-
+#原画ライセンスグループ
+require 'spec_helper'
+
+describe OriginalPictureLicenseGroup do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @other_user = Factory( :user_yas)
+ @other_author = @other_user.author
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @ol = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @ol.should be_valid
+ end
+
+ context 'original_picture_idを検証するとき' do
+ before do
+ @ol = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ end
+ it 'テストデータの確認' do
+ @ol.original_picture_id = @op.id
+ @ol.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @ol.original_picture_id = nil
+ @ol.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @ol.original_picture_id = 'a'
+ @ol.should_not be_valid
+ end
+ it '存在する原画でなければ失敗する' do
+ @ol.original_picture_id = 0
+ @ol.should_not be_valid
+ end
+ end
+ context 'license_group_idを検証するとき' do
+ before do
+ @ol = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ end
+ it 'テストデータの確認' do
+ @ol.license_group_id = @lg.id
+ @ol.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @ol.license_group_id = nil
+ @ol.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @ol.license_group_id = 'a'
+ @ol.should_not be_valid
+ end
+ it '存在するライセンスグループでなければ失敗する' do
+ @ol.license_group_id = 0
+ @ol.should_not be_valid
+ end
+ end
+ end
+ describe '補充に於いて' do
+ it '原画idを補充している' do
+ @ol = OriginalPictureLicenseGroup.new
+ @ol.original_picture_id = nil
+ @ol.supply_default 5
+ @ol.original_picture_id.should eq 5
+ end
+ end
+end
@other_user = Factory( :user_yas)
@other_author = @other_user.author
@other_artist = Factory :artist_yas, :author_id => @other_author.id
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
describe '検証に於いて' do
end
it 'オーソドックスなデータなら通る' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id
@op.should be_valid
end
context 'extを検証するとき' do
before do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id
end
it 'テストデータの確認' do
@op.ext = 'jpeg'
end
context 'widthを検証するとき' do
before do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id
end
it 'テストデータの確認' do
@op.width = 1
end
context 'heightを検証するとき' do
before do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id
end
it 'テストデータの確認' do
@op.height = 1
end
context 'filesizeを検証するとき' do
before do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id
end
it 'テストデータの確認' do
@op.filesize = 1
end
context 'artist_idを検証するとき' do
before do
- @op = Factory.build :original_picture, :license_id => @license.id
+ @op = Factory.build :original_picture
end
it 'テストデータの確認' do
@op.artist_id = @artist.id
@op.should_not be_valid
end
end
- context 'license_idを検証するとき' do
- before do
- @op = Factory.build :original_picture, :artist_id => @artist.id
- end
- it 'テストデータの確認' do
- @op.license_id = @license.id
- @op.should be_valid
- end
- it 'nullなら失敗する' do
- @op.license_id = nil
- @op.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @op.license_id = 'a'
- @op.should_not be_valid
- end
- it '存在するlicenseでなければ失敗する' do
- @op.license_id = 0
- @op.should_not be_valid
- end
- end
end
describe 'データ補充に於いて' do
pic = OriginalPicture.show @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, @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{
end
end
describe 'json単体出力オプションに於いて' do
- it 'includeキーがライセンスと素材を含んでいる' do
- r = OriginalPicture.show_json_include_opt
- r[:include].should eq [:license, :resource_picture]
- end
+ it 'includeキーを含んでいる' do\r
+ r = OriginalPicture.show_json_include_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = OriginalPicture.show_json_include_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it '素材を含んでいる' do\r
+ r = OriginalPicture.show_json_include_opt[:include]\r
+ r.has_key?(:resource_picture).should be_true\r
+ end\r
end
describe '一覧取得に於いて' do
before do
end
end
end
- describe 'json一覧出力オプションに於いて' do
- it 'includeキーがライセンスと素材を含んでいる' do
- r = OriginalPicture.list_json_opt
- r[:include].should eq [:license, :resource_picture]
- end
+ describe 'list関連テーブルプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = OriginalPicture.list_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = OriginalPicture.list_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it '素材を含んでいる' do\r
+ r = OriginalPicture.list_opt[:include]\r
+ r.has_key?(:resource_picture).should be_true\r
+ end\r
end
+ describe 'json一覧出力オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = OriginalPicture.list_json_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '1つの項目を含んでいる' do\r
+ r = OriginalPicture.list_json_opt[:include]\r
+ r.should have(1).items\r
+ end\r
+ it '素材を含んでいる' do\r
+ r = OriginalPicture.list_json_opt[:include]\r
+ r.has_key?(:resource_picture).should be_true\r
+ end\r
+ end\r
describe 'RMagick変換に於いて' do
before do
@op = Factory.build :original_picture, :artist_id => @artist.id
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
- ResourcePicture.any_instance.stub(:store).with(any_args).and_return(true)
end
it 'RMagick変換を依頼している' do
OriginalPicture.any_instance.should_receive(:data_to_mgk).exactly(1)
- @op.store 'bindata', @artist, @license.id\r
+ @op.store 'bindata', @artist\r
end
it '自身に属性をセットしている' do
OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
- @op.store 'bindata', @artist, @license.id\r
+ @op.store 'bindata', @artist\r
end
it '自身が保存されている' do
OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
- @op.store 'bindata', @artist, @license.id\r
+ @op.store 'bindata', @artist\r
end
it 'PictureIoに画像データの保存を依頼している' do
PictureIO::LocalPicture.any_instance.should_receive(:put).with(any_args).exactly(1)
- @op.store 'bindata', @artist, @license.id\r
- end
- it '素材モデルに対象素材を問い合わせている' do
- ResourcePicture.should_receive(:update_picture).with(any_args).exactly(1)
- @op.store 'bindata', @artist, @license.id\r
- end
- it '対象素材オブジェクトに保存を依頼している' do
- ResourcePicture.any_instance.should_receive(:store).with(any_args).exactly(1)
- @op.store 'bindata', @artist, @license.id\r
+ @op.store 'bindata', @artist\r
end
end
context 'つつがなく終わるとき' do
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
# OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
- ResourcePicture.any_instance.stub(:store).with(any_args).and_return(true)
end
it '自身に属性をセットしている' do
lambda {
- @op.store 'bindata', @artist, @license.id\r
+ @op.store 'bindata', @artist\r
}.should change @op, :filesize
end
it '原画モデルが作成されている' do
lambda {
- @op.store 'bindata', @artist, @license.id
+ @op.store 'bindata', @artist
}.should change OriginalPicture, :count
end
it '原画が保存されている' do
- @op.store 'bindata', @artist, @license.id
+ @op.store 'bindata', @artist
OriginalPicture.find(@op).should_not be_nil\r
end
it 'Trueを返す' do
- @op.store('bindata', @artist, @license.id).should eq true\r
+ @op.store('bindata', @artist).should eq true\r
end
end
#以下から例外ケース。処理先頭から失敗させていく
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(false)
end
it 'falseを返す' do
- @op.store('bindata', @artist, @license.id).should be_false\r
+ @op.store('bindata', @artist).should be_false\r
end
it '自身の保存は呼ばれていない' do
OriginalPicture.any_instance.should_not_receive(:save)\r
+ @op.store('bindata', @artist)\r
end
end
context '自身の保存に失敗したとき' do
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)\r
end
it 'falseを返す' do
- @op.store('bindata', @artist, @license.id).should be_false\r
+ @op.store('bindata', @artist).should be_false\r
end
it '更新されていない' do
- @op.store('bindata', @artist, @license.id)
+ @op.store('bindata', @artist)
@op.should be_a_new OriginalPicture\r
end
it '原画の保存は呼ばれていない' do
PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(false)
end
it 'falseを返す' do
- @op.store('bindata', @artist, @license.id).should be_false\r
+ @op.store('bindata', @artist).should be_false\r
end
it '更新されていない' do
- @op.store('bindata', @artist, @license.id)\r
+ @op.store('bindata', @artist)\r
@op.should be_a_new OriginalPicture\r
end
it '対象素材オブジェクトの保存は呼ばれていない' do
ResourcePicture.any_instance.should_not_receive(:save)\r
- @op.store('bindata', @artist, @license.id)\r
- end
- it '全体エラーメッセージがセットされている' do
- lambda {
- @op.store('bindata', @artist, @license.id)\r
- }.should change(@op.errors[:base], :count)
- end
- end
- context '対象素材オブジェクトの保存に失敗したとき' do
- before do
- OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
- OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
- PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
- ResourcePicture.any_instance.stub(:store).with(any_args).and_return(false)
- end
- it 'falseを返す' do
- @op.store('bindata', @artist, @license.id).should be_false\r
- end
- it '更新されていない' do
- @op.store('bindata', @artist, @license.id)\r
- @op.should be_a_new OriginalPicture\r
+ @op.store('bindata', @artist)\r
end
it '全体エラーメッセージがセットされている' do
lambda {
- @op.store('bindata', @artist, @license.id)\r
+ @op.store('bindata', @artist)\r
}.should change(@op.errors[:base], :count)
end
end
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
- @license = Factory :license
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
@panel = Factory :panel, :author_id => @author.id
end
before do
@pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id
end
+ #ネストの保存はnilを許可しなければならないので数値チェックだけ
it 'テストデータの確認' do
@pp.panel_id = @panel.id
@pp.should be_valid
@pp.should_not be_valid
end
end
- context 'resource_picture_idを検証するとき' do
- before do
- @pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id
- end
- it 'テストデータの確認' do
- @pp.resource_picture_id = @rp.id
- @pp.should be_valid
- end
- it 'nullなら失敗する' do
- @pp.resource_picture_id = nil
- @pp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @pp.resource_picture_id = 'a'
- @pp.should_not be_valid
- end
- it '存在するフキダシテンプレートでなければ失敗する' do
- @pp.resource_picture_id = 0
- @pp.should_not be_valid
- end
- end
context 'linkを検証するとき' do
before do
@pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id
describe Panel do\r
before do\r
Factory :admin\r
- @license = Factory :license\r
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)\r
@author = @user.author\r
@artist = Factory :artist_yas, :author_id => @author.id\r
@other_user = Factory( :user_yas)\r
@other_author = @other_user.author\r
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
- @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id\r
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id\r
+ @op = Factory :original_picture, :artist_id => @artist.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
@sbt = Factory :speech_balloon_template\r
end\r
\r
--- /dev/null
+# -*- encoding: utf-8 -*-
+#実素材
+require 'spec_helper'
+
+describe Picture do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @other_user = Factory( :user_yas)
+ @other_author = @other_user.author
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ @p.should be_valid
+ end
+
+ context 'original_picture_idを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.original_picture_id = @op.id
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.original_picture_id = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.original_picture_id = 'a'
+ @p.should_not be_valid
+ end
+ it '存在する原画でなければ失敗する' do
+ @p.original_picture_id = 0
+ @p.should_not be_valid
+ end
+ end
+ context 'revisionを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.revision = 1
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.revision = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.revision = 'a'
+ @p.should_not be_valid
+ end
+ end
+ context 'extを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.ext = 'jpeg'
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.ext = ''
+ @p.should_not be_valid
+ end
+ it '5文字以上なら失敗する' do
+ @p.ext = 'a'*5
+ @p.should_not be_valid
+ end
+ it 'png,gif,jpeg以外なら失敗する' do
+ @p.ext = 'bmp'
+ @p.should_not be_valid
+ end
+ end
+ context 'widthを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.width = 1
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.width = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.width = 'a'
+ @p.should_not be_valid
+ end
+ it '0なら失敗する' do
+ @p.width = '0'
+ @p.should_not be_valid
+ end
+ it '負でも失敗する' do
+ @p.width = -1
+ @p.should_not be_valid
+ end
+ end
+ context 'heightを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.height = 1
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.height = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.height = 'a'
+ @p.should_not be_valid
+ end
+ it '0なら失敗する' do
+ @p.height = '0'
+ @p.should_not be_valid
+ end
+ it '負でも失敗する' do
+ @p.height = -1
+ @p.should_not be_valid
+ end
+ end
+ context 'filesizeを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.filesize = 1
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.filesize = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.filesize = 'a'
+ @p.should_not be_valid
+ end
+ it '負なら失敗する' do
+ @p.filesize = '-1'
+ @p.should_not be_valid
+ end
+ it '2MB以上なら失敗する' do
+ @p.filesize = 2000000+1
+ @p.should_not be_valid
+ end
+ end
+ context 'artist_idを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.artist_id = @artist.id
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.artist_id = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.artist_id = 'a'
+ @p.should_not be_valid
+ end
+ it '存在する絵師でなければ失敗する' do
+ @p.artist_id = 0
+ @p.should_not be_valid
+ end
+ end
+ context 'license_idを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.license_id = @license.id
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.license_id = nil
+ @p.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @p.license_id = 'a'
+ @p.should_not be_valid
+ end
+ it '存在するライセンスグループでなければ失敗する' do
+ @p.license_id = 0
+ @p.should_not be_valid
+ end
+ end
+ context 'artist_nameを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.artist_name = 'a'
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.artist_name = nil
+ @p.should_not be_valid
+ end
+ end
+ context 'classnameを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.classname = 'a'*50
+ @p.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @p.classname = ''
+ @p.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @p.classname = 'a'*51
+ @p.should_not be_valid
+ end
+ end
+ context 'creditを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.credit = 'a'
+ @p.should be_valid
+ end
+ end
+ context 'settingsを検証するとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @p.settings = 'a'
+ @p.should be_valid
+ end
+ end
+ end
+ describe '補充に於いて' do
+ end
+ describe '最新Revision取得に於いて' do
+ context '初めての原画を公開したとき' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Revisionは1となる' do
+ @p.new_revision.should eq 1
+ end
+ end
+ context 'HEADが1のとき' do
+ before do
+ Factory :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Revisionは2となる' do
+ @p.new_revision.should eq 2
+ end
+ end
+ context 'HEADが5のとき' do
+ before do
+ Factory :picture, :revision => 1, :original_picture_id => @op.id, :license_id => @license.id
+ Factory :picture, :revision => 5, :original_picture_id => @op.id, :license_id => @license.id
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Revisionは6となる' do
+ @p.new_revision.should eq 6
+ end
+ end
+ end
+ describe '素材からのコピーデータセットに於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ attr = {:ext => 'jpeg', :width => 264, :height => 265, :filesize => 266,
+ :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 = Factory.build :resource_picture, attr
+ @p = Factory.build :picture
+ end
+ it '素材オブジェクトから属性を取り出して対象実素材にセットしている' do
+ res = @p.copy_data(@rp)
+ @p.ext.should eq 'jpeg'
+ @p.width.should eq 264
+ @p.height.should eq 265
+ @p.filesize.should eq 266
+ @p.artist_id.should eq @artist.id
+ @p.license_id.should eq @license.id
+ @p.original_picture_id.should eq @op.id
+ @p.artist_name.should eq 'tester'
+ @p.classname.should eq 'Tester'
+ @p.credit.should match /title/
+ @p.settings.should match /set/
+ end
+ end
+
+ describe '作成に於いて' do
+ before do
+ #RMagickのスタブをおいておく
+ class Mgk ; class Image ; end ; end
+ @filesize = 76543
+ Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
+ Mgk.any_instance.stub(:format).with(any_args).and_return('png')
+ Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
+ Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
+ Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize)
+ Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
+ #原画ファイル削除だけは必ず成功するものとしておく
+ PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
+ end
+ context '事前チェック' do
+ before 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)
+ class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
+ @gifmgk = GifMgk.new #パラメータを二種類用意する。
+ Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it '最新Revisionを取得している' do
+ Picture.any_instance.should_receive(:new_revision).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ it '自身を保存している' do
+ Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ it '画像ファイルの作成機能で画像を保存している' do
+ mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
+ Picture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
+ res = @p.store(mgk)
+ end
+ it '自身にgifフォーマット変換対象かを問い合わせている' do
+ Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ it '自身にGifフォーマット変換を依頼している' do
+ Picture.should_receive(:png_to_gif).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ it '画像ファイルの作成機能でgif画像を保存している' do
+ #二回目の保存はgif変換の結果を渡す。
+ Picture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before 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)
+ class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
+ @gifmgk = GifMgk.new #パラメータを二種類用意する。
+ Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ @p = Factory.build :picture, :revision => nil, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Trueを返す' do
+ res = @p.store(Mgk.new)
+ res.should be_true
+ end
+ it 'Revisionに最新Revisionセット' do
+ res = @p.store(Mgk.new)
+ @p.revision.should eq 1
+ end
+ it '自身が保存されている' do
+ lambda {
+ res = @p.store(Mgk.new)
+ }.should change Picture, :count
+ end
+ end
+ context 'gif変換なしで、つつがなく終わるとき' do
+ before 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(false)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Trueを返す' do
+ res = @p.store(Mgk.new)
+ res.should be_true
+ end
+ it 'gif保存は呼ばれていない' do
+ #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
+ Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ end
+ #以下から例外ケース。処理先頭から失敗させていく
+ context '自身の保存に失敗したとき' do
+ before do
+ Picture.any_instance.stub(:save).with(any_args).and_return(false)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Falseを返す' do
+ res = @p.store(Mgk.new)
+ res.should be_false
+ end
+ it '更新されていない' do
+ @p.store(Mgk.new)
+ @p.should be_a_new Picture
+ end
+ end
+ context '画像の保存に失敗したとき' do
+ before do
+ Picture.any_instance.stub(:save).with(any_args).and_return(true)
+ Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Falseを返す' do
+ res = @p.store(Mgk.new)
+ res.should be_false
+ end
+ it 'gif変換判定は呼ばれていない' do
+ Picture.any_instance.should_not_receive(:to_gif?).with(any_args)
+ res = @p.store(Mgk.new)
+ end
+ end
+ context 'gif変換に失敗したとき' do
+ before 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)
+ Picture.stub(:png_to_gif).with(any_args).and_return(false)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Falseを返す' do
+ res = @p.store(Mgk.new)
+ res.should be_false
+ end
+ it 'gif画像の保存は呼ばれていない' do
+ #本画像の保存があるので、一度は呼ばれる
+ Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
+ res = @p.store(Mgk.new)
+ end
+ end
+ context 'gif画像の保存に失敗したとき' do
+ before do
+ @mgk = Mgk.new
+ Picture.any_instance.stub(:save).with(any_args).and_return(true)
+ Picture.any_instance.stub(:store_picture).with(@mgk).and_return(true)
+ Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
+ class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために
+ @gifmgk = GifMgk.new #パラメータを二種類用意する。
+ Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ Picture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ it 'Falseを返す' do
+ res = @p.store(@mgk)
+ res.should be_false
+ end
+ end
+ end
+
+ describe '反転画像の保存先に於いて' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ context '禁止のとき' do
+ it 'ベースディレクトリだけを返す' do
+ Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
+ r = @p.subdirs
+ r.should have(1).item
+ end
+ it 'ベースディレクトリだけを返す' do
+ Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
+ r = @p.subdirs
+ r.first.should eq ''
+ end
+ end
+ context '許可のとき' do
+ it 'ベースディレクトリと反転3種を返す' do
+ Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
+ r = @p.subdirs
+ r.should have(4).item
+ end
+ it 'ベースディレクトリと反転3種を返す' do
+ Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
+ r = @p.subdirs
+ r.last.should eq 'vh'
+ end
+ end
+ end
+
+ describe '画像ファイルの作成に於いて' do
+ #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
+ before do
+ #RMagickのスタブをおいておく
+ class Mgk ; class Image ; end ; end
+ @filesize = 76543
+ Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
+ Mgk.any_instance.stub(:format).with(any_args).and_return('png')
+ Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
+ Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
+ Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize)
+ Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
+ #原画ファイル削除だけは必ず成功するものとしておく
+ 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'])
+ Picture.any_instance.stub(:h).with(any_args).and_return('data')
+ Picture.any_instance.stub(:v).with(any_args).and_return('data')
+ Picture.any_instance.stub(:vh).with(any_args).and_return('data')
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+ end
+ context '事前チェック' do
+ before do
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。
+ PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
+ end
+ it '画像ファイルの保存が4回呼ばれる' do
+ PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '画像ファイルのベースへの保存が1回呼ばれる' do
+ PictureIO.picture_io.should_receive(:put).with('data', @p.filename, '').exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '画像ファイルの垂直反転への保存が1回呼ばれる' do
+ PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'v').exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '画像ファイルの水平反転への保存が1回呼ばれる' do
+ PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'h').exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
+ PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'vh').exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '垂直反転が1回呼ばれる' do
+ Picture.any_instance.should_receive(:v).with(any_args).exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '水平反転が1回呼ばれる' do
+ Picture.any_instance.should_receive(:h).with(any_args).exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ it '垂直水平反転が1回呼ばれる' do
+ Picture.any_instance.should_receive(:vh).with(any_args).exactly(1)
+ res = @p.store_picture(Mgk.new)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。
+ PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
+ end
+ it 'Trueを返す' do
+ res = @p.store_picture(Mgk.new)
+ res.should be_true
+ end
+ end
+ context '例外ケース' do
+ before do
+ PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
+ end
+ it 'Falseを返す' do
+ res = @p.store_picture(Mgk.new)
+ res.should be_false
+ end
+ end
+
+ end
+
+ describe 'フラグ展開に於いて' do
+ before do
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id,
+ :settings => "{\"open\": 1, \"commercial\": 2, \"official\": 3, \"attribution\": 4, \"derive\": 5, \"thumbnail\": 6, \"gif_convert\": 7, \"reverse\": 8, \"resize\": 9, \"sync_vh\": 10, \"overlap\": 11}"
+ end
+ context 'json展開チェック' do
+ it '展開してなければ展開して@flagsに保管する' do
+ @p.flags.should_not be_nil
+ end
+ it '展開できなければnilのまま' do
+ @p.settings += '}'
+ @p.flags.should be_nil
+ end
+ end
+ context 'openについて' do
+ it '@flag_openに保管する' do
+ @p.flag_open.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_open
+ @p.flags = nil
+ @p.flag_open.should_not be_nil
+ end
+ it '1を返す' do
+ @p.flag_open.should eq 1
+ end
+ end
+ context 'commercialについて' do
+ it '@flag_commercialに保管する' do
+ @p.flag_commercial.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_commercial
+ @p.flags = nil
+ @p.flag_commercial.should_not be_nil
+ end
+ it '2を返す' do
+ @p.flag_commercial.should eq 2
+ end
+ end
+ context 'officialについて' do
+ it '@flag_officialに保管する' do
+ @p.flag_official.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_official
+ @p.flags = nil
+ @p.flag_official.should_not be_nil
+ end
+ it 'を返す' do
+ @p.flag_official.should eq 3
+ end
+ end
+ context 'attributionについて' do
+ it '@flag_attributionに保管する' do
+ @p.flag_attribution.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_attribution
+ @p.flags = nil
+ @p.flag_attribution.should_not be_nil
+ end
+ it '4を返す' do
+ @p.flag_attribution.should eq 4
+ end
+ end
+ context 'deriveについて' do
+ it '@flag_deriveに保管する' do
+ @p.flag_derive.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_derive
+ @p.flags = nil
+ @p.flag_derive.should_not be_nil
+ end
+ it '5を返す' do
+ @p.flag_derive.should eq 5
+ end
+ end
+ context 'thumbnailについて' do
+ it '@flag_thumbnailに保管する' do
+ @p.flag_thumbnail.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_thumbnail
+ @p.flags = nil
+ @p.flag_thumbnail.should_not be_nil
+ end
+ it '6を返す' do
+ @p.flag_thumbnail.should eq 6
+ end
+ end
+ context 'gif_convertについて' do
+ it '@flag_gif_convertに保管する' do
+ @p.flag_gif_convert.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_gif_convert
+ @p.flags = nil
+ @p.flag_gif_convert.should_not be_nil
+ end
+ it '7を返す' do
+ @p.flag_gif_convert.should eq 7
+ end
+ end
+ context 'reverseについて' do
+ it '@flag_reverseに保管する' do
+ @p.flag_reverse.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_reverse
+ @p.flags = nil
+ @p.flag_reverse.should_not be_nil
+ end
+ it '8を返す' do
+ @p.flag_reverse.should eq 8
+ end
+ end
+ context 'resizeについて' do
+ it '@flag_resizeに保管する' do
+ @p.flag_resize.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_resize
+ @p.flags = nil
+ @p.flag_resize.should_not be_nil
+ end
+ it '9を返す' do
+ @p.flag_resize.should eq 9
+ end
+ end
+ context 'sync_vhについて' do
+ it '@flag_sync_vhに保管する' do
+ @p.flag_sync_vh.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_sync_vh
+ @p.flags = nil
+ @p.flag_sync_vh.should_not be_nil
+ end
+ it '10を返す' do
+ @p.flag_sync_vh.should eq 10
+ end
+ end
+ context 'overlapについて' do
+ it '@flag_overlapに保管する' do
+ @p.flag_overlap.should_not be_nil
+ end
+ it '本当にフラグHashからじゃなく、変数から取得してる?' do
+ @p.flag_overlap
+ @p.flags = nil
+ @p.flag_overlap.should_not be_nil
+ end
+ it '11を返す' do
+ @p.flag_overlap.should eq 11
+ end
+ end
+ end
+
+ describe 'クレジットデータに於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
+ end
+ it 'system_picture_idが入っている' do
+ res = @p.credit_data
+ res["system_picture_id"].should eq 2
+ end
+ end
+
+end
--- /dev/null
+require 'spec_helper'
+
+describe ResourcePictureLicense do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
# -*- encoding: utf-8 -*-\r
-require 'spec_helper'
-
-describe ResourcePicture do
- before do
- Factory :admin
- @user = Factory( :user_yas)
- @author = @user.author
+#素材\r
+require 'spec_helper'\r
+\r
+describe ResourcePicture do\r
+ before do\r
+ Factory :admin\r
+ @user = Factory( :user_yas)\r
+ @author = @user.author\r
@artist = Factory :artist_yas, :author_id => @author.id\r
- @other_user = Factory( :user_yas)
- @other_author = @other_user.author
- @other_artist = Factory :artist_yas, :author_id => @other_author.id
- @license = Factory :license
- @original_picture = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
-
- class Mgk ; class Image ; end ; end
- Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
- Mgk.any_instance.stub(:format).with(any_args).and_return('png')
- Mgk.any_instance.stub(:format=).with(any_args)
- Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
- Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
- Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)
- Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
- #原画ファイル削除だけは必ず成功するものとしておく
- PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
+ @other_user = Factory( :user_yas)\r
+ @other_author = @other_user.author\r
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id\r
+ @sp = Factory :system_picture\r
+ @lg = Factory :license_group\r
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
+ @original_picture = Factory :original_picture, :artist_id => @artist.id\r
+ \r
+ class Mgk ; class Image ; end ; end\r
+ Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
+ Mgk.any_instance.stub(:format).with(any_args).and_return('png')\r
+ Mgk.any_instance.stub(:format=).with(any_args)\r
+ Mgk.any_instance.stub(:rows).with(any_args).and_return(200)\r
+ Mgk.any_instance.stub(:columns).with(any_args).and_return(100)\r
+ Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)\r
+ Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')\r
+ #原画ファイル削除だけは必ず成功するものとしておく\r
+ PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)\r
+ Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\r
+ Picture.any_instance.stub(:h).with(any_args).and_return('data')\r
+ Picture.any_instance.stub(:v).with(any_args).and_return('data')\r
+ Picture.any_instance.stub(:vh).with(any_args).and_return('data')\r
end\r
-
- describe '検証に於いて' do
+ \r
+ describe '検証に於いて' do\r
before do\r
- end
-
- it 'オーソドックスなデータなら通る' do
- @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
- @rp.should be_valid
- end
-
- context 'extを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.ext = 'jpeg'
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.ext = ''
- @rp.should_not be_valid
- end
- it '5文字以上なら失敗する' do
- @rp.ext = 'a'*5
- @rp.should_not be_valid
- end
- it 'png,gif,jpeg以外なら失敗する' do
- @rp.ext = 'bmp'
- @rp.should_not be_valid
- end
- end
- context 'widthを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.width = 1
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.width = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.width = 'a'
- @rp.should_not be_valid
- end
- it '0なら失敗する' do
- @rp.width = '0'
- @rp.should_not be_valid
- end
- it '負でも失敗する' do
- @rp.width = -1
- @rp.should_not be_valid
- end
- end
- context 'heightを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.height = '1'
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.height = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.height = 'a'
- @rp.should_not be_valid
- end
- it '0なら失敗する' do
- @rp.height = '0'
- @rp.should_not be_valid
- end
- it '負でも失敗する' do
- @rp.height = -1
- @rp.should_not be_valid
- end
- end
- context 'filesizeを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.filesize = '1'
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.filesize = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.filesize = 'a'
- @rp.should_not be_valid
- end
- it '負なら失敗する' do
- @rp.filesize = '-1'
- @rp.should_not be_valid
- end
- it '2MB以上なら失敗する' do
- @rp.filesize = 2000000+1
- @rp.should_not be_valid
- end
- end
- context 'artist_idを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :original_picture_id => @original_picture.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.artist_id = @artist.id
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.artist_id = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.artist_id = 'a'
- @rp.should_not be_valid
- end
- it '存在する絵師でなければ失敗する' do
- @rp.artist_id = 0
- @rp.should_not be_valid
- end
- end
- context 'license_idを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :original_picture_id => @original_picture.id
- end
- it 'テストデータの確認' do
- @rp.license_id = @license.id
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.license_id = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.license_id = 'a'
- @rp.should_not be_valid
- end
- it '存在する絵師でなければ失敗する' do
- @rp.license_id = 0
- @rp.should_not be_valid
- end
- end
- context 'original_picture_idを検証するとき' do
- before do
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :license_id => @license.id
- end
- it 'テストデータの確認' do
- @rp.original_picture_id = @original_picture.id
- @rp.should be_valid
- end
- it 'nullなら失敗する' do
- @rp.original_picture_id = nil
- @rp.should_not be_valid
- end
- it '数値でなければ失敗する' do
- @rp.original_picture_id = 'a'
- @rp.should_not be_valid
- end
- it '存在する原画でなければ失敗する' do
- @rp.original_picture_id = 0
- @rp.should_not be_valid
- end
- end
- end
-
- describe 'データ補充に於いて' do
- before do
- end
-
- end
+ @p = Factory :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+ end\r
+ \r
+ it 'オーソドックスなデータなら通る' do\r
+ @rp.should be_valid\r
+ end\r
+ \r
+ context 'extを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.ext = 'jpeg'\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.ext = ''\r
+ @rp.should_not be_valid\r
+ end\r
+ it '5文字以上なら失敗する' do\r
+ @rp.ext = 'a'*5\r
+ @rp.should_not be_valid\r
+ end\r
+ it 'png,gif,jpeg以外なら失敗する' do\r
+ @rp.ext = 'bmp'\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'widthを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.width = 1\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.width = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.width = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '0なら失敗する' do\r
+ @rp.width = '0'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '負でも失敗する' do\r
+ @rp.width = -1\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'heightを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.height = '1'\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.height = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.height = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '0なら失敗する' do\r
+ @rp.height = '0'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '負でも失敗する' do\r
+ @rp.height = -1\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'filesizeを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.filesize = '1'\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.filesize = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.filesize = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '負なら失敗する' do\r
+ @rp.filesize = '-1'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '2MB以上なら失敗する' do\r
+ @rp.filesize = 2000000+1\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'artist_idを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.artist_id = @artist.id\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.artist_id = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.artist_id = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '存在する絵師でなければ失敗する' do\r
+ @rp.artist_id = 0\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'license_idを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.license_id = @license.id\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.license_id = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.license_id = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '存在する絵師でなければ失敗する' do\r
+ @rp.license_id = 0\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'original_picture_idを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.original_picture_id = @original_picture.id\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.original_picture_id = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.original_picture_id = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '存在する原画でなければ失敗する' do\r
+ @rp.original_picture_id = 0\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'artist_nameを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.artist_name = 'a'\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.artist_name = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'classnameを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.classname = 'a'*50\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.classname = ''\r
+ @rp.should_not be_valid\r
+ end\r
+ it '51文字以上なら失敗する' do\r
+ @rp.classname = 'a'*51\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ context 'creditを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.credit = 'a'\r
+ @rp.should be_valid\r
+ end\r
+ end\r
+ context 'settingsを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.settings = 'a'\r
+ @rp.should be_valid\r
+ end\r
+ end\r
+ context 'picture_idを検証するとき' do\r
+ it 'テストデータの確認' do\r
+ @rp.picture_id = @p.id\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.picture_id = nil\r
+ @rp.should_not be_valid\r
+ end\r
+ it '数値でなければ失敗する' do\r
+ @rp.picture_id = 'a'\r
+ @rp.should_not be_valid\r
+ end\r
+ it '存在する実素材でなければ失敗する' do\r
+ @rp.picture_id = 0\r
+ @rp.should_not be_valid\r
+ end\r
+ end\r
+ end\r
\r
- describe '単体取得に於いて' do
- before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
- end
- it '指定の素材を返す' do
- pic = ResourcePicture.show @rp.id
- pic.should eq @rp
- end
- context '関連テーブルオプションがないとき' do
- it 'ライセンスと絵師を含んでいる' do
- r = ResourcePicture.show_include_opt
- r.should eq [:license, :artist]
- end
- end
- context '関連テーブルオプションで原画を含ませたとき' do
- it 'ライセンスと絵師と原画データを含んでいる' do
- r = ResourcePicture.show_include_opt(:include => :original_picture)
- r.should eq [:license, :artist, :original_picture]
- end
- end
- context '存在しない素材を開こうとしたとき' do
- it '404RecordNotFound例外を返す' do
- lambda{
- pic = ResourcePicture.show 0
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
- end
- describe 'json単体出力オプションに於いて' do
- it 'includeキーがライセンスと絵師を含んでいる' do
- r = ResourcePicture.show_json_include_opt
- r[:include].should eq [:license, :artist]
- end
- end
- describe '一覧取得に於いて' do
- before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- ResourcePicture.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- ResourcePicture.page().should eq 1
- end
- it '0以下の場合は1になる' do
- ResourcePicture.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- ResourcePicture.page_size('7').should eq 7
- end
- it 'nilの場合はResourcePicture.default_page_sizeになる' do
- ResourcePicture.page_size().should eq ResourcePicture.default_page_size
- end
- it '0以下の場合はResourcePicture.default_page_sizeになる' do
- ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size
- end
- it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do
- ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size
- end
- end
- it 'リストを返す' do
- pic = ResourcePicture.list
- pic.should eq [@rp]
- end
- it '時系列で並んでいる' do
- nop = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :updated_at => Time.now + 100
- pic = ResourcePicture.list
- pic.should eq [nrp, @rp]
- end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- nop2 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :updated_at => Time.now + 100
- nop3 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :updated_at => Time.now + 200
- nop4 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :updated_at => Time.now + 300
- nop5 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :updated_at => Time.now + 400
- ResourcePicture.stub(:default_page_size).and_return(2)
- end
- it '通常は2件を返す' do
- pic = ResourcePicture.list
- pic.should have(2).items
- end
- it 'page=1なら末尾2件を返す' do
- #時系列で並んでいる
- pic = ResourcePicture.list({}, 1)
- pic.should eq [@nrp5, @nrp4]
- end
- it 'page=2なら中間2件を返す' do
- pic = ResourcePicture.list({}, 2)
- pic.should eq [@nrp3, @nrp2]
- end
- it 'page=3なら先頭1件を返す' do
- pic = ResourcePicture.list({}, 3)
- pic.should eq [@rp]
- end
- end
- end
- describe 'json一覧出力オプションに於いて' do
- it 'includeキーがライセンスと絵師を含んでいる' do
- r = ResourcePicture.list_json_opt
- r[:include].should eq [:license, :artist]
- end
+ describe 'データ補充に於いて' do\r
+ before do\r
+ end\r
+ \r
end\r
-
- describe 'サイズの調整に於いて' do
- before do
- end
-
- it 'サイズに収まるときはそのまま使う' do
- ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]
- end
- it '小さくても拡大しない' do
- ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]
- end
- it '縦長のときは縦に合わせて縮小' do
- ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]
- end
- it '横長のときは横に合わせて縮小' do
- ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]
- end
- end
\r
- describe 'フォーマット変換対象判定に於いて' do
- before do
+ describe '単体取得に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+ end\r
+ it '指定の素材を返す' do\r
+ pic = ResourcePicture.show @rp.id\r
+ pic.should eq @rp\r
+ end\r
+ context '関連テーブルオプションがないとき' do\r
+ it 'ライセンスと絵師を含んでいる' do\r
+ r = ResourcePicture.show_include_opt\r
+ r.should eq [:license, :artist]\r
+ end\r
+ end\r
+ context '関連テーブルオプションで原画を含ませたとき' do\r
+ it 'ライセンスと絵師と原画データを含んでいる' do\r
+ r = ResourcePicture.show_include_opt(:include => :original_picture)\r
+ r.should eq [:license, :artist, :original_picture]\r
+ end\r
+ end\r
+ context '存在しない素材を開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ pic = ResourcePicture.show 0\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ describe 'json単体出力オプションに於いて' do\r
+ it 'includeキーがライセンスと絵師を含んでいる' do\r
+ r = ResourcePicture.show_json_include_opt\r
+ r[:include].should eq [:license, :artist]\r
+ end\r
+ end\r
+ describe '一覧取得に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+ end\r
+ context 'page補正について' do\r
+ it '文字列から数値に変換される' do\r
+ ResourcePicture.page('8').should eq 8\r
+ end\r
+ it 'nilの場合は1になる' do\r
+ ResourcePicture.page().should eq 1\r
+ end\r
+ it '0以下の場合は1になる' do\r
+ ResourcePicture.page('0').should eq 1\r
+ end\r
+ end\r
+ context 'page_size補正について' do\r
+ it '文字列から数値に変換される' do\r
+ ResourcePicture.page_size('7').should eq 7\r
+ end\r
+ it 'nilの場合はResourcePicture.default_page_sizeになる' do\r
+ ResourcePicture.page_size().should eq ResourcePicture.default_page_size\r
+ end\r
+ it '0以下の場合はResourcePicture.default_page_sizeになる' do\r
+ ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size\r
+ end\r
+ it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do\r
+ ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size\r
+ end\r
+ end\r
+ it 'リストを返す' do\r
+ pic = ResourcePicture.list\r
+ pic.should eq [@rp]\r
+ end\r
+ it '時系列で並んでいる' do\r
+ nop = Factory :original_picture, :artist_id => @artist.id\r
+ nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+ pic = ResourcePicture.list\r
+ pic.should eq [nrp, @rp]\r
+ end\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
+ nop2 = Factory :original_picture, :artist_id => @artist.id\r
+ @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+ nop3 = Factory :original_picture, :artist_id => @artist.id\r
+ @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+ nop4 = Factory :original_picture, :artist_id => @artist.id\r
+ @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+ nop5 = Factory :original_picture, :artist_id => @artist.id\r
+ @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+ ResourcePicture.stub(:default_page_size).and_return(2)\r
+ end\r
+ it '通常は2件を返す' do\r
+ pic = ResourcePicture.list\r
+ pic.should have(2).items \r
+ end\r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ pic = ResourcePicture.list({}, 1)\r
+ pic.should eq [@nrp5, @nrp4]\r
+ end\r
+ it 'page=2なら中間2件を返す' do\r
+ pic = ResourcePicture.list({}, 2)\r
+ pic.should eq [@nrp3, @nrp2]\r
+ end\r
+ it 'page=3なら先頭1件を返す' do\r
+ pic = ResourcePicture.list({}, 3)\r
+ pic.should eq [@rp]\r
+ end\r
+ end\r
+ end\r
+ describe 'json一覧出力オプションに於いて' do\r
+ it 'includeキーがライセンスと絵師を含んでいる' do\r
+ r = ResourcePicture.list_json_opt\r
+ r[:include].should eq [:license, :artist]\r
+ end\r
+ end\r
+ \r
+ describe 'サイズの調整に於いて' do\r
+ before do\r
+ end\r
+ \r
+ it 'サイズに収まるときはそのまま使う' do\r
+ ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]\r
+ end\r
+ it '小さくても拡大しない' do\r
+ ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]\r
+ end\r
+ it '縦長のときは縦に合わせて縮小' do\r
+ ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]\r
+ end\r
+ it '横長のときは横に合わせて縮小' do\r
+ ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]\r
+ end\r
+ end\r
+ \r
+ describe 'フォーマット変換対象判定に於いて' do\r
+ before do\r
@rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :license_id => @license.id
- end
+ :artist_id => @artist.id, :license_id => @license.id\r
+ end\r
context '変換するケース' do\r
it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
- License.any_instance.stub(:no_convert).with(any_args).and_return(0)
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
@rp.ext = 'png'\r
- @rp.to_gif?.should be_true
- end
- end
- context '変換しないケース' do
+ @rp.to_gif?.should be_true\r
+ end\r
+ end\r
+ context '変換しないケース' do\r
it '画像フォーマットがでない' do\r
- License.any_instance.stub(:no_convert).with(any_args).and_return(0)
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
@rp.ext = 'gif'\r
- @rp.to_gif?.should be_false
- end
- it 'ライセンスの変換禁止フラグが無効' do\r
- License.any_instance.stub(:no_convert).with(any_args).and_return(1)
+ @rp.to_gif?.should be_false\r
+ end\r
+ it '変換禁止フラグが無効' do\r
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
@rp.ext = 'png'\r
- @rp.to_gif?.should be_false
- end
- end
- end
-
- describe 'Gifフォーマット変換に於いて' do
- before do
- Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
- end
- context 'つつがなく終わるとき' do
- it 'Mgkオブジェクトが返る' do
+ @rp.to_gif?.should be_false\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe 'Gifフォーマット変換に於いて' do\r
+ before do\r
+ Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'Mgkオブジェクトが返る' do\r
mgk = ResourcePicture.png_to_gif('mgkbin')\r
- mgk.is_a?(Mgk).should be_true
- end
+ mgk.is_a?(Mgk).should be_true\r
+ end\r
it 'Mgkオブジェクトはgif変換されている' do\r
- #スタブばかりで変換できないので代入されているかでチェックする
- Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)
+ #スタブばかりで変換できないので代入されているかでチェックする\r
+ Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)\r
ResourcePicture.png_to_gif('mgkbin')\r
- end
- end
- context 'RMagick変換が失敗したとき' do
- before do
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
- end
- it 'falseを返す' do
+ end\r
+ end\r
+ context 'RMagick変換が失敗したとき' do\r
+ before do\r
+ Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+ end\r
+ it 'falseを返す' do\r
res = ResourcePicture.png_to_gif('mgkbin')\r
res.should be_false\r
- end
- end
- end
-
- describe 'å¯¾è±¡ç´ æ\9d\90ã\81®å\8f\96å¾\97ã\81«æ\96¼ã\81\84ã\81¦' do
+ end\r
+ end\r
+ end\r
+ \r
+ describe 'å\8e\9fç\94»ã\81\8bã\82\89ã\81®ã\82³ã\83\94ã\83¼ã\83\87ã\83¼ã\82¿ã\82»ã\83\83ã\83\88ã\81«æ\96¼ã\81\84ã\81¦' do\r
before do\r
- @op = Factory.build :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
- :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
+ :artist_id => @artist.id\r
@rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :license_id => @license.id
- end
- context '原画オブジェクトが素材を持っている(更新ケース)' do
+ :artist_id => @artist.id\r
+ end\r
+ it '原画オブジェクトから属性を取り出して対象素材にセットしている' do\r
+ res = @rp.copy_data(@op)\r
+ @rp.ext.should eq 'jpeg'\r
+ @rp.width.should eq 264\r
+ @rp.height.should eq 265\r
+ @rp.filesize.should eq 266\r
+ @rp.artist_id.should eq @artist.id\r
+ end\r
+ end\r
+ \r
+ describe 'RMagick変換に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '画像データをオブジェクト化している' do\r
+ Magick::Image.stub(:from_blob).and_return(['mgkobj'])\r
+ @rp.data_to_mgk('mgkbin').should eq 'mgkobj'\r
+ end\r
+ end\r
+ context '失敗するとき' do\r
+ it 'Falseを返す' do\r
+ Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+ @rp.data_to_mgk('mgkbin').should be_false\r
+ end\r
+ it '全体エラーがセットされている' do\r
+ Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+ lambda {\r
+ @rp.data_to_mgk('mgkbin')\r
+ }.should change(@rp.errors[:base], :count)\r
+ end\r
+ end\r
+ end\r
+ describe '画像オブジェクトの取得に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ end\r
+ context '事前チェック' do\r
before do\r
- OriginalPicture.any_instance.stub(:resource_picture).with(any_args).and_return(@rp)\r
- end
- it 'それを対象素材として返す' do
- res = ResourcePicture.update_picture(@op)\r
- res.should eq @rp\r
- end
- end
- context '持っていない(新規作成ケース)' do
+ OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
+ ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)\r
+ end\r
+ it '原画から画像データを取得している' do\r
+ OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)\r
+ res = @rp.op_mgk\r
+ end\r
+ it '素材に原画データのRMagick変換を依頼している' do\r
+ ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)\r
+ res = @rp.op_mgk\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ #原画から画像データを取得する。\r
+ #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
+ before do\r
+ @mgk = Mgk.new\r
+ OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
+ ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)\r
+ end\r
+ it '画像オブジェクトを返す' do\r
+ res = @rp.op_mgk\r
+ res.should eq @mgk\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '新規実素材の取得に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', \r
+ :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ @mgk = Mgk.new\r
+ end\r
+ context '事前チェック' do\r
+ before do\r
+ Picture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
+ Picture.any_instance.stub(:store).with(any_args).and_return(true)\r
+ end\r
+ it '実素材に原画からのコピーデータを依頼している' do\r
+ Picture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
+ res = @rp.new_picture @mgk\r
+ end\r
+ it '実素材を保存している' do\r
+ Picture.any_instance.should_receive(:store).with(any_args).exactly(1)\r
+ res = @rp.new_picture @mgk\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '実素材に原画からのコピーデータをセットしている' do\r
+ res = @rp.new_picture @mgk\r
+ @rp.ext.should eq @op.ext\r
+ @rp.width.should eq @op.width\r
+ @rp.height.should eq @op.height\r
+ @rp.filesize.should eq @op.filesize\r
+ @rp.artist_id.should eq @op.artist_id\r
+ @rp.original_picture_id.should eq @op.id\r
+ end\r
+ it '実素材を返す' do\r
+ res = @rp.new_picture @mgk\r
+ res.is_a?(Picture).should be_true\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '作成・更新に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ end\r
+ context '事前チェック' do\r
+ before do\r
+ #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
+ #それで外部のメソッド呼び出しだけに着目してテストする。\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
+ ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+ ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
+ end\r
+ it '素材に原画からのコピーデータをセットしている' do\r
+ ResourcePicture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
+ res = @rp.store\r
+ end\r
+ it '画像オブジェクトの取得を依頼している' do\r
+ ResourcePicture.any_instance.should_receive(:op_mgk).with(any_args).exactly(1)\r
+ res = @rp.store\r
+ end\r
+ it '新規実素材の取得を依頼している' do\r
+ ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
+ res = @rp.store\r
+ end\r
+ it '自身を保存している' do\r
+ ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)\r
+ res = @rp.store\r
+ end\r
+ it '画像ファイルの作成・更新機能で画像を保存している' do\r
+ ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)\r
+ res = @rp.store\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
+ ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+ ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
+ end\r
+ it 'Trueを返す' do\r
+ res = @rp.store\r
+ res.should be_true\r
+ end\r
+ it '実素材idをセットしている' do\r
+ res = @rp.store\r
+ @rp.picture_id.should_not be_nil\r
+ end\r
+ it '実素材idから最新画像idを取得してセットしている' do\r
+ res = @rp.store\r
+ @rp.picture_id.should eq @p.id\r
+ end\r
+ it '自身が保存されている' do\r
+ lambda {\r
+ res = @rp.store\r
+ }.should change ResourcePicture, :count\r
+ end\r
+ end\r
+ #以下から例外ケース。処理先頭から失敗させていく\r
+ context '画像オブジェクトの取得に失敗したとき' do\r
+ before do\r
+ ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store\r
+ res.should be_false\r
+ end\r
+ it '更新されていない' do\r
+ @rp.store\r
+ @rp.should be_a_new ResourcePicture\r
+ end\r
+ end\r
+ context '新規実素材の取得に失敗したとき' do\r
+ before do\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
+ ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+ ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
+ Picture.any_instance.stub(:valid?).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store\r
+ res.should be_false\r
+ end\r
+ it '更新されていない' do\r
+ @rp.store\r
+ @rp.should be_a_new ResourcePicture\r
+ end\r
+ end\r
+ context '自身の保存に失敗したとき' do\r
+ before do\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
+ ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+ ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
+ ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store\r
+ res.should be_false\r
+ end\r
+ it '更新されていない' do\r
+ @rp.store\r
+ @rp.should be_a_new ResourcePicture\r
+ end\r
+ it '処理を中断してロールバックする' do\r
+ lambda {\r
+ res = @rp.store\r
+ }.should_not change Picture, :count\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '画像ファイルの作成・更新に於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ end\r
+ context '事前チェック' do\r
before do\r
- OriginalPicture.any_instance.stub(:resource_picture).with(any_args).and_return(nil)\r
- end
- it '新規素材モデルを用意し、それを対象素材として返す' do
- res = ResourcePicture.update_picture(@op)\r
- res.should be_a_new ResourcePicture\r
- end\r
- it '原画オブジェクトから属性を取り出して対象素材にセットしている' do
- res = ResourcePicture.update_picture(@op)\r
- res.ext.should eq 'jpeg'\r
- res.width.should eq 264\r
- res.height.should eq 265\r
- res.filesize.should eq 266\r
- res.artist_id.should eq @artist.id\r
- res.license_id.should eq @license.id\r
- end\r
-
- end
- end
-
- describe '作成・更新に於いて' do
- before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @rp = Factory.build :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
- end
- context '事前チェック' do
- before do
- #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
- #それで外部のメソッド呼び出しだけに着目してテストする。
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
+ #それで外部のメソッド呼び出しだけに着目してテストする。\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
- ResourcePicture.stub(:to_gif?).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
@gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
- end
- it '自身を保存している' do
- ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
- res = @rp.store(Mgk.new)\r
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
end\r
it '画像ファイルの作成・更新機能で画像を保存している' do\r
- mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
- ResourcePicture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
- res = @rp.store(mgk)\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
- it '自身にフォーマット変換対象かを問い合わせている' do
- ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
- res = @rp.store(Mgk.new)\r
+ it '自身にフォーマット変換対象かを問い合わせている' do\r
+ ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
- it '自身にGifフォーマット変換を依頼している' do
- ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
- res = @rp.store(Mgk.new)\r
+ it '自身にGifフォーマット変換を依頼している' do\r
+ ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
- #二回目の保存はgif変換の結果を渡す。
- ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
- res = @rp.store(Mgk.new)\r
- end\r
- end
- context 'つつがなく終わるとき' do
- before do
- #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-# ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ #二回目の保存はgif変換の結果を渡す。\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
@gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
- end
- it 'Trueを返す' do
- res = @rp.store(Mgk.new)\r
- res.should be_true\r
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
end\r
- it '自身が保存されている' do\r
- lambda {
- res = @rp.store(Mgk.new)\r
- }.should change ResourcePicture, :count\r
+ it 'Trueを返す' do\r
+ res = @rp.store_picture_with_gif @mgk\r
+ res.should be_true\r
end\r
- end
- context 'gif変換なしで、つつがなく終わるとき' do
- before do
- #すべての処理を正常パターンで通過させ、保存機能をチェックする。
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ end\r
+ context 'gif変換なしで、つつがなく終わるとき' do\r
+ before do\r
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
- end
- it 'Trueを返す' do
- res = @rp.store(Mgk.new)\r
+ end\r
+ it 'Trueを返す' do\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_true\r
end\r
it 'gif保存は呼ばれていない' do\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
- res = @rp.store(Mgk.new)\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
- end
- #以下から例外ケース。処理先頭から失敗させていく
- context '自身の保存に失敗したとき' do
- before do
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
- end
- it 'Falseを返す' do
- res = @rp.store(Mgk.new)\r
- res.should be_false\r
- end\r
- it '更新されていない' do
- @rp.store(Mgk.new)
- @rp.should be_a_new ResourcePicture\r
- end
- end
- context '画像の保存に失敗したとき' do
- before do
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ end\r
+ #以下から例外ケース。処理先頭から失敗させていく\r
+ context '画像の保存に失敗したとき' do\r
+ before do\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
- end
- it 'Falseを返す' do
- res = @rp.store(Mgk.new)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
it 'gif変換判定は呼ばれていない' do\r
- ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
- res = @rp.store(Mgk.new)\r
+ ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
- end
- context 'gif変換に失敗したとき' do
- before do
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ end\r
+ context 'gif変換に失敗したとき' do\r
+ before do\r
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)
- end
- it 'Falseを返す' do
- res = @rp.store(Mgk.new)\r
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
it 'gif画像の保存は呼ばれていない' do\r
#本画像の保存があるので、一度は呼ばれる\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
- res = @rp.store(Mgk.new)\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
- end
- context 'gif画像の保存に失敗したとき' do
+ end\r
+ context 'gif画像の保存に失敗したとき' do\r
before do\r
- @mgk = Mgk.new
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
+ @mgk = Mgk.new\r
ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
@gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
- end
- it 'Falseを返す' do
- res = @rp.store(@mgk)\r
+ end\r
+ it 'Falseを返す' do\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
- end
+ end\r
end\r
-
+ \r
describe '画像ファイルの作成・更新に於いて' do\r
#PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
- before do
- PictureIO.resource_picture_io.class.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh', 'thumbnail'])\r
- ResourcePicture.any_instance.stub(:h).with(any_args).and_return('data')
- ResourcePicture.any_instance.stub(:v).with(any_args).and_return('data')
- ResourcePicture.any_instance.stub(:vh).with(any_args).and_return('data')
- ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('data')
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
- end
- context '事前チェック' do
- before do
- #すべての処理を正常パターンで通過させ、保存機能をチェックする。
- PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
- end
- it '画像ファイルの保存が5回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(5)
- res = @rp.store_picture(Mgk.new)\r
- end\r
- it '画像ファイルのベースへの保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, '').exactly(1)
- res = @rp.store_picture(Mgk.new)\r
- end\r
- it '画像ファイルの垂直反転への保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'v').exactly(1)
- res = @rp.store_picture(Mgk.new)\r
- end\r
- it '画像ファイルの水平反転への保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'h').exactly(1)
- res = @rp.store_picture(Mgk.new)\r
- end\r
- it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'vh').exactly(1)
- res = @rp.store_picture(Mgk.new)\r
- end\r
- it '画像ファイルのサムネイルへの保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'thumbnail').exactly(1)
- res = @rp.store_picture(Mgk.new)\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ @rp.copy_data @op\r
+ end\r
+ context '事前チェック' do\r
+ before do\r
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+ PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+ ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
end\r
- it '垂直反転が1回呼ばれる' do\r
- ResourcePicture.any_instance.should_receive(:v).with(any_args).exactly(1)
+ it 'サムネイル化が1回呼ばれる' do\r
+ ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)\r
res = @rp.store_picture(Mgk.new)\r
end\r
- it '水平反転が1回呼ばれる' do\r
- ResourcePicture.any_instance.should_receive(:h).with(any_args).exactly(1)
+ it '画像ファイルの保存が2回呼ばれる' do\r
+ PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)\r
res = @rp.store_picture(Mgk.new)\r
end\r
- it '垂直水平反転が1回呼ばれる' do\r
- ResourcePicture.any_instance.should_receive(:vh).with(any_args).exactly(1)
+ it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do\r
+ PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', @rp.filename).exactly(1)\r
res = @rp.store_picture(Mgk.new)\r
end\r
- it 'サムネイル化が1回呼ばれる' do\r
- ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)
+ it '画像ファイルのfullへの保存が1回呼ばれる' do\r
+ PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'full').exactly(1)\r
res = @rp.store_picture(Mgk.new)\r
end\r
- end
- context 'つつがなく終わるとき' do
- before do
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
- PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
- end
- it 'Trueを返す' do
+ PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+ end\r
+ it 'Trueを返す' do\r
res = @rp.store_picture(Mgk.new)\r
res.should be_true\r
end\r
- end
- context '例外ケース' do
- before do
- PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)
- end
- it 'Falseを返す' do
+ end\r
+ context '例外ケース' do\r
+ before do\r
+ ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+ PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
res = @rp.store_picture(Mgk.new)\r
res.should be_false\r
end\r
- end
-
- end
-
-describe 'サムネイル変換に於いて' do
- #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする
- before do
- ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
- end
+ end\r
+ \r
+ end\r
+ \r
+ describe 'サムネイル変換に於いて' do\r
+ #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする\r
+ before do\r
+ ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
+ end\r
it 'サムネイルサイズに縮小した画像データを返す' do\r
- ResourcePicture.should_receive(:resize).with(any_args).exactly(1)
+ ResourcePicture.should_receive(:resize).with(any_args).exactly(1)\r
@rp.thumbnail(Mgk.new)\r
end\r
it 'データが返る' do\r
#全体スタブより\r
@rp.thumbnail(Mgk.new).should eq 'data'\r
end\r
- end
-
- describe '垂直反転変換に於いて' do
- #垂直反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
- before do
- Mgk.any_instance.stub(:flip).with(any_args).and_return(Mgk.new)
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
- end\r
- it '垂直反転する' do\r
- Mgk.any_instance.should_receive(:flip).exactly(1)
- @rp.v(Mgk.new)\r
- end\r
- it '画像データ化する' do\r
- Mgk.any_instance.should_receive(:to_blob).exactly(1)
- @rp.v(Mgk.new)\r
- end\r
- it 'データが返る' do\r
- #全体スタブより\r
- @rp.v(Mgk.new).should eq 'data'\r
- end\r
- end
-
- describe '水平反転変換に於いて' do
- #水平反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
- before do
- Mgk.any_instance.stub(:flop).with(any_args).and_return(Mgk.new)
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
- end
- it '水平反転する' do\r
- Mgk.any_instance.should_receive(:flop).exactly(1)
- @rp.h(Mgk.new)\r
- end\r
- it '画像データ化する' do\r
- Mgk.any_instance.should_receive(:to_blob).exactly(1)
- @rp.h(Mgk.new)\r
- end\r
- it 'データが返る' do\r
- #全体スタブより\r
- @rp.h(Mgk.new).should eq 'data'\r
- end\r
- end
-
- describe '垂直水平反転変換に於いて' do
- #垂直水平反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
- before do
- Mgk.any_instance.stub(:flip).with(any_args).and_return(Mgk.new)
- Mgk.any_instance.stub(:flop).with(any_args).and_return(Mgk.new)
- @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
- end
- it '垂直反転する' do\r
- Mgk.any_instance.should_receive(:flip).exactly(1)
- @rp.vh(Mgk.new)\r
- end\r
- it '水平反転する' do\r
- Mgk.any_instance.should_receive(:flop).exactly(1)
- @rp.vh(Mgk.new)\r
- end\r
- it '画像データ化する' do\r
- Mgk.any_instance.should_receive(:to_blob).exactly(1)
- @rp.vh(Mgk.new)\r
+ end\r
+ \r
+ describe 'クレジットデータに於いて' do\r
+ before do\r
+ @op = Factory :original_picture, :artist_id => @artist.id\r
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{"system_picture_id": 2}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr\r
end\r
- it 'データが返る' do\r
- #全体スタブより\r
- @rp.vh(Mgk.new).should eq 'data'\r
+ it 'system_picture_idが入っている' do\r
+ res = @rp.credit_data\r
+ res["system_picture_id"].should eq 2\r
end\r
- end
-
-end
+ end\r
+ \r
+end\r
\r
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
- @license = Factory :license
@panel = Factory :panel, :author_id => @author.id
@speech_balloon_template = Factory :speech_balloon_template
before do
@sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
end
+ #ネストの保存はnilを許可しなければならないので数値チェックだけ
it 'テストデータの確認' do
@sb.panel_id = @panel.id
@sb.should be_valid
@jes = JSON.parse @tes
@admin = Factory :admin
- @license = Factory :license
end
describe '検証に於いて' do
describe Speech do\r
before do\r
Factory :admin\r
- @license = Factory :license\r
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)\r
@author = @user.author\r
\r
before do\r
@speech = Factory.build :speech, :speech_balloon_id => @speech_balloon.id\r
end\r
+ #ネストの保存はnilを許可しなければならないので数値チェックだけ
it 'テストデータの確認' do\r
@speech.speech_balloon_id = @speech_balloon.id\r
@speech.should be_valid\r
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンス選択
+require 'spec_helper'
+
+describe StandardLicense do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @other_user = Factory( :user_yas)
+ @other_author = @other_user.author
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ @sl.should be_valid
+ end
+
+ context 'license_idを検証するとき' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @sl.license_id = @license.id
+ @sl.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @sl.license_id = nil
+ @sl.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @sl.license_id = 'a'
+ @sl.should_not be_valid
+ end
+ it '存在するライセンスグループでなければ失敗する' do
+ @sl.license_id = 0
+ @sl.should_not be_valid
+ end
+ end
+ context 'artist_nameを検証するとき' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @sl.artist_name = 'a'
+ @sl.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @sl.artist_name = nil
+ @sl.should_not be_valid
+ end
+ end
+ end
+ describe '補充に於いて' do
+ it '原画idを補充している' do
+ @sl = StandardLicense.new
+ @sl.artist_name = nil
+ @sl.supply_default @artist
+ @sl.artist_name.should eq @artist.name
+ end
+ end
+ describe 'クレジットデータに於いて' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'jsonテキストを返す' do
+ r = @sl.credit
+ lambda{
+ JSON.parse @sl.credit
+ }.should_not raise_error
+ end
+ it 'system_picture_idを含んでいて値はライセンスに割り当てたシステム画像になっている' do
+ r = JSON.parse @sl.credit
+ r.has_key?('system_picture_id').should be_true
+ r['system_picture_id'].should eq @sl.license.system_picture_id
+ end
+ end
+end
describe Story do
before do
Factory :admin
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
describe SystemPicture do
before do
@admin = Factory :admin
- @license = Factory :license
end
describe '検証に於いて' do