--- /dev/null
+// Place all the styles related to the LicenseGroup controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+// Place all the styles related to the ResourcePictureLicense controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
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'
--- /dev/null
+class LicenseGroupsController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_admin!, :only => [:list, :browse]
+
+ # GET /license_groups
+ # GET /license_groups.json
+ def index
+ @license_groups = LicenseGroup.list({})
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @license_groups.to_json(LicenseGroup.list_json_opt) }
+ end
+ end
+
+ # GET /license_groups/1
+ # GET /license_groups/1.json
+ def show
+ @license_group = LicenseGroup.show(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @license_group.to_json(LicenseGroup.show_json_include_opt) }
+ end
+ end
+
+ def list
+ @license_groups = LicenseGroup.all
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
+
+ def browse
+ @license_group = LicenseGroup.find(params[:id])
+
+ respond_to do |format|
+ format.html { render layout: 'system' }
+ end
+ end
+end
--- /dev/null
+class ResourcePictureLicenseController < ApplicationController
+end
--- /dev/null
+module LicenseGroupsHelper
+end
--- /dev/null
+module ResourcePictureLicenseHelper
+end
+#
class License < ActiveRecord::Base
- has_one :original_license
- has_one :common_license
- validates :name, :presence => true, :length => {:maximum => 50}
- validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => {:allow_blank => true}
+ belongs_to :license_group
+ belongs_to :system_picture
- 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'
+ validates :license_group_id, :presence => true, :numericality => true, :existence => true
+ validates :name, :presence => true, :length => {:maximum => 50}
+ 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.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
+ res = 0
+ return 0 unless attrs.is_a?(Hash)
+ attrs.each do |name, attr|
+ 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 lg_id, opt = {}
opt.merge!(self.list_opt) unless opt[:include]
- opt.merge!({:order => 'name', :limit => page_size, :offset => (page -1) * page_size})
+ opt.merge!({:conditions => ['licenses.license_group_id = ?', lg_id], :order => 'name'})
License.find(:all, opt)
end
def self.list_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
def self.list_json_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
def self.show rid, opt = {}
end
def self.show_include_opt opt = {}
- res = [:common_license, :original_license]
+ res = [:license_group]
res.push(opt[:include]) if opt[:include]
res
end
def self.show_json_include_opt
- {:include => {:common_license => {}, :original_license => {}}}
+ {:include => {:license_group => {}}}
end
end
--- /dev/null
+class LicenseGroup < ActiveRecord::Base
+ has_many :licenses
+
+ validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
+ validates :classname, :presence => true, :length => {:maximum => 50}
+ validates :caption, :presence => true, :length => {:maximum => 30}
+ validates :url, :presence => true, :length => {:maximum => 200}, :url => true
+
+ def self.store name, attr
+ lattr = attr["licenses_attributes"]
+ attr.delete "licenses_attributes"
+ r = LicenseGroup.modify_object name, attr
+ if (c = License.stores(lattr)) > 0
+ r.errors.add :base, 'licenses can not create'
+ end
+ r.save
+ 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
--- /dev/null
+class ResourcePictureLicense < ActiveRecord::Base
+end
class SystemPicture < ActiveRecord::Base
has_many :balloons
has_many :balloon_templates
+ has_many :licenses
validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
validates :width, :presence => true, :numericality => true, :natural_number => true
--- /dev/null
+<div>
+<% 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 -%>
+</div>
+
+<%= link_to 'Back', :action => :list %>
--- /dev/null
+<h1>Listing license Groups</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>name</th>
+ <th>caption</th>
+ </tr>
+
+<% @license_groups.each do |lg| %>
+ <tr>
+ <td><%= link_to lg.id, license_group_path(lg) %></td>
+ <td><%= h lg.name %></td>
+ <td><%= content_tag(:a, h(lg.caption), :href => lg.url) %></td>
+ </tr>
+<% end -%>
+</table>
--- /dev/null
+<h1>Listing license Groups</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>name</th>
+ <th>classname</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>created_at</th>
+ <th>updated_at</th>
+ </tr>
+
+<% @license_groups.each do |lg| %>
+ <tr>
+ <td><%= link_to lg.id, :action => :browse, :id => lg.id %></td>
+ <td><%= h lg.name %></td>
+ <td><%= h lg.classname %></td>
+ <td><%= h lg.caption %></td>
+ <td><%= h lg.url %></td>
+ <td><%= lg.created_at %></td>
+ <td><%= lg.updated_at %></td>
+ </tr>
+<% end -%>
+</table>
--- /dev/null
+<p id="notice"><%= notice %></p>
+
+<p>
+<%= h @license_group.name %>
+</p>
+<p>
+<%= h @license_group.classname %>
+</p>
+<p>
+<%= h @license_group.caption %>
+</p>
+<p>
+<%= h @license_group.url %>
+</p>
+<p>
+<%= @license_group.created_at %>
+</p>
+<p>
+<%= @license_group.updated_at %>
+</p>
+
+<%= link_to 'Back', license_groups_path %>
</tr>
<tr>
<td>
- <%= link_to 'lesences', :controller => 'licenses', :action => :list %>
+ <%= link_to 'licenses', :controller => 'licenses', :action => :list %>
</td>
</tr>
<tr>
<td>
- <%= link_to 'common lesences', :controller => 'common_licenses', :action => :list %>
- </td>
- </tr>
- <tr>
- <td>
- <%= link_to 'original lesences', :controller => 'original_licenses', :action => :list %>
+ <%= link_to 'license_groups', :controller => 'license_groups', :action => :list %>
</td>
</tr>
<tr>
get :browse
end
end
+ resources :license_groups do
+ collection do
+ get :index
+ get :show
+ get :list
+ get :browse
+ end
+ end
resources :original_licenses do
collection do
get :index
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "Unknown": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/"\r
+ }\r
+}\r
--- /dev/null
+class CreateLicenseGroups < ActiveRecord::Migration
+ def change
+ create_table :license_groups do |t|
+ t.string :name, :null => false, :limit => 50
+ t.string :classname, :null => false, :limit => 50
+ t.string :caption, :null => false, :limit => 30
+ t.string :url, :null => false
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class CreateResourcePictureLicenses < ActiveRecord::Migration
+ def change
+ create_table :resource_picture_licenses do |t|
+ t.integer :resource_picture_id, :null => false
+ t.integer :license_id, :null => false
+ t.string :artist_name, :null => false
+ t.string :credit
+ t.string :settings
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class ChangeLicense < ActiveRecord::Migration
+ def up
+ remove_index :licenses, :column => [:url]
+ drop_table :licenses
+ create_table :licenses do |t|
+ t.integer :license_group_id, :null => false, :default => 0
+ t.string :name, :null => false, :limit => 50, :default => 'Default'
+ t.string :caption, :null => false, :limit => 30, :default => 'no name'
+ t.integer :system_picture_id, :null => false, :default => 0
+ t.string :url, :null => false\r
+ t.timestamps
+ end
+ add_index :licenses, [:name], :unique => true
+ add_index :licenses, [:url], :unique => true
+ end
+
+ def down
+ remove_index :licenses, :column => [:name]
+ remove_index :licenses, :column => [:url]
+ drop_table :licenses
+ create_table :licenses do |t|
+ t.string :name, :null => false\r
+ t.string :url, :null => false\r
+ t.integer :cc_by, :null => false, :default => 0\r
+ t.integer :cc_sa, :null => false, :default => 0\r
+ t.integer :cc_nd, :null => false, :default => 0\r
+ t.integer :cc_nc, :null => false, :default => 0\r
+ t.integer :no_resize, :null => false, :default => 0\r
+ t.integer :no_flip, :null => false, :default => 0\r
+ t.integer :no_convert, :null => false, :default => 0\r
+ t.integer :keep_aspect_ratio, :null => false, :default => 0\r
+
+ t.timestamps
+ end
+ add_index :licenses, [:url], :unique => true
+ end
+end
--- /dev/null
+# -*- 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
--- /dev/null
+require 'spec_helper'
+
+describe ResourcePictureLicenseController do
+
+end
# 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|
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the LicenseGroupHelper. For example:
+#
+# describe LicenseGroupsHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe LicenseGroupsHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the ResourcePictureLicenseHelper. For example:
+#
+# describe ResourcePictureLicenseHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe ResourcePictureLicenseHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "UnknownUrl": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner"\r
+ },\r
+ "UnknownClassname": {\r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/"\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "name": "PublicDomain", \r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "licenses_attributes": {\r
+ "PublicDomain": {\r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/",\r
+ "system_picture": "Data"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ },\r
+ "Unknown": {\r
+ "classname": "Unknown", \r
+ "caption": "Unknown owner", \r
+ "url": "http://test.uk/",\r
+ "licenses_attributes": {\r
+ "UnknownF1": {\r
+ "caption": "Unknown Flag1", \r
+ "url": "http://test.com/f1",\r
+ "system_picture": "Dataf1"\r
+ },\r
+ "UnknownF2": {\r
+ "caption": "Unknown Flag2", \r
+ "url": "http://test.com/f2",\r
+ "system_picture": "Dataf2"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンスグループ
+require 'spec_helper'
+
+describe LicenseGroup do
+ before do
+ #テストデータを用意してね
+ @f = Rails.root + 'spec/json/license_group.json'
+ @t = File.open(@f, 'r').read
+ @j = JSON.parse @t
+ @fs = Rails.root + 'spec/json/license_groups.json'
+ @fes = Rails.root + 'spec/json/invalid_license_groups.json'
+ end
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @lg = Factory.build :license_group
+ @lg.should be_valid
+ end
+
+ context 'nameを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.name = 'a'*50
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.name = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.name = 'a'*51
+ @lg.should_not be_valid
+ end
+ it '重複していたら失敗する' do
+ l = Factory :license_group
+ @lg.should_not be_valid
+ end
+ end
+ context 'classnameを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.classname = 'a'*50
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.classname = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.classname = 'a'*51
+ @lg.should_not be_valid
+ end
+ end
+ context 'captionを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.caption = 'a'*30
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.caption = ''
+ @lg.should_not be_valid
+ end
+ it '51文字以上なら失敗する' do
+ @lg.caption = 'a'*51
+ @lg.should_not be_valid
+ end
+ end
+ context 'urlを検証するとき' do
+ before do
+ @lg = Factory.build :license_group
+ end
+ it 'テストデータの確認' do
+ @lg.url = 'http://test.com/'
+ @lg.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @lg.url = ''
+ @lg.should_not be_valid
+ end
+ it '201文字以上なら失敗する' do
+ @lg.url = 'a'*201
+ @lg.should_not be_valid
+ end
+ it 'url形式でないなら失敗する' do
+ @lg.url = 'aaaaaaa'
+ @lg.should_not be_valid
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @n = @j.keys.first
+ @a = @j.values.first
+ end
+ context 'つつがなく終わるとき' do
+ it 'データ更新準備を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:modify_object).with(any_args).exactly(1)
+ License.stub(:stores).with(any_args).and_return(0)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it 'ライセンスに複数の更新を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(0)
+ License.should_receive(:stores).with(any_args).exactly(1)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it '保存を依頼する' do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(0)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ LicenseGroup.any_instance.should_receive(:save).with(any_args).exactly(1)
+ r = LicenseGroup.store(@n, @a)
+ end
+ it 'オブジェクトを返す' do
+ r = LicenseGroup.store(@n, @a)
+ r.is_a?(LicenseGroup).should be_true
+ r.name.should eq @n
+ r.url.should eq @a["url"]
+ end
+ it 'カラム値からlicenses_attributesが削除されている' do
+ @a["licenses_attributes"].should_not be_nil
+ r = LicenseGroup.store(@n, @a)
+ @a["licenses_attributes"].should be_nil
+ end
+ end
+ context 'ライセンス複数更新が失敗するとき' do
+ before do
+ LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+ License.stub(:stores).with(any_args).and_return(1)
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+ end
+ it '全体エラーメッセージがセットされている' do
+ r = LicenseGroup.store(@n, @a)
+ r.errors[:base].should_not be_blank
+ end
+ it 'ライセンスが作成されていない' do
+ lambda {
+ r = LicenseGroup.store(@n, @a)
+ }.should_not change License, :count
+ end
+ it 'ライセンスグループが作成されていない' do
+ lambda {
+ r = LicenseGroup.store(@n, @a)
+ }.should_not change LicenseGroup, :count
+ end
+ end
+ end
+
+ describe 'インポートに於いて' do
+ before do
+ end
+ context 'つつがなく終わるとき' do
+ it 'ファイルインポートを依頼する' do
+ LicenseGroup.should_receive(:import_file).with(any_args).exactly(1)
+ LicenseGroup.stub(:import_file).with(any_args).and_return([])
+ LicenseGroup.import(@f)
+ end
+ it 'ライセンスグループ更新を一回依頼する' do
+ LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:store).with(any_args).exactly(1)
+ LicenseGroup.import(@f)
+ end
+ it 'ライセンスグループが追加される' do
+ lambda {
+ LicenseGroup.import(@f)
+ }.should change LicenseGroup, :count
+ end
+ it '[]を返す' do
+ 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
+ r = LicenseGroup.import(@fs)
+ r.should eq []
+ end
+ end
+ context 'ライセンスグループ作成に失敗したとき' do
+ before do
+ LicenseGroup.any_instance.stub(:save).with(any_args).and_return(false)
+ LicenseGroup.any_instance.stub(:valid?).with(any_args).and_return(false)
+ end
+ it 'ライセンスグループの数に変化がない' do
+ lambda {
+ LicenseGroup.import(@f)
+ }.should_not change LicenseGroup, :count
+ end
+ it '配列を返す' do
+ r = LicenseGroup.import(@f)
+ r.is_a?(Array).should be_true
+ end
+ it '配列の中身は一件' do
+ r = LicenseGroup.import(@f)
+ r.should have(1).items
+ end
+ it 'ライセンスグループオブジェクトが入っている' do
+ r = LicenseGroup.import(@f)
+ r.first.is_a?(LicenseGroup).should be_true
+ end
+ end
+ context '複数のライセンスグループ作成に失敗したとき' do
+ #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
+ it 'ライセンスグループの数に変化がない' do
+ lambda {
+ LicenseGroup.import(@fes)
+ }.should_not change LicenseGroup, :count
+ end
+ it '途中で保存に失敗しても全件更新依頼する' do
+ LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+ LicenseGroup.should_receive(:store).with(any_args).exactly(3)
+ LicenseGroup.import(@fes)
+ end
+ it '配列を返す' do
+ r = LicenseGroup.import(@fes)
+ r.is_a?(Array).should be_true
+ end
+ it '配列の中身は2件' do
+ r = LicenseGroup.import(@fes)
+ r.should have(2).items
+ end
+ it '配列の中身は失敗したライセンスグループオブジェクトが入っている' do
+ r = LicenseGroup.import(@fes)
+ r[0].is_a?(LicenseGroup).should be_true
+ r[0]["name"].should eq 'UnknownUrl'
+ r[1].is_a?(LicenseGroup).should be_true
+ r[1]["name"].should eq 'UnknownClassname'
+ end
+ end
+ end
+
+ describe '単体取得に於いて' do
+ before do
+ @lg = Factory :license_group
+ end
+ it '指定のコマを返す' do
+ l = LicenseGroup.show @lg.id
+ l.should eq @lg
+ end
+ end
+ describe '関連テーブルプションに於いて' do
+ context 'オプションがないとき' do
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_include_opt
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.show_json_include_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.show_json_include_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe '一覧取得に於いて' do
+ before do
+ @lg = Factory :license_group, :name => "1"
+ end
+ it 'リストを返す' do
+ l = LicenseGroup.list
+ l.should eq [@lg]
+ end
+ it '名前順で並んでいる' do
+ @lg2 = Factory :license_group, :name => "5", :url => 'http://test.ptn/10'
+ l = LicenseGroup.list
+ l.should eq [@lg, @lg2]
+ end
+ end
+ describe 'list関連テーブルプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = LicenseGroup.list_json_opt
+ r.has_key?(:include).should be_true
+ end
+ it '1つの項目を含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.should have(1).items
+ end
+ it 'ライセンスを含んでいる' do
+ r = LicenseGroup.list_json_opt[:include]
+ r.has_key?(:licenses).should be_true
+ end
+ end
+
+end
end
describe '検証に於いて' do
before do
- @l = Factory.build :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it 'オーソドックスなデータなら通る' do
@l.should be_valid
end
+ context 'license_group_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.license_group_id = @lg.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.license_group_id = ''
+ @l.should_not be_valid
+ end
+ it '数値でなければ失敗する' do\r
+ @l.license_group_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するライセンスグループでなければ失敗する' do\r
+ @l.license_group_id = 0\r
+ @l.should_not be_valid\r
+ end\r
+ end
context 'nameを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.name = 'a'*50\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.name = ''
@l.should_not be_valid
@l.name = 'a'*51
@l.should_not be_valid
end
+ it '重複していたら失敗する' do
+ lc = Factory :license
+ @l.should_not be_valid
+ end
+ end
+ context 'captionを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.caption = 'a'*30\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.caption = ''
+ @l.should_not be_valid
+ end
+ it '31文字以上なら失敗する' do
+ @l.caption = 'a'*31
+ @l.should_not be_valid
+ end
end
context 'urlを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 180
+ @l.save!\r
+ @l.should be_valid\r
+ end\r
it 'nullなら失敗する' do
@l.url = ''
@l.should_not be_valid
end
it '201文字以上なら失敗する' do
- @l.url = 'a'*201
+ @l.url = 'http://test.jp/aaaaa' + 'a' * 181
@l.should_not be_valid
end
- it '重複していたら失敗する' do
- lc = Factory :license
+ it 'url形式でなら失敗する' do
+ @l.url = 'a'*200\r
+ @l.should_not be_valid\r
+ end
+ end
+ context 'system_picture_idを検証するとき' do
+ it 'テストデータの確認' do\r
+ @l.system_picture_id = @sp.id\r
+ @l.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do
+ @l.system_picture_id = ''
@l.should_not be_valid
end
- it 'url形式でなら失敗する' do
- @l.url = ''
- pending
+ it '数値でなければ失敗する' do\r
+ @l.system_picture_id = 'a'\r
+ @l.should_not be_valid\r
+ end\r
+ it '存在するシステム画像でなければ失敗する' do\r
+ @l.system_picture_id = 0\r
+ @l.should_not be_valid\r
+ end\r
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @lg = Factory :license_group
+ @f = Rails.root + 'spec/json/license_group.json'
+ @t = File.open(@f, 'r').read
+ @j = JSON.parse @t
+ @n = @j.keys.first
+ @a = @j.values.first
+ @attr = @a["licenses_attributes"]
+ @ln = @attr.keys.first
+ @la = @attr.values.first
+ @la["license_group_id"] = @lg.id
+ end
+ context 'つつがなく終わるとき' do
+ it 'システム画像置換を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.should_receive(:replace_system_picture).with(any_args).exactly(1)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ r = License.store(@ln, @la)
+ end
+ it 'データ更新準備を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.should_receive(:modify_object).with(any_args).exactly(1)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ r = License.store(@ln, @la)
+ end
+ it '保存を依頼する' do
+ License.stub(:replace_system_picture).with(any_args).and_return(true)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ License.any_instance.stub(:save).with(any_args).and_return(true)
+ License.any_instance.should_receive(:save).with(any_args).exactly(1)
+ r = License.store(@ln, @la)
+ end
+ it 'オブジェクトを返す' do
+ r = License.store(@ln, @la)
+ r.is_a?(License).should be_true
+ r.name.should eq @ln
+ r.url.should eq @la["url"]
+ end
+ it 'ライセンスが作成されている' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should change License, :count
+ end
+ it 'システム画像が作成されている' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should change SystemPicture, :count
+ end
+ end
+ context 'システム画像置換が失敗するとき' do
+ before do
+ License.stub(:replace_system_picture).with(any_args).and_return(false)
+ License.stub(:modify_object).with(any_args).and_return(License.new)
+ end
+ it '全体エラーメッセージがセットされている' do
+ r = License.store(@ln, @la)
+ r.errors[:base].should_not be_blank
+ end
+ it 'ライセンスが作成されていない' do
+ lambda {
+ r = License.store(@ln, @la)
+ }.should_not change License, :count
end
end
end
- describe '対象ライセンスの取得に於いて' do
+ describe '複数の更新に於いて' do
before do
- @lc = Factory :license
+ @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)
+ 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)
+ 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)
+ 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)
+ 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)
+ r.should eq 0
end
end
end
- #作成が
describe '単体取得に於いて' do
before do
- @lcl = Factory :license
- @cl = Factory :common_license, :license_id => @lcl.id
- @lol = Factory :license, :url => 'http://test.ptn/10'
- @ol = Factory :original_license, :license_id => @lol.id, :url => 'http://test.ptn/10'
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
it '指定のコマを返す' do
- l = License.show @lcl.id
- l.should eq @lcl
+ l = License.show @l.id
+ l.should eq @l
end
end
describe '関連テーブルプションに於いて' do
context 'オプションがないとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_include_opt
- r.should eq [:common_license, :original_license]
+ r.should eq [:license_group]
end
end
- context 'オプションで原画を含ませたとき' do
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨å\8e\9fç\94»ã\83\87ã\83¼ã\82¿を含んでいる' do
- r = License.show_include_opt(:include => :original_picture)
- r.should eq [:common_license, :original_license, :original_picture]
+ context 'オプションで素材ライセンスを含ませたとき' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97ã\81¨ç´ æ\9d\90ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ r = License.show_include_opt(:include => :resource_picture_license)
+ r.should eq [:license_group, :resource_picture_license]
end
end
end
r = License.show_json_include_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.show_json_include_opt[:include]
- r.should have(2).items
+ r.should have(1).items
end
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.show_json_include_opt[:include]
- r.has_key?(:common_license).should be_true
- end
- it 'オリジナルライセンスを含んでいる' do
- r = License.show_json_include_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe '一覧取得に於いて' do
before do
- @lcl = Factory :license, :name => 'peta2.0'
- @cl = Factory :common_license, :license_id => @lcl.id
- end
- context 'page補正について' do
- it '文字列から数値に変換される' do
- License.page('8').should eq 8
- end
- it 'nilの場合は1になる' do
- License.page().should eq 1
- end
- it '0以下の場合は1になる' do
- License.page('0').should eq 1
- end
- end
- context 'page_size補正について' do
- it '文字列から数値に変換される' do
- License.page_size('7').should eq 7
- end
- it 'nilの場合はLicense.default_page_sizeになる' do
- License.page_size().should eq License.default_page_size
- end
- it '0以下の場合はLicense.default_page_sizeになる' do
- License.page_size('0').should eq License.default_page_size
- end
- it 'License.max_page_sizeを超えた場合はLicense.max_page_sizeになる' do
- License.page_size('1000').should eq License.max_page_size
- end
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @lg2 = Factory :license_group, :name => 'pubdm'
end
it 'リストを返す' do
- pl = License.list
- pl.should eq [@lcl]
+ l = License.list @lg.id
+ 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'
- 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
+ it 'グループ順,名前順で並んでいる' do
+ @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 @lg.id
+ l.should eq [@l, @l2]
end
end
describe 'list関連テーブルプションに於いて' do
r = License.list_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_opt[:include]
- r.should have(2).items
+ r.should have(1).items
end
- it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_opt[:include]
- r.has_key?(:common_license).should be_true
- end
- it 'オリジナルライセンスを含んでいる' do
- r = License.list_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
r = License.list_json_opt
r.has_key?(:include).should be_true
end
- it '2つの項目を含んでいる' do
- r = License.list_json_opt[:include]
- r.should have(2).items
- end
- it 'コモンライセンスを含んでいる' do
+ it '1つの項目を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:common_license).should be_true
+ r.should have(1).items
end
- it 'ã\82ªã\83ªã\82¸ã\83\8aã\83«ã\83©ã\82¤ã\82»ã\83³ã\82¹を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97を含んでいる' do
r = License.list_json_opt[:include]
- r.has_key?(:original_license).should be_true
+ r.has_key?(:license_group).should be_true
end
end
--- /dev/null
+require 'spec_helper'
+
+describe ResourcePictureLicense do
+ pending "add some examples to (or delete) #{__FILE__}"
+end