selectable_attr_rails 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/MIT-LICENSE +20 -0
- data/README +198 -0
- data/Rakefile +57 -0
- data/VERSION.yml +4 -0
- data/init.rb +5 -0
- data/install.rb +1 -0
- data/lib/selectable_attr_i18n.rb +38 -0
- data/lib/selectable_attr_rails/db_loadable.rb +65 -0
- data/lib/selectable_attr_rails/helpers/abstract_selection_helper.rb +55 -0
- data/lib/selectable_attr_rails/helpers/check_box_group_helper.rb +63 -0
- data/lib/selectable_attr_rails/helpers/radio_button_group_helper.rb +55 -0
- data/lib/selectable_attr_rails/helpers/select_helper.rb +72 -0
- data/lib/selectable_attr_rails/helpers.rb +7 -0
- data/lib/selectable_attr_rails/validatable/base.rb +33 -0
- data/lib/selectable_attr_rails/validatable/enum.rb +16 -0
- data/lib/selectable_attr_rails/validatable.rb +8 -0
- data/lib/selectable_attr_rails/version.rb +3 -0
- data/lib/selectable_attr_rails.rb +43 -0
- data/selectable_attr_rails.gemspec +74 -0
- data/spec/database.yml +6 -0
- data/spec/fixtures/.gitignore +0 -0
- data/spec/introduction_spec.rb +397 -0
- data/spec/schema.rb +30 -0
- data/spec/selectable_attr_i18n_spec.rb +293 -0
- data/spec/spec_helper.rb +30 -0
- data/uninstall.rb +1 -0
- metadata +123 -0
data/spec/schema.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 1) do
|
2
|
+
|
3
|
+
create_table "products", :force => true do |t|
|
4
|
+
t.string "product_type_cd"
|
5
|
+
t.integer "price"
|
6
|
+
t.string "name"
|
7
|
+
t.datetime "created_at"
|
8
|
+
t.datetime "updated_at"
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table "item_masters", :force => true do |t|
|
12
|
+
t.string "category_name", :limit => 20
|
13
|
+
t.integer "item_no"
|
14
|
+
t.string "item_cd", :limit => 2
|
15
|
+
t.string "name", :limit => 20
|
16
|
+
t.datetime "created_at"
|
17
|
+
t.datetime "updated_at"
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table "i18n_item_masters", :force => true do |t|
|
21
|
+
t.string "locale", :limit => 5
|
22
|
+
t.string "category_name", :limit => 20
|
23
|
+
t.integer "item_no"
|
24
|
+
t.string "item_cd", :limit => 2
|
25
|
+
t.string "name", :limit => 20
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,293 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
if defined?(I18n)
|
3
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
4
|
+
|
5
|
+
describe SelectableAttr::Enum do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
I18n.backend = I18n::Backend::Simple.new
|
9
|
+
I18n.backend.store_translations 'en', 'selectable_attrs' => {'enum1' => {
|
10
|
+
'entry1' => 'entry one',
|
11
|
+
'entry2' => 'entry two',
|
12
|
+
'entry3' => 'entry three'
|
13
|
+
} }
|
14
|
+
I18n.backend.store_translations 'ja', 'selectable_attrs' => {'enum1' => {
|
15
|
+
'entry1' => 'エントリ壱',
|
16
|
+
'entry2' => 'エントリ弐',
|
17
|
+
'entry3' => 'エントリ参'
|
18
|
+
} }
|
19
|
+
end
|
20
|
+
|
21
|
+
Enum1 = SelectableAttr::Enum.new do
|
22
|
+
i18n_scope(:selectable_attrs, :enum1)
|
23
|
+
entry 1, :entry1, "エントリ1"
|
24
|
+
entry 2, :entry2, "エントリ2"
|
25
|
+
entry 3, :entry3, "エントリ3"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'test_enum1_i18n' do
|
29
|
+
I18n.locale = nil
|
30
|
+
I18n.locale.should == :en
|
31
|
+
Enum1.name_by_key(:entry1).should == "entry one"
|
32
|
+
Enum1.name_by_key(:entry2).should == "entry two"
|
33
|
+
Enum1.name_by_key(:entry3).should == "entry three"
|
34
|
+
Enum1.names.should == ["entry one", "entry two", "entry three"]
|
35
|
+
|
36
|
+
I18n.locale = 'ja'
|
37
|
+
Enum1.name_by_key(:entry1).should == "エントリ壱"
|
38
|
+
Enum1.name_by_key(:entry2).should == "エントリ弐"
|
39
|
+
Enum1.name_by_key(:entry3).should == "エントリ参"
|
40
|
+
Enum1.names.should == ["エントリ壱", "エントリ弐", "エントリ参"]
|
41
|
+
|
42
|
+
I18n.locale = 'en'
|
43
|
+
Enum1.name_by_key(:entry1).should == "entry one"
|
44
|
+
Enum1.name_by_key(:entry2).should == "entry two"
|
45
|
+
Enum1.name_by_key(:entry3).should == "entry three"
|
46
|
+
Enum1.names.should == ["entry one", "entry two", "entry three"]
|
47
|
+
end
|
48
|
+
|
49
|
+
class EnumBase
|
50
|
+
include ::SelectableAttr::Base
|
51
|
+
end
|
52
|
+
|
53
|
+
class SelectableAttrMock1 < EnumBase
|
54
|
+
selectable_attr :attr1, :default => 2 do
|
55
|
+
i18n_scope(:selectable_attrs, :enum1)
|
56
|
+
entry 1, :entry1, "エントリ1"
|
57
|
+
entry 2, :entry2, "エントリ2"
|
58
|
+
entry 3, :entry3, "エントリ3"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'test_attr1_i18n' do
|
63
|
+
I18n.default_locale = 'ja'
|
64
|
+
I18n.locale = nil
|
65
|
+
I18n.locale.should == 'ja'
|
66
|
+
SelectableAttrMock1.attr1_name_by_key(:entry1).should == "エントリ壱"
|
67
|
+
SelectableAttrMock1.attr1_name_by_key(:entry2).should == "エントリ弐"
|
68
|
+
SelectableAttrMock1.attr1_name_by_key(:entry3).should == "エントリ参"
|
69
|
+
SelectableAttrMock1.attr1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
|
70
|
+
|
71
|
+
I18n.locale = 'ja'
|
72
|
+
SelectableAttrMock1.attr1_name_by_key(:entry1).should == "エントリ壱"
|
73
|
+
SelectableAttrMock1.attr1_name_by_key(:entry2).should == "エントリ弐"
|
74
|
+
SelectableAttrMock1.attr1_name_by_key(:entry3).should == "エントリ参"
|
75
|
+
SelectableAttrMock1.attr1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
|
76
|
+
|
77
|
+
I18n.locale = 'en'
|
78
|
+
SelectableAttrMock1.attr1_name_by_key(:entry1).should == "entry one"
|
79
|
+
SelectableAttrMock1.attr1_name_by_key(:entry2).should == "entry two"
|
80
|
+
SelectableAttrMock1.attr1_name_by_key(:entry3).should == "entry three"
|
81
|
+
SelectableAttrMock1.attr1_options.should == [["entry one",1], ["entry two",2], ["entry three",3]]
|
82
|
+
end
|
83
|
+
|
84
|
+
class SelectableAttrMock2 < EnumBase
|
85
|
+
selectable_attr :enum1, :default => 2 do
|
86
|
+
i18n_scope(:selectable_attrs, :enum1)
|
87
|
+
entry 1, :entry1, "エントリ1"
|
88
|
+
entry 2, :entry2, "エントリ2"
|
89
|
+
entry 3, :entry3, "エントリ3"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'test_enum1_i18n' do
|
94
|
+
I18n.default_locale = 'ja'
|
95
|
+
I18n.locale = nil
|
96
|
+
I18n.locale.should == 'ja'
|
97
|
+
SelectableAttrMock2.enum1_name_by_key(:entry1).should == "エントリ壱"
|
98
|
+
SelectableAttrMock2.enum1_name_by_key(:entry2).should == "エントリ弐"
|
99
|
+
SelectableAttrMock2.enum1_name_by_key(:entry3).should == "エントリ参"
|
100
|
+
SelectableAttrMock2.enum1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
|
101
|
+
|
102
|
+
I18n.locale = 'ja'
|
103
|
+
SelectableAttrMock2.enum1_name_by_key(:entry1).should == "エントリ壱"
|
104
|
+
SelectableAttrMock2.enum1_name_by_key(:entry2).should == "エントリ弐"
|
105
|
+
SelectableAttrMock2.enum1_name_by_key(:entry3).should == "エントリ参"
|
106
|
+
SelectableAttrMock2.enum1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
|
107
|
+
|
108
|
+
I18n.locale = 'en'
|
109
|
+
SelectableAttrMock2.enum1_name_by_key(:entry1).should == "entry one"
|
110
|
+
SelectableAttrMock2.enum1_name_by_key(:entry2).should == "entry two"
|
111
|
+
SelectableAttrMock2.enum1_name_by_key(:entry3).should == "entry three"
|
112
|
+
SelectableAttrMock2.enum1_options.should == [["entry one",1], ["entry two",2], ["entry three",3]]
|
113
|
+
end
|
114
|
+
|
115
|
+
# i18n用のlocaleカラムを持つselectable_attrのエントリ名をDB上に保持するためのモデル
|
116
|
+
class I18nItemMaster < ActiveRecord::Base
|
117
|
+
end
|
118
|
+
|
119
|
+
# selectable_attrを使った場合その3
|
120
|
+
# アクセス時に毎回アクセス時にDBから項目名を取得します。
|
121
|
+
# 対象となる項目名はi18n対応している名称です
|
122
|
+
class ProductWithI18nDB1 < ActiveRecord::Base
|
123
|
+
set_table_name 'products'
|
124
|
+
selectable_attr :product_type_cd do
|
125
|
+
# update_byメソッドには、エントリのidと名称を返すSELECT文を指定する代わりに、
|
126
|
+
# エントリのidと名称の配列の配列を返すブロックを指定することも可能です。
|
127
|
+
update_by(:when => :everytime) do
|
128
|
+
records = I18nItemMaster.find(:all,
|
129
|
+
:conditions => [
|
130
|
+
"category_name = 'product_type_cd' and locale = ? ", I18n.locale.to_s],
|
131
|
+
:order => "item_no")
|
132
|
+
records.map{|r| [r.item_cd, r.name]}
|
133
|
+
end
|
134
|
+
entry '01', :book, '書籍', :discount => 0.8
|
135
|
+
entry '02', :dvd, 'DVD', :discount => 0.2
|
136
|
+
entry '03', :cd, 'CD', :discount => 0.5
|
137
|
+
entry '09', :other, 'その他', :discount => 1
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
it "test_update_entry_name_with_i18n" do
|
143
|
+
I18n.locale = 'ja'
|
144
|
+
# DBに全くデータがなくてもコードで記述してあるエントリは存在します。
|
145
|
+
I18nItemMaster.delete_all("category_name = 'product_type_cd'")
|
146
|
+
ProductWithI18nDB1.product_type_entries.length.should == 4
|
147
|
+
ProductWithI18nDB1.product_type_name_by_key(:book).should == '書籍'
|
148
|
+
ProductWithI18nDB1.product_type_name_by_key(:dvd).should == 'DVD'
|
149
|
+
ProductWithI18nDB1.product_type_name_by_key(:cd).should == 'CD'
|
150
|
+
ProductWithI18nDB1.product_type_name_by_key(:other).should == 'その他'
|
151
|
+
|
152
|
+
ProductWithI18nDB1.product_type_hash_array.should == [
|
153
|
+
{:id => '01', :key => :book, :name => '書籍', :discount => 0.8},
|
154
|
+
{:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
|
155
|
+
{:id => '03', :key => :cd, :name => 'CD', :discount => 0.5},
|
156
|
+
{:id => '09', :key => :other, :name => 'その他', :discount => 1},
|
157
|
+
]
|
158
|
+
|
159
|
+
# DBからエントリの名称を動的に変更できます
|
160
|
+
item_book = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 1, :item_cd => '01', :name => '本')
|
161
|
+
ProductWithI18nDB1.product_type_entries.length.should == 4
|
162
|
+
ProductWithI18nDB1.product_type_name_by_key(:book).should == '本'
|
163
|
+
ProductWithI18nDB1.product_type_name_by_key(:dvd).should == 'DVD'
|
164
|
+
ProductWithI18nDB1.product_type_name_by_key(:cd).should == 'CD'
|
165
|
+
ProductWithI18nDB1.product_type_name_by_key(:other).should == 'その他'
|
166
|
+
ProductWithI18nDB1.product_type_options.should == [['本', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
|
167
|
+
|
168
|
+
ProductWithI18nDB1.product_type_hash_array.should == [
|
169
|
+
{:id => '01', :key => :book, :name => '本', :discount => 0.8},
|
170
|
+
{:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
|
171
|
+
{:id => '03', :key => :cd, :name => 'CD', :discount => 0.5},
|
172
|
+
{:id => '09', :key => :other, :name => 'その他', :discount => 1},
|
173
|
+
]
|
174
|
+
|
175
|
+
# DBからエントリの並び順を動的に変更できます
|
176
|
+
item_book.item_no = 4;
|
177
|
+
item_book.save!
|
178
|
+
item_other = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 1, :item_cd => '09', :name => 'その他')
|
179
|
+
item_dvd = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 2, :item_cd => '02') # nameは指定しなかったらデフォルトが使われます。
|
180
|
+
item_cd = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 3, :item_cd => '03') # nameは指定しなかったらデフォルトが使われます。
|
181
|
+
ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01']]
|
182
|
+
|
183
|
+
# DBからエントリを動的に追加することも可能です。
|
184
|
+
item_toys = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'おもちゃ')
|
185
|
+
ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
|
186
|
+
ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
|
187
|
+
|
188
|
+
ProductWithI18nDB1.product_type_hash_array.should == [
|
189
|
+
{:id => '09', :key => :other, :name => 'その他', :discount => 1},
|
190
|
+
{:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
|
191
|
+
{:id => '03', :key => :cd, :name => 'CD', :discount => 0.5},
|
192
|
+
{:id => '01', :key => :book, :name => '本', :discount => 0.8},
|
193
|
+
{:id => '04', :key => :entry_04, :name => 'おもちゃ'}
|
194
|
+
]
|
195
|
+
|
196
|
+
|
197
|
+
# 英語名を登録
|
198
|
+
item_book = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 4, :item_cd => '01', :name => 'Book')
|
199
|
+
item_other = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 1, :item_cd => '09', :name => 'Others')
|
200
|
+
item_dvd = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 2, :item_cd => '02', :name => 'DVD')
|
201
|
+
item_cd = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 3, :item_cd => '03', :name => 'CD')
|
202
|
+
item_toys = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'Toy')
|
203
|
+
|
204
|
+
# 英語名が登録されていてもI18n.localeが変わらなければ、日本語のまま
|
205
|
+
ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
|
206
|
+
ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
|
207
|
+
|
208
|
+
ProductWithI18nDB1.product_type_hash_array.should == [
|
209
|
+
{:id => '09', :key => :other, :name => 'その他', :discount => 1},
|
210
|
+
{:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
|
211
|
+
{:id => '03', :key => :cd, :name => 'CD', :discount => 0.5},
|
212
|
+
{:id => '01', :key => :book, :name => '本', :discount => 0.8},
|
213
|
+
{:id => '04', :key => :entry_04, :name => 'おもちゃ'}
|
214
|
+
]
|
215
|
+
|
216
|
+
# I18n.localeを変更すると取得できるエントリの名称も変わります
|
217
|
+
I18n.locale = 'en'
|
218
|
+
ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['DVD', '02'], ['CD', '03'], ['Book', '01'], ['Toy', '04']]
|
219
|
+
ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
|
220
|
+
|
221
|
+
ProductWithI18nDB1.product_type_hash_array.should == [
|
222
|
+
{:id => '09', :key => :other, :name => 'Others', :discount => 1},
|
223
|
+
{:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
|
224
|
+
{:id => '03', :key => :cd, :name => 'CD', :discount => 0.5},
|
225
|
+
{:id => '01', :key => :book, :name => 'Book', :discount => 0.8},
|
226
|
+
{:id => '04', :key => :entry_04, :name => 'Toy'}
|
227
|
+
]
|
228
|
+
|
229
|
+
I18n.locale = 'ja'
|
230
|
+
ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
|
231
|
+
ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
|
232
|
+
|
233
|
+
I18n.locale = 'en'
|
234
|
+
ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['DVD', '02'], ['CD', '03'], ['Book', '01'], ['Toy', '04']]
|
235
|
+
ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
|
236
|
+
|
237
|
+
# DBからレコードを削除してもコードで定義したentryは削除されません。
|
238
|
+
# 順番はDBからの取得順で並び替えられたものの後になります
|
239
|
+
item_dvd.destroy
|
240
|
+
ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['CD', '03'], ['Book', '01'], ['Toy', '04'], ['DVD', '02']]
|
241
|
+
|
242
|
+
# DB上で追加したレコードを削除すると、エントリも削除されます
|
243
|
+
item_toys.destroy
|
244
|
+
ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['CD', '03'], ['Book', '01'], ['DVD', '02']]
|
245
|
+
|
246
|
+
# 名称を指定していたDBのレコードを削除したら元に戻ります。
|
247
|
+
item_book.destroy
|
248
|
+
ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['CD', '03'], ['書籍', '01'], ['DVD', '02']]
|
249
|
+
|
250
|
+
# エントリに該当するレコードを全部削除したら、元に戻ります。
|
251
|
+
I18nItemMaster.delete_all("category_name = 'product_type_cd'")
|
252
|
+
ProductWithI18nDB1.product_type_options.should == [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'test_i18n_export' do
|
256
|
+
I18nItemMaster.delete_all("category_name = 'product_type_cd'")
|
257
|
+
|
258
|
+
I18n.locale = 'ja'
|
259
|
+
actual = SelectableAttr::Enum.i18n_export
|
260
|
+
actual.keys.should == ['selectable_attrs']
|
261
|
+
actual['selectable_attrs'].keys.include?('enum1').should == true
|
262
|
+
actual['selectable_attrs']['enum1'].should ==
|
263
|
+
{'entry1'=>"エントリ壱",
|
264
|
+
'entry2'=>"エントリ弐",
|
265
|
+
'entry3'=>"エントリ参"}
|
266
|
+
|
267
|
+
actual['selectable_attrs']['ProductWithI18nDB1'].should ==
|
268
|
+
{'product_type_cd'=>
|
269
|
+
{'book'=>"書籍", 'dvd'=>"DVD", 'cd'=>"CD", 'other'=>"その他"}}
|
270
|
+
|
271
|
+
I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 1, :item_cd => '09', :name => 'Others')
|
272
|
+
I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 2, :item_cd => '02', :name => 'DVD')
|
273
|
+
I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 3, :item_cd => '03', :name => 'CD')
|
274
|
+
I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 4, :item_cd => '01', :name => 'Book')
|
275
|
+
I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'Toy')
|
276
|
+
|
277
|
+
I18n.locale = 'en'
|
278
|
+
actual = SelectableAttr::Enum.i18n_export
|
279
|
+
actual.keys.should == ['selectable_attrs']
|
280
|
+
actual['selectable_attrs'].keys.include?('enum1').should == true
|
281
|
+
actual['selectable_attrs']['enum1'].should ==
|
282
|
+
{'entry1'=>"entry one",
|
283
|
+
'entry2'=>"entry two",
|
284
|
+
'entry3'=>"entry three"}
|
285
|
+
actual['selectable_attrs'].keys.include?('ProductWithI18nDB1').should == true
|
286
|
+
actual['selectable_attrs']['ProductWithI18nDB1'].should ==
|
287
|
+
{'product_type_cd'=>
|
288
|
+
{'book'=>"Book", 'dvd'=>"DVD", 'cd'=>"CD", 'other'=>"Others", 'entry_04'=>"Toy"}}
|
289
|
+
end
|
290
|
+
end
|
291
|
+
else
|
292
|
+
$stderr.puts "WARNING! i18n test skipeed because I18n not found"
|
293
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$KCODE='u'
|
2
|
+
|
3
|
+
FIXTURES_ROOT = File.join(File.dirname(__FILE__), 'fixtures') unless defined?(FIXTURES_ROOT)
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_record'
|
8
|
+
require 'active_record/fixtures'
|
9
|
+
require 'active_record/test_case'
|
10
|
+
require 'action_view'
|
11
|
+
|
12
|
+
require 'selectable_attr'
|
13
|
+
|
14
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
15
|
+
require File.join(File.dirname(__FILE__), '..', 'init')
|
16
|
+
|
17
|
+
require 'yaml'
|
18
|
+
config = YAML.load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
19
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), 'debug.log'))
|
20
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
21
|
+
|
22
|
+
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
23
|
+
|
24
|
+
|
25
|
+
def assert_hash(expected, actual)
|
26
|
+
keys = (expected.keys + actual.keys).uniq
|
27
|
+
keys.each do |key|
|
28
|
+
assert_equal expected[key], actual[key], "unmatch value for #{key.inspect}"
|
29
|
+
end
|
30
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: selectable_attr_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takeshi Akima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-19 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.2
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: actionpack
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: akm-selectable_attr
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.3.5
|
54
|
+
version:
|
55
|
+
description: selectable_attr_rails makes possible to use selectable_attr in rails application
|
56
|
+
email: akima@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- MIT-LICENSE
|
66
|
+
- README
|
67
|
+
- Rakefile
|
68
|
+
- VERSION.yml
|
69
|
+
- init.rb
|
70
|
+
- install.rb
|
71
|
+
- lib/selectable_attr_i18n.rb
|
72
|
+
- lib/selectable_attr_rails.rb
|
73
|
+
- lib/selectable_attr_rails/db_loadable.rb
|
74
|
+
- lib/selectable_attr_rails/helpers.rb
|
75
|
+
- lib/selectable_attr_rails/helpers/abstract_selection_helper.rb
|
76
|
+
- lib/selectable_attr_rails/helpers/check_box_group_helper.rb
|
77
|
+
- lib/selectable_attr_rails/helpers/radio_button_group_helper.rb
|
78
|
+
- lib/selectable_attr_rails/helpers/select_helper.rb
|
79
|
+
- lib/selectable_attr_rails/validatable.rb
|
80
|
+
- lib/selectable_attr_rails/validatable/base.rb
|
81
|
+
- lib/selectable_attr_rails/validatable/enum.rb
|
82
|
+
- lib/selectable_attr_rails/version.rb
|
83
|
+
- selectable_attr_rails.gemspec
|
84
|
+
- spec/database.yml
|
85
|
+
- spec/fixtures/.gitignore
|
86
|
+
- spec/introduction_spec.rb
|
87
|
+
- spec/schema.rb
|
88
|
+
- spec/selectable_attr_i18n_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- uninstall.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/akm/selectable_attr_rails/
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --charset=UTF-8
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: "0"
|
105
|
+
version:
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
version:
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.3.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: selectable_attr_rails makes possible to use selectable_attr in rails application
|
119
|
+
test_files:
|
120
|
+
- spec/introduction_spec.rb
|
121
|
+
- spec/schema.rb
|
122
|
+
- spec/selectable_attr_i18n_spec.rb
|
123
|
+
- spec/spec_helper.rb
|