From: yasushiito Date: Sat, 30 Jun 2012 03:44:09 +0000 (+0900) Subject: Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04license X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=efd817c2dbd6c7b98352306dccdb5f272ca5c67c;hp=809beb5cd929c25f2d0ea1c3edd536d8d682c3a4 Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04license --- diff --git a/app/assets/stylesheets/license_group.css.scss b/app/assets/stylesheets/license_group.css.scss new file mode 100644 index 00000000..bdb12d91 --- /dev/null +++ b/app/assets/stylesheets/license_group.css.scss @@ -0,0 +1,3 @@ +// 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/ diff --git a/app/assets/stylesheets/resource_picture_license.css.scss b/app/assets/stylesheets/resource_picture_license.css.scss new file mode 100644 index 00000000..ed0bb8e5 --- /dev/null +++ b/app/assets/stylesheets/resource_picture_license.css.scss @@ -0,0 +1,3 @@ +// 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/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 79a5b24e..af9271d4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_filter :bf def bf - if Admin.count.to_i == 0 or License.count.to_i == 0 + if Admin.count.to_i == 0 # or License.count.to_i == 0 if params[:controller] == 'system' and params[:action] == 'start' else redirect_to :controller => '/system', :action => 'start' diff --git a/app/controllers/license_groups_controller.rb b/app/controllers/license_groups_controller.rb new file mode 100644 index 00000000..7d3aa4b7 --- /dev/null +++ b/app/controllers/license_groups_controller.rb @@ -0,0 +1,41 @@ +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 diff --git a/app/controllers/licenses_controller.rb b/app/controllers/licenses_controller.rb index 2943122c..4fa0b497 100644 --- a/app/controllers/licenses_controller.rb +++ b/app/controllers/licenses_controller.rb @@ -1,12 +1,11 @@ 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 diff --git a/app/controllers/resource_picture_license_controller.rb b/app/controllers/resource_picture_license_controller.rb new file mode 100644 index 00000000..aecb5c31 --- /dev/null +++ b/app/controllers/resource_picture_license_controller.rb @@ -0,0 +1,2 @@ +class ResourcePictureLicenseController < ApplicationController +end diff --git a/app/helpers/license_groups_helper.rb b/app/helpers/license_groups_helper.rb new file mode 100644 index 00000000..0f9c6f35 --- /dev/null +++ b/app/helpers/license_groups_helper.rb @@ -0,0 +1,2 @@ +module LicenseGroupsHelper +end diff --git a/app/helpers/resource_picture_license_helper.rb b/app/helpers/resource_picture_license_helper.rb new file mode 100644 index 00000000..5dbfc837 --- /dev/null +++ b/app/helpers/resource_picture_license_helper.rb @@ -0,0 +1,2 @@ +module ResourcePictureLicenseHelper +end diff --git a/app/models/license.rb b/app/models/license.rb index 3226b2d6..704e3489 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,63 +1,48 @@ +# 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 = {} @@ -67,13 +52,13 @@ class License < ActiveRecord::Base 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 diff --git a/app/models/license_group.rb b/app/models/license_group.rb new file mode 100644 index 00000000..fa67c7b8 --- /dev/null +++ b/app/models/license_group.rb @@ -0,0 +1,58 @@ +#ライセンスグループ +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 diff --git a/app/models/resource_picture_license.rb b/app/models/resource_picture_license.rb new file mode 100644 index 00000000..5d4d0b28 --- /dev/null +++ b/app/models/resource_picture_license.rb @@ -0,0 +1,2 @@ +class ResourcePictureLicense < ActiveRecord::Base +end diff --git a/app/models/system_picture.rb b/app/models/system_picture.rb index db857b7b..a2dea479 100644 --- a/app/models/system_picture.rb +++ b/app/models/system_picture.rb @@ -1,6 +1,7 @@ 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 diff --git a/app/views/license_groups/browse.html.erb b/app/views/license_groups/browse.html.erb new file mode 100644 index 00000000..ffd5af4b --- /dev/null +++ b/app/views/license_groups/browse.html.erb @@ -0,0 +1,62 @@ +
+

