class LicenseGroup < ActiveRecord::Base
+ 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
end
# It's strongly recommended to check this file into your version control system.\r
\r
ActiveRecord::Schema.define(:version => 20120617061753) do\r
+\r
create_table "admins", :force => true do |t|\r
t.string "email", :default => "", :null => false\r
t.string "encrypted_password", :limit => 128, :default => "", :null => false\r
t.datetime "updated_at"\r
end\r
\r
- create_table "imports", :force => true do |t|\r
- t.integer "a"\r
- t.string "b", :null => false\r
- t.datetime "created_at"\r
- t.datetime "updated_at"\r
- end\r
-\r
create_table "licenses", :force => true do |t|\r
t.integer "license_group_id", :default => 0, :null => false\r
t.string "name", :limit => 50, :default => "Default", :null => false\r
# 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.name 'peta2.5'
license.url 'http://test.lc/'
--- /dev/null
+{\r
+ "PublicDomain": {\r
+ "name": "PublicDomain", \r
+ "classname": "PublicDomain", \r
+ "caption": "Public Domain", \r
+ "url": "http://test.com/"\r
+ }\r
+}\r
+# -*- encoding: utf-8 -*-
+#ライセンスグループ
require 'spec_helper'
describe LicenseGroup do
- pending "add some examples to (or delete) #{__FILE__}"
+ before do
+ #テストデータを用意してね
+ @f = Rails.root + 'spec/json/license_group.json'
+ @t = File.open(@f, 'r').read
+ @j = JSON.parse @t
+ 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
+
end
res
end
- def import_file(filename)
+ def import_file(filename, &blk)
t = nil
begin
t = File.open(filename, 'r').read
rescue
return false
end
- self.import t
+ self.import t, blk
end
end
{\r
- "a": 1\r
+ "1": {\r
+ "a": 1,\r
+ "b": "x"\r
+ }\r
}\r
Import.should_receive(:import).with(any_args).exactly(1)
Import.import_file(@f)
end
+ it 'ブロックがあるとき更新を一回依頼する' do
+ Import.any_instance.stub(:valid?).with(any_args).and_return(true)
+ #newでスタブを作るとインスタンス生成ができないので、テスト用スタブで
+ Import.should_receive(:etest).with(any_args).exactly(1)
+ Import.import_file(@f) {|name, attr| Import.etest ; Import.new(attr) }
+ end
#テキスト取り込み成功でTrueが返る
it 'Trueを返す' do
Import.import_file(@f).should be_true