{:include => {:license_group => {}}}
end
+ def self.list_by_name name
+ License.find :all, :conditions => ['licenses.name = ?', name], :order => 'licenses.updated_at desc'
+ end
+
def self.store name, attr
r = License.replace_system_picture attr
attr['credit_pictures'] = attr['credit_pictures'].to_json
--- /dev/null
+<h1><%= t '.title' -%></h1>\r
+<table>\r
+ <tr>\r
+ <th><%= t_m 'License.caption' -%></th>\r
+ <th><%= t_m 'License.license_group_id' -%></th>\r
+ </tr>\r
+ <% @licenses.each do |license| %>\r
+ <tr>\r
+ <td>\r
+ <%= link_to t('link.marker'), license_path(license) %>\r
+ <%= link_to h(license.caption), license.url %>\r
+ </td>\r
+ <td>\r
+ <%= link_to h(license.license_group.caption), license_group_path(license.license_group) %>\r
+ </td>\r
+ </tr>\r
+ <% end -%>\r
+</table>\r
end
end
+ describe '管理名検索の一覧に於いて' do
+ before do
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ sign_in @user
+ License.stub(:list_by_name).with(any_args).and_return([@l])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ライセンスモデルに管理名検索を問い合わせている' do
+ License.should_receive(:list_by_name).exactly(1)
+ get :search, :name => @l.name
+ end
+ it '@licensesにリストを取得している' do
+ get :search, :name => @l.name
+ assigns(:licenses).should have_at_least(1).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :name => @l.name
+ response.should be_success
+ end
+ it 'searchテンプレートを描画する' do
+ get :search, :name => @l.name
+ response.should render_template("search")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :name => @l.name, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :search, :name => @l.name, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがリスト構造になっている' do
+ get :search, :name => @l.name, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(1).items
+ end
+ it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
+ get :search, :name => @l.name, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("name").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
+
else
describe '一覧表示に於いて' do
before do
end
end
+ describe '管理名検索に於いて' do
+ before do
+ @sp = FactoryGirl.create :system_picture
+ @lg = FactoryGirl.create :license_group
+ @l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @lg2 = FactoryGirl.create :license_group, :name => 'pubdm'
+ @l2 = FactoryGirl.create :license, :name => 'pettan2.2b', :url => @l.url + 'l2', :license_group_id => @lg.id, :system_picture_id => @sp.id
+ end
+ context 'つつがなく終わるとき' do
+ it 'リストを返す' do
+ l = License.list_by_name @l2.name
+ l.should eq [@l2]
+ end
+ end
+ end
+
describe '更新に於いて' do
before do
@lg = FactoryGirl.create :license_group