+

id
+<%= @license_group.id %> +

+

+<%= h @license_group.name %> +

+

+

name
+<%= h @license_group.name %> +

+

+

classname
+<%= h @license_group.classname %> +

+

+

caption
+<%= h @license_group.caption %> +

+

+

url
+<%= h @license_group.url %> +

+

+<%= @license_group.created_at %> +

+

+<%= @license_group.updated_at %> +

+
+

Listing licenses

+ + + + + + + + + + + + + + +<% @license_group.licenses.each do |license| %> + + + + + + + + + + + +<% end -%> +
idlicense_group_idnamecaptionurlsystem_picture_idsettingscreated_atupdated_at
<%= link_to license.id, :action => :browse, :id => license.id %><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %><%= h license.name %><%= h license.caption %><%= h license.url %><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %><%= h license.settings %><%= license.created_at %><%= license.updated_at %>
+ +<%= link_to 'Back', :action => :list %> diff --git a/app/views/license_groups/index.html.erb b/app/views/license_groups/index.html.erb new file mode 100644 index 00000000..331ce181 --- /dev/null +++ b/app/views/license_groups/index.html.erb @@ -0,0 +1,17 @@ +

Listing license Groups

+ + + + + + + + +<% @license_groups.each do |lg| %> + + + + + +<% end -%> +
idnamecaption
<%= link_to lg.id, license_group_path(lg) %><%= h lg.name %><%= content_tag(:a, h(lg.caption), :href => lg.url) %>
diff --git a/app/views/license_groups/list.html.erb b/app/views/license_groups/list.html.erb new file mode 100644 index 00000000..9d99f86f --- /dev/null +++ b/app/views/license_groups/list.html.erb @@ -0,0 +1,25 @@ +

Listing license Groups

+ + + + + + + + + + + + +<% @license_groups.each do |lg| %> + + + + + + + + + +<% end -%> +
idnameclassnamecaptionurlcreated_atupdated_at
<%= link_to lg.id, :action => :browse, :id => lg.id %><%= h lg.name %><%= h lg.classname %><%= h lg.caption %><%= h lg.url %><%= lg.created_at %><%= lg.updated_at %>
diff --git a/app/views/license_groups/show.html.erb b/app/views/license_groups/show.html.erb new file mode 100644 index 00000000..ce494aff --- /dev/null +++ b/app/views/license_groups/show.html.erb @@ -0,0 +1,22 @@ +

<%= notice %>

+ +

+<%= h @license_group.name %> +

+

+<%= h @license_group.classname %> +

+

+<%= h @license_group.caption %> +

+

+<%= h @license_group.url %> +

+

+<%= @license_group.created_at %> +

+

+<%= @license_group.updated_at %> +

+ +<%= link_to 'Back', license_groups_path %> diff --git a/app/views/licenses/browse.html.erb b/app/views/licenses/browse.html.erb index c00a645e..97a995d9 100644 --- a/app/views/licenses/browse.html.erb +++ b/app/views/licenses/browse.html.erb @@ -1,9 +1,42 @@ + license_group_id + name + caption + url + system_picture_id + settings
-<% 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 -%> +

+

id
+<%= @license.id %> +

+

+

license_group_id
+<%= h @license.license_group_id %> +

+

+

name
+<%= h @license.name %> +

+

+

caption
+<%= h @license.caption %> +

+

+

url
+<%= h @license.url %> +

+
system_picture_id
+<%= @license.system_picture_id %> +

+
settings
+<%= h @license.settings %> +

+

+<%= @license.created_at %> +

+

+<%= @license.updated_at %> +

<%= link_to 'Back', :action => :list %> diff --git a/app/views/licenses/index.html.erb b/app/views/licenses/index.html.erb index 7df7b82d..29afe660 100644 --- a/app/views/licenses/index.html.erb +++ b/app/views/licenses/index.html.erb @@ -3,38 +3,20 @@ + - - - - - - - - + + <% @licenses.each do |license| %> + - - - - - - - - - + + <% end -%>
namecaption urlcc_bycc_sacc_ndcc_ncno_resizeno_flipno_convertkeep_aspect_ratiocreated_atupdated_at
<%= h license.name %><%= h license.caption %> <%= h license.url %><%= license.cc_by %><%= license.cc_sa %><%= license.cc_nd %><%= license.cc_nc %><%= license.no_resize %><%= license.no_flip %><%= license.no_convert %><%= license.keep_aspect_ratio %> - <% if license.common_license -%> - <%= link_to 'Show', license.common_license %> - <% else -%> - <%= link_to 'Show', license.original_license %> - <% end -%> - <%= license.created_at %><%= license.updated_at %>
-<%= link_to 'new original license', new_original_license_path %> diff --git a/app/views/licenses/list.html.erb b/app/views/licenses/list.html.erb index cdafef5f..77ae8b5a 100644 --- a/app/views/licenses/list.html.erb +++ b/app/views/licenses/list.html.erb @@ -3,34 +3,25 @@ + + - - - - - - - - + + - <% @licenses.each do |license| %> + + - - - - - - - - + + diff --git a/app/views/system/browse.html.erb b/app/views/system/browse.html.erb index 836bacd3..0f4c05c0 100644 --- a/app/views/system/browse.html.erb +++ b/app/views/system/browse.html.erb @@ -66,17 +66,12 @@ - - - diff --git a/config/routes.rb b/config/routes.rb index 0eb6117c..c8d922ac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -140,6 +140,14 @@ Pettanr::Application.routes.draw do 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 diff --git a/db/license_groups.json b/db/license_groups.json new file mode 100644 index 00000000..6736a8f8 --- /dev/null +++ b/db/license_groups.json @@ -0,0 +1,31 @@ +{ + "PublicDomaina": { + "classname": "PublicDomain", + "caption": "Public Domain", + "url": "http://test.com/", + "licenses_attributes": { + "PublicDomain": { + "caption": "Public Domain", + "url": "http://test.com/", + "system_picture": "Data" + } + } + }, + "Unknowna": { + "classname": "Unknown", + "caption": "Unknown owner", + "url": "http://test.uk/", + "licenses_attributes": { + "UnknownF1": { + "caption": "Unknown Flag1", + "url": "http://test.com/f1", + "system_picture": "Dataf1" + }, + "UnknownF2": { + "caption": "Unknown Flag2", + "url": "http://test.com/f2", + "system_picture": "Dataf2" + } + } + } +} diff --git a/db/migrate/20120617054342_create_license_groups.rb b/db/migrate/20120617054342_create_license_groups.rb new file mode 100644 index 00000000..357b78d5 --- /dev/null +++ b/db/migrate/20120617054342_create_license_groups.rb @@ -0,0 +1,12 @@ +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 diff --git a/db/migrate/20120617055928_create_resource_picture_licenses.rb b/db/migrate/20120617055928_create_resource_picture_licenses.rb new file mode 100644 index 00000000..a0ebffde --- /dev/null +++ b/db/migrate/20120617055928_create_resource_picture_licenses.rb @@ -0,0 +1,13 @@ +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 diff --git a/db/migrate/20120617061753_change_license.rb b/db/migrate/20120617061753_change_license.rb new file mode 100644 index 00000000..094937a7 --- /dev/null +++ b/db/migrate/20120617061753_change_license.rb @@ -0,0 +1,38 @@ +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 + 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 + t.string :url, :null => false + t.integer :cc_by, :null => false, :default => 0 + t.integer :cc_sa, :null => false, :default => 0 + t.integer :cc_nd, :null => false, :default => 0 + t.integer :cc_nc, :null => false, :default => 0 + t.integer :no_resize, :null => false, :default => 0 + t.integer :no_flip, :null => false, :default => 0 + t.integer :no_convert, :null => false, :default => 0 + t.integer :keep_aspect_ratio, :null => false, :default => 0 + + t.timestamps + end + add_index :licenses, [:url], :unique => true + end +end diff --git a/spec/controllers/app_controller_spec.rb b/spec/controllers/app_controller_spec.rb index 7a87973b..edb068bd 100644 --- a/spec/controllers/app_controller_spec.rb +++ b/spec/controllers/app_controller_spec.rb @@ -11,7 +11,9 @@ describe SystemController do 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 @@ -64,7 +66,9 @@ describe SystemController do #要請の必要がある=管理者がいない または ライセンスがない 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 diff --git a/spec/controllers/artists_controller_spec.rb b/spec/controllers/artists_controller_spec.rb index e0db6676..d0a6cfb3 100644 --- a/spec/controllers/artists_controller_spec.rb +++ b/spec/controllers/artists_controller_spec.rb @@ -5,7 +5,9 @@ require 'spec_helper' 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 diff --git a/spec/controllers/authors_controller_spec.rb b/spec/controllers/authors_controller_spec.rb index 6adf6891..3bb2d475 100644 --- a/spec/controllers/authors_controller_spec.rb +++ b/spec/controllers/authors_controller_spec.rb @@ -5,7 +5,9 @@ require 'spec_helper' 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 diff --git a/spec/controllers/comics_controller_spec.rb b/spec/controllers/comics_controller_spec.rb index 07156f08..20dfcc3d 100644 --- a/spec/controllers/comics_controller_spec.rb +++ b/spec/controllers/comics_controller_spec.rb @@ -4,7 +4,9 @@ require 'spec_helper' describe ComicsController 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 #ユーザ作成時に連動して作成される end diff --git a/spec/controllers/common_licenses_controller_spec.rb b/spec/controllers/common_licenses_controller_spec.rb index 5dcdf254..e69de29b 100644 --- a/spec/controllers/common_licenses_controller_spec.rb +++ b/spec/controllers/common_licenses_controller_spec.rb @@ -1,338 +0,0 @@ -# -*- 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 diff --git a/spec/controllers/license_groups_controller_spec.rb b/spec/controllers/license_groups_controller_spec.rb new file mode 100644 index 00000000..9064b789 --- /dev/null +++ b/spec/controllers/license_groups_controller_spec.rb @@ -0,0 +1,115 @@ +# -*- encoding: utf-8 -*- +#ライセンスグループ +require 'spec_helper' + +describe LicenseGroupsController do + before do + @admin = Factory :admin + @user = Factory( :user_yas) + @lg = Factory :license_group, :name => 'peta' + 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 diff --git a/spec/controllers/licenses_controller_spec.rb b/spec/controllers/licenses_controller_spec.rb index 9b3c5cdf..534097e2 100644 --- a/spec/controllers/licenses_controller_spec.rb +++ b/spec/controllers/licenses_controller_spec.rb @@ -5,8 +5,8 @@ require 'spec_helper' 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 @@ -14,36 +14,11 @@ describe LicensesController do 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 @@ -93,11 +68,12 @@ describe LicensesController do 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 @@ -105,22 +81,22 @@ describe LicensesController 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 @@ -131,7 +107,7 @@ describe LicensesController do 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 diff --git a/spec/controllers/original_licenses_controller_spec.rb b/spec/controllers/original_licenses_controller_spec.rb index 4c5df40c..e69de29b 100644 --- a/spec/controllers/original_licenses_controller_spec.rb +++ b/spec/controllers/original_licenses_controller_spec.rb @@ -1,588 +0,0 @@ -# -*- 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 diff --git a/spec/controllers/original_pictures_controller_spec.rb b/spec/controllers/original_pictures_controller_spec.rb index 93596032..f6029f27 100644 --- a/spec/controllers/original_pictures_controller_spec.rb +++ b/spec/controllers/original_pictures_controller_spec.rb @@ -7,7 +7,9 @@ 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 diff --git a/spec/controllers/panel_pictures_controller_spec.rb b/spec/controllers/panel_pictures_controller_spec.rb index 5e8d308e..4fde5c59 100644 --- a/spec/controllers/panel_pictures_controller_spec.rb +++ b/spec/controllers/panel_pictures_controller_spec.rb @@ -5,7 +5,9 @@ require 'spec_helper' 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 diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index e7c058ea..cabdf60c 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -4,7 +4,9 @@ require 'spec_helper' describe PanelsController 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 => @author.id diff --git a/spec/controllers/resource_picture_license_controller_spec.rb b/spec/controllers/resource_picture_license_controller_spec.rb new file mode 100644 index 00000000..33c2774f --- /dev/null +++ b/spec/controllers/resource_picture_license_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ResourcePictureLicenseController do + +end diff --git a/spec/controllers/resource_pictures_controller_spec.rb b/spec/controllers/resource_pictures_controller_spec.rb index f8fa0d83..d45e33fa 100644 --- a/spec/controllers/resource_pictures_controller_spec.rb +++ b/spec/controllers/resource_pictures_controller_spec.rb @@ -5,7 +5,9 @@ require 'spec_helper' 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 diff --git a/spec/controllers/speech_balloon_templates_controller_spec.rb b/spec/controllers/speech_balloon_templates_controller_spec.rb index aac1bd34..3a215b26 100644 --- a/spec/controllers/speech_balloon_templates_controller_spec.rb +++ b/spec/controllers/speech_balloon_templates_controller_spec.rb @@ -5,7 +5,9 @@ describe SpeechBalloonTemplatesController do 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 diff --git a/spec/factories.rb b/spec/factories.rb index 2f449d2d..779e4ede 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -36,17 +36,19 @@ Factory.define :artist_yas, :class => Artist do |artist| # 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| diff --git a/spec/helpers/license_groups_helper_spec.rb b/spec/helpers/license_groups_helper_spec.rb new file mode 100644 index 00000000..5b68da92 --- /dev/null +++ b/spec/helpers/license_groups_helper_spec.rb @@ -0,0 +1,15 @@ +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 diff --git a/spec/helpers/resource_picture_license_helper_spec.rb b/spec/helpers/resource_picture_license_helper_spec.rb new file mode 100644 index 00000000..34345c63 --- /dev/null +++ b/spec/helpers/resource_picture_license_helper_spec.rb @@ -0,0 +1,15 @@ +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 diff --git a/spec/json/invalid_license_groups.json b/spec/json/invalid_license_groups.json new file mode 100644 index 00000000..afed9923 --- /dev/null +++ b/spec/json/invalid_license_groups.json @@ -0,0 +1,15 @@ +{ + "PublicDomain": { + "classname": "PublicDomain", + "caption": "Public Domain", + "url": "http://test.com/" + }, + "UnknownUrl": { + "classname": "Unknown", + "caption": "Unknown owner" + }, + "UnknownClassname": { + "caption": "Unknown owner", + "url": "http://test.uk/" + } +} diff --git a/spec/json/license_group.json b/spec/json/license_group.json new file mode 100644 index 00000000..3cfb5ab8 --- /dev/null +++ b/spec/json/license_group.json @@ -0,0 +1,15 @@ +{ + "PublicDomain": { + "name": "PublicDomain", + "classname": "PublicDomain", + "caption": "Public Domain", + "url": "http://test.com/", + "licenses_attributes": { + "PublicDomain": { + "caption": "Public Domain", + "url": "http://test.com/", + "system_picture": "Data" + } + } + } +} diff --git a/spec/json/license_groups.json b/spec/json/license_groups.json new file mode 100644 index 00000000..fe31ec72 --- /dev/null +++ b/spec/json/license_groups.json @@ -0,0 +1,24 @@ +{ + "PublicDomain": { + "classname": "PublicDomain", + "caption": "Public Domain", + "url": "http://test.com/" + }, + "Unknown": { + "classname": "Unknown", + "caption": "Unknown owner", + "url": "http://test.uk/", + "licenses_attributes": { + "UnknownF1": { + "caption": "Unknown Flag1", + "url": "http://test.com/f1", + "system_picture": "Dataf1" + }, + "UnknownF2": { + "caption": "Unknown Flag2", + "url": "http://test.com/f2", + "system_picture": "Dataf2" + } + } + } +} diff --git a/spec/models/artist_spec.rb b/spec/models/artist_spec.rb index 3abe2230..4993cbbf 100644 --- a/spec/models/artist_spec.rb +++ b/spec/models/artist_spec.rb @@ -7,7 +7,9 @@ describe Artist do 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 diff --git a/spec/models/balloon_spec.rb b/spec/models/balloon_spec.rb index e3cb45e5..fe027ace 100644 --- a/spec/models/balloon_spec.rb +++ b/spec/models/balloon_spec.rb @@ -7,7 +7,6 @@ describe Balloon do @user = Factory( :user_yas) @author = @user.author @artist = Factory :artist_yas, :author_id => @author.id - @license = Factory :license @balloon = Factory :panel @speech_balloon_template = Factory :speech_balloon_template diff --git a/spec/models/common_license_spec.rb b/spec/models/common_license_spec.rb index 70d2031e..e69de29b 100644 --- a/spec/models/common_license_spec.rb +++ b/spec/models/common_license_spec.rb @@ -1,562 +0,0 @@ -# -*- 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 diff --git a/spec/models/license_group_spec.rb b/spec/models/license_group_spec.rb new file mode 100644 index 00000000..46a225f5 --- /dev/null +++ b/spec/models/license_group_spec.rb @@ -0,0 +1,340 @@ +# -*- 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 diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 39fda16b..37d3cadc 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -7,14 +7,38 @@ describe License do 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 + @l.license_group_id = @lg.id + @l.should be_valid + end + it 'nullなら失敗する' do + @l.license_group_id = '' + @l.should_not be_valid + end + it '数値でなければ失敗する' do + @l.license_group_id = 'a' + @l.should_not be_valid + end + it '存在するライセンスグループでなければ失敗する' do + @l.license_group_id = 0 + @l.should_not be_valid + end + end context 'nameを検証するとき' do + it 'テストデータの確認' do + @l.name = 'a'*50 + @l.should be_valid + end it 'nullなら失敗する' do @l.name = '' @l.should_not be_valid @@ -23,84 +47,201 @@ describe License do @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 + @l.caption = 'a'*30 + @l.should be_valid + end + 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 + @l.url = 'http://test.jp/aaaaa' + 'a' * 180 + @l.save! + @l.should be_valid + end 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 + @l.should_not be_valid + end + end + context 'system_picture_idを検証するとき' do + it 'テストデータの確認' do + @l.system_picture_id = @sp.id + @l.should be_valid + end + it 'nullなら失敗する' do + @l.system_picture_id = '' @l.should_not be_valid end - it 'url形式でなら失敗する' do - @l.url = '' - pending + it '数値でなければ失敗する' do + @l.system_picture_id = 'a' + @l.should_not be_valid + end + it '存在するシステム画像でなければ失敗する' do + @l.system_picture_id = 0 + @l.should_not be_valid + end + 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 'コモンライセンスとオリジナルライセンスを含んでいる' do + it 'ライセンスグループを含んでいる' do r = License.show_include_opt - r.should eq [:common_license, :original_license] + r.should eq [:license_group] end end - context 'オプションで原画を含ませたとき' do - it 'コモンライセンスとオリジナルライセンスと原画データを含んでいる' do - r = License.show_include_opt(:include => :original_picture) - r.should eq [:common_license, :original_license, :original_picture] + context 'オプションで素材ライセンスを含ませたとき' do + it 'ライセンスグループと素材ライセンスを含んでいる' do + r = License.show_include_opt(:include => :resource_picture_license) + r.should eq [:license_group, :resource_picture_license] end end end @@ -109,88 +250,31 @@ describe License do 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 'コモンライセンスを含んでいる' do + it 'ライセンスグループを含んでいる' 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 @@ -198,17 +282,13 @@ describe License 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 'コモンライセンスを含んでいる' do + it 'ライセンスグループを含んでいる' 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 @@ -216,17 +296,13 @@ describe License 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 'オリジナルライセンスを含んでいる' do + it 'ライセンスグループを含んでいる' 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 diff --git a/spec/models/original_license_spec.rb b/spec/models/original_license_spec.rb index d8f30108..e69de29b 100644 --- a/spec/models/original_license_spec.rb +++ b/spec/models/original_license_spec.rb @@ -1,558 +0,0 @@ -# -*- 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 diff --git a/spec/models/original_picture_spec.rb b/spec/models/original_picture_spec.rb index f8c8f7c1..0ccc0212 100644 --- a/spec/models/original_picture_spec.rb +++ b/spec/models/original_picture_spec.rb @@ -10,7 +10,9 @@ describe OriginalPicture do @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 diff --git a/spec/models/panel_picture_spec.rb b/spec/models/panel_picture_spec.rb index 15203821..a15713c6 100644 --- a/spec/models/panel_picture_spec.rb +++ b/spec/models/panel_picture_spec.rb @@ -7,7 +7,9 @@ describe PanelPicture 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 @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 @panel = Factory :panel, :author_id => @author.id diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 76996f97..4e546204 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -4,7 +4,9 @@ require 'spec_helper' describe Panel 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 diff --git a/spec/models/resource_picture_license_spec.rb b/spec/models/resource_picture_license_spec.rb new file mode 100644 index 00000000..de4e4f51 --- /dev/null +++ b/spec/models/resource_picture_license_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ResourcePictureLicense do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/resource_picture_spec.rb b/spec/models/resource_picture_spec.rb index 9d91f1f4..28a3430c 100644 --- a/spec/models/resource_picture_spec.rb +++ b/spec/models/resource_picture_spec.rb @@ -10,7 +10,9 @@ describe ResourcePicture do @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 @original_picture = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id class Mgk ; class Image ; end ; end diff --git a/spec/models/speech_balloon_spec.rb b/spec/models/speech_balloon_spec.rb index c7392fb5..69455900 100644 --- a/spec/models/speech_balloon_spec.rb +++ b/spec/models/speech_balloon_spec.rb @@ -8,7 +8,6 @@ describe SpeechBalloon do @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 diff --git a/spec/models/speech_balloon_template_spec.rb b/spec/models/speech_balloon_template_spec.rb index 7ddda413..e4fb9388 100644 --- a/spec/models/speech_balloon_template_spec.rb +++ b/spec/models/speech_balloon_template_spec.rb @@ -15,7 +15,6 @@ describe SpeechBalloonTemplate do @jes = JSON.parse @tes @admin = Factory :admin - @license = Factory :license end describe '検証に於いて' do diff --git a/spec/models/speech_spec.rb b/spec/models/speech_spec.rb index 821f4360..47c0e29f 100644 --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@ -4,7 +4,9 @@ require 'spec_helper' describe Speech do before do Factory :admin - @license = Factory :license + @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) @author = @user.author diff --git a/spec/models/system_picture_spec.rb b/spec/models/system_picture_spec.rb index 626ec474..3546e12b 100644 --- a/spec/models/system_picture_spec.rb +++ b/spec/models/system_picture_spec.rb @@ -4,7 +4,6 @@ require 'spec_helper' describe SystemPicture do before do @admin = Factory :admin - @license = Factory :license end describe '検証に於いて' do
idlicense_group_id namecaption urlcc_bycc_sacc_ndcc_ncno_resizeno_flipno_convertkeep_aspect_ratiosystem_picture_idsettings created_at updated_at
<%= link_to license.id, :action => :browse, :id => license.id %><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %> <%= h license.name %><%= h license.caption %> <%= h license.url %><%= license.cc_by %><%= license.cc_sa %><%= license.cc_nd %><%= license.cc_nc %><%= license.no_resize %><%= license.no_flip %><%= license.no_convert %><%= license.keep_aspect_ratio %><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %><%= h license.settings %> <%= license.created_at %> <%= license.updated_at %>
- <%= link_to 'lesences', :controller => 'licenses', :action => :list %> + <%= link_to 'licenses', :controller => 'licenses', :action => :list %>
- <%= link_to 'common lesences', :controller => 'common_licenses', :action => :list %> -
- <%= link_to 'original lesences', :controller => 'original_licenses', :action => :list %> + <%= link_to 'license_groups', :controller => 'license_groups', :action => :list %>