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
l
end
- def self.stores attrs
+ 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
+#ライセンスグループ
class LicenseGroup < ActiveRecord::Base
has_many :licenses
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
- if (c = License.stores(lattr)) > 0
+ r.save
+ #取っておいたライセンスデータとidでライセンス作成
+ if (c = License.stores(lattr, r.id)) > 0
r.errors.add :base, 'licenses can not create'
end
- r.save
r
end
<div>
-<% if @license.common_license -%>
- <%= link_to 'to common_licenses', :controller => 'common_licenses', :action => :browse, :id => @license.common_license.id %>
-<% else -%>
- <%= link_to 'to original_licenses', :controller => 'original_licenses', :action => :browse, :id => @license.original_license.id %>
-<% end -%>
+<p>
+<div>id</div>
+<%= @license_group.id %>
+</p>
+<p>
+<%= h @license_group.name %>
+</p>
+<p>
+<div>name</div>
+<%= h @license_group.name %>
+</p>
+<p>
+<div>classname</div>
+<%= h @license_group.classname %>
+</p>
+<p>
+<div>caption</div>
+<%= h @license_group.caption %>
+</p>
+<p>
+<div>url</div>
+<%= h @license_group.url %>
+</p>
+<p>
+<%= @license_group.created_at %>
+</p>
+<p>
+<%= @license_group.updated_at %>
+</p>
</div>
+<h1>Listing licenses</h1>
+
+<table>
+ <tr>
+ <th>id</th>
+ <th>license_group_id</th>
+ <th>name</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
+ <th>created_at</th>
+ <th>updated_at</th>
+ </tr>
+
+<% @license_group.licenses.each do |license| %>
+ <tr>
+ <td><%= link_to license.id, :action => :browse, :id => license.id %></td>
+ <td><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %></td>
+ <td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
+ <td><%= h license.url %></td>
+ <td><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %></td>
+ <td><%= h license.settings %></td>
+ <td><%= license.created_at %></td>
+ <td><%= license.updated_at %></td>
+ </tr>
+<% end -%>
+</table>
<%= link_to 'Back', :action => :list %>
+ <th>license_group_id</th>
+ <th>name</th>
+ <th>caption</th>
+ <th>url</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
<div>
-<% if @license.common_license -%>
- <%= link_to 'to common_licenses', :controller => 'common_licenses', :action => :browse, :id => @license.common_license.id %>
-<% else -%>
- <%= link_to 'to original_licenses', :controller => 'original_licenses', :action => :browse, :id => @license.original_license.id %>
-<% end -%>
+<p>
+<div>id</div>
+<%= @license.id %>
+</p>
+<p>
+<div>license_group_id</div>
+<%= h @license.license_group_id %>
+</p>
+<p>
+<div>name</div>
+<%= h @license.name %>
+</p>
+<p>
+<div>caption</div>
+<%= h @license.caption %>
+</p>
+<p>
+<div>url</div>
+<%= h @license.url %>
+</p>
+<div>system_picture_id</div>
+<%= @license.system_picture_id %>
+</p>
+<div>settings</div>
+<%= h @license.settings %>
+</p>
+<p>
+<%= @license.created_at %>
+</p>
+<p>
+<%= @license.updated_at %>
+</p>
</div>
<%= link_to 'Back', :action => :list %>
<table>
<tr>
<th>name</th>
+ <th>caption</th>
<th>url</th>
- <th>cc_by</th>
- <th>cc_sa</th>
- <th>cc_nd</th>
- <th>cc_nc</th>
- <th>no_resize</th>
- <th>no_flip</th>
- <th>no_convert</th>
- <th>keep_aspect_ratio</th>
+ <th>created_at</th>
+ <th>updated_at</th>
<th></th>
</tr>
<% @licenses.each do |license| %>
<tr>
<td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
<td><%= h license.url %></td>
- <td><%= license.cc_by %></td>
- <td><%= license.cc_sa %></td>
- <td><%= license.cc_nd %></td>
- <td><%= license.cc_nc %></td>
- <td><%= license.no_resize %></td>
- <td><%= license.no_flip %></td>
- <td><%= license.no_convert %></td>
- <td><%= license.keep_aspect_ratio %></td>
- <td>
- <% if license.common_license -%>
- <%= link_to 'Show', license.common_license %>
- <% else -%>
- <%= link_to 'Show', license.original_license %>
- <% end -%>
- </td>
+ <td><%= license.created_at %></td>
+ <td><%= license.updated_at %></td>
</tr>
<% end -%>
</table>
-<%= link_to 'new original license', new_original_license_path %>
<table>
<tr>
<th>id</th>
+ <th>license_group_id</th>
<th>name</th>
+ <th>caption</th>
<th>url</th>
- <th>cc_by</th>
- <th>cc_sa</th>
- <th>cc_nd</th>
- <th>cc_nc</th>
- <th>no_resize</th>
- <th>no_flip</th>
- <th>no_convert</th>
- <th>keep_aspect_ratio</th>
+ <th>system_picture_id</th>
+ <th>settings</th>
<th>created_at</th>
<th>updated_at</th>
- <th></th>
</tr>
<% @licenses.each do |license| %>
<tr>
<td><%= link_to license.id, :action => :browse, :id => license.id %></td>
+ <td><%= link_to license.license_group_id, :controller => 'license_groups', :action => :browse, :id => license.license_group_id %></td>
<td><%= h license.name %></td>
+ <td><%= h license.caption %></td>
<td><%= h license.url %></td>
- <td><%= license.cc_by %></td>
- <td><%= license.cc_sa %></td>
- <td><%= license.cc_nd %></td>
- <td><%= license.cc_nc %></td>
- <td><%= license.no_resize %></td>
- <td><%= license.no_flip %></td>
- <td><%= license.no_convert %></td>
- <td><%= license.keep_aspect_ratio %></td>
+ <td><%= link_to license.system_picture_id, :controller => 'system_pictures', :action => :browse, :id => license.system_picture_id %></td>
+ <td><%= h license.settings %></td>
<td><%= license.created_at %></td>
<td><%= license.updated_at %></td>
</tr>
{\r
- "PublicDomain": {\r
+ "PublicDomaina": {\r
"classname": "PublicDomain", \r
"caption": "Public Domain", \r
- "url": "http://test.com/"\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
- "Unknown": {\r
+ "Unknowna": {\r
"classname": "Unknown", \r
"caption": "Unknown owner", \r
- "url": "http://test.uk/"\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
t.string :caption, :null => false, :limit => 30, :default => 'no name'
t.integer :system_picture_id, :null => false, :default => 0
t.string :url, :null => false\r
+ t.string :settings
t.timestamps
end
add_index :licenses, [:name], :unique => true
describe LicensesController do
before do
@admin = Factory :admin
- @lc = Factory :license
- @cl = Factory :common_license, :license_id => @lc.id
+ @lg = Factory :license_group
+ @sp = Factory :system_picture
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
describe '一覧表示に於いて' do
before do
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
sign_in @user
- License.stub(:list).and_return([@lc, @lc, @lc])
+ License.stub(:list).and_return([@l, @l, @l])
end
- context 'パラメータpageについて' do
- it '@pageに値が入る' do
- get :index, :page => 5
- assigns(:page).should eq 5
- end
- it '省略されると@pageに1値が入る' do
- get :index
- assigns(:page).should eq 1
- end
- it '与えられたpage_sizeがセットされている' do
- get :index, :page_size => 15
- assigns(:page_size).should eq 15
- end
- it '省略されると@page_sizeにデフォルト値が入る' do
- get :index
- assigns(:page_size).should eq License.default_page_size
- end
- it '最大を超えると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 1500
- assigns(:page_size).should eq License.max_page_size
- end
- it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
- get :index, :page_size => 0
- assigns(:page_size).should eq License.default_page_size
- end
- end
- context 'つつがなく終わるとき' do
+ context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
get :index
response.should be_success
describe '単体表示に於いて' do
before do
sign_in @user
- License.stub(:show).and_return(@lc)
+ @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ License.stub(:show).and_return(@l)
end
context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
- get :show, :id => @lc.id
+ get :show, :id => @l.id
response.should be_success
end
it 'ライセンスモデルに単体取得を問い合わせている' do
get :show
end
it '@licenseにアレを取得している' do
- get :show, :id => @lc.id
- assigns(:license).id.should eq(@lc.id)
+ get :show, :id => @l.id
+ assigns(:license).id.should eq(@l.id)
end
context 'html形式' do
it 'showテンプレートを描画する' do
- get :show, :id => @lc.id
+ get :show, :id => @l.id
response.should render_template("show")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :show, :id => @lc.id, :format => :json
+ get :show, :id => @l.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
it 'データがアレになっている' do
- get :show, :id => @lc.id, :format => :json
+ get :show, :id => @l.id, :format => :json
json = JSON.parse response.body
json["name"].should match(/peta/)
end
sign_out @user
end
it 'ステータスコード200 okを返す' do
- get :show, :id => @lc.id
+ get :show, :id => @l.id
response.status.should eq 200
end
end
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 []
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 []