OSDN Git Service

pass test license controller
authoryasushiito <yas@pen-chan.jp>
Fri, 29 Jun 2012 10:16:48 +0000 (19:16 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 29 Jun 2012 10:16:48 +0000 (19:16 +0900)
app/controllers/licenses_controller.rb
app/models/license.rb
app/models/license_group.rb
app/views/license_groups/browse.html.erb
app/views/licenses/browse.html.erb
app/views/licenses/index.html.erb
app/views/licenses/list.html.erb
db/license_groups.json
db/migrate/20120617061753_change_license.rb
spec/controllers/licenses_controller_spec.rb
spec/models/license_group_spec.rb

index 2943122..4fa0b49 100644 (file)
@@ -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
index e1251ea..d150059 100644 (file)
@@ -20,10 +20,11 @@ class License < ActiveRecord::Base
     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
index 41099dc..fa67c7b 100644 (file)
@@ -1,3 +1,4 @@
+#ライセンスグループ
 class LicenseGroup < ActiveRecord::Base
   has_many :licenses
   
@@ -7,13 +8,16 @@ class LicenseGroup < ActiveRecord::Base
   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
   
index c00a645..ffd5af4 100644 (file)
@@ -1,9 +1,62 @@
 <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 %>
index c00a645..97a995d 100644 (file)
@@ -1,9 +1,42 @@
+    <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 %>
index 7df7b82..29afe66 100644 (file)
@@ -3,38 +3,20 @@
 <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 %>
index cdafef5..77ae8b5 100644 (file)
@@ -3,34 +3,25 @@
 <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>
index afb7d37..6736a8f 100644 (file)
@@ -1,12 +1,31 @@
 {\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
index 321af1e..094937a 100644 (file)
@@ -8,6 +8,7 @@ class ChangeLicense < ActiveRecord::Migration
       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
index 9b3c5cd..534097e 100644 (file)
@@ -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
index 92b8560..46a225f 100644 (file)
@@ -179,6 +179,11 @@ describe LicenseGroup do
           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 []
@@ -195,6 +200,11 @@ describe LicenseGroup do
           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 []