OSDN Git Service

fix peta spec
[pettanr/pettanr.git] / spec / support / peta_macros.rb
1 module ItemMacros\r
2   # 文字コード検証\r
3   def valid_encode? item, text_column_names\r
4     text_column_names.each do |name|\r
5       expect(item.class.valid_encode_columns).to include name\r
6       item.attributes[name] = "\x83G\x83r\x83]\x83D"\r
7       # バージョンが上がって問題なくなったかもしれない\r
8       #expect { item.valid_encode }.to raise_error(Pettanr::BadRequest)\r
9     end\r
10   end\r
11   \r
12   def define_child_models? model, models\r
13     expect(model.child_models.size).to eq models.size\r
14     models.each do |m|\r
15       expect(model.child_models).to include m\r
16     end\r
17   end\r
18   \r
19   def define_child_element_names? model, item_names\r
20     expect(model.child_models.size).to eq item_names.size\r
21     item_names.each do |m|\r
22       expect(model.child_element_names).to include m\r
23     end\r
24   end\r
25   \r
26   def define_my_manifest? model\r
27     expect(model.my_peta).to eq Manifest.manifest.items[model.item_name]\r
28     expect(model.my_controller).to eq Manifest.manifest.controllers[model.table_name]\r
29     expect(model.my_manifest).to eq Manifest.manifest.models[model.item_name]\r
30   end\r
31   \r
32   # マニフェストを取得するためのショートカット\r
33   def define_my_manifest? model\r
34     expect(model.my_peta).to eq Manifest.manifest.items[model.item_name]\r
35     expect(model.my_controller).to eq Manifest.manifest.controllers[model.table_name]\r
36     expect(model.my_manifest).to eq Manifest.manifest.models[model.item_name]\r
37   end\r
38   \r
39   # 名前の活用が正しく変化していることを確認している\r
40   def set_name? item, subjects\r
41     subjects.each do |name, value|\r
42       expect(item.__send__(name)).to eq value\r
43     end\r
44   end\r
45   \r
46   # 拡張カラムなのかを確認している\r
47   def set_extend_column? model, subjects\r
48     subjects.each do |name, value|\r
49       expect(model.extend_column?(name)).to eq value\r
50     end\r
51   end\r
52   \r
53   # ブースターが用意されているか、名前だけでも確認する\r
54   def set_boosters? item, names\r
55     item.boosts 'post'\r
56     item.boosters.keys.each do |name|\r
57       expect(name).to include names\r
58     end\r
59   end\r
60   \r
61   # 拡張データを畳み込めるか確認する\r
62   def fold_extend_settings? model, attr, extend_column_names\r
63     model.fold_extend_settings attr\r
64     extend_column_names.each do |name|\r
65       expect(attr[name]).to be_kind_of String\r
66     end\r
67   end\r
68   \r
69   def define_test item\r
70     expect {expect(item.dom_id)}.not_to raise_error\r
71     expect {expect(item.editize?)}.not_to raise_error\r
72     expect {expect(item.dom_pool_type)}.not_to raise_error\r
73     expect {expect(item.merge_dom_item_id({}))}.not_to raise_error\r
74     expect {expect(item.tag_attributes)}.not_to raise_error\r
75     expect {expect(item.field_tag_attributes(:hoge))}.not_to raise_error\r
76     expect {expect(item.post_attribute_key)}.not_to raise_error\r
77   end\r
78   \r
79 end\r
80 \r
81 module ContentMacros\r
82   # ぶら下がるそれぞれのリーフを取得\r
83   def define_leaf_items? item, leaf_models\r
84     expect(item.respond_to?(:leaf_items)).to be true\r
85     leaf_models.each do |model|\r
86       expect(item.leaf_items(model)).to_not be_empty\r
87       expect(item.leaf_items(model).first.class).to eq model\r
88     end\r
89   end\r
90   \r
91   def define_leafs_items? item, leaf_models\r
92     expect(item.respond_to?(:leafs_items)).to be true\r
93     expect(item.leafs_items).to_not be_empty\r
94     item.leafs_items.map {|i| i.class }.each do |model|\r
95       expect(leaf_models).to include model\r
96     end\r
97   end\r
98   \r
99 end\r
100 \r
101 module BinderMacros\r
102   # ぶら下がるそれぞれのリーフを取得\r
103   def define_leaf_items? item, leaf_models\r
104     expect(item.respond_to?(:leaf_items)).to be true\r
105     leaf_models.each do |model|\r
106       expect(item.leaf_items(model)).to_not be_empty\r
107       expect(item.leaf_items(model).first.class).to eq model\r
108     end\r
109   end\r
110   \r
111   def define_leafs_items? item, leaf_models\r
112     expect(item.respond_to?(:leafs_items)).to be true\r
113     expect(item.leafs_items).to_not be_empty\r
114     item.leafs_items.map {|i| i.class }.each do |model|\r
115       expect(leaf_models).to include model\r
116     end\r
117   end\r
118   \r
119 end\r
120 \r
121 module LeafMacros\r
122   def define_test item\r
123     expect {expect(item.new_t(0))}.not_to raise_error\r
124   end\r
125   \r
126 end\r
127 \r
128 module RootMacros\r
129   # ぶら下がるそれぞれのリーフを取得\r
130   def define_leaf_items? item, leaf_models\r
131     expect(item.respond_to?(:leaf_items)).to be true\r
132     leaf_models.each do |model|\r
133       expect(item.leaf_items(model)).to_not be_empty\r
134       expect(item.leaf_items(model).first.class).to eq model\r
135     end\r
136   end\r
137   \r
138   def define_leafs_items? item, leaf_models\r
139     expect(item.respond_to?(:leafs_items)).to be true\r
140     expect(item.leafs_items).to_not be_empty\r
141     item.leafs_items.map {|i| i.class }.each do |model|\r
142       expect(leaf_models).to include model\r
143     end\r
144   end\r
145   \r
146 end\r
147 \r
148 module ElementMacros\r
149   # ぶら下がるそれぞれのリーフを取得\r
150   def define_leaf_items? item, leaf_models\r
151     expect(item.respond_to?(:leaf_items)).to be true\r
152     leaf_models.each do |model|\r
153       expect(item.leaf_items(model)).to_not be_empty\r
154       expect(item.leaf_items(model).first.class).to eq model\r
155     end\r
156   end\r
157   \r
158   def define_leafs_items? item, leaf_models\r
159     expect(item.respond_to?(:leafs_items)).to be true\r
160     expect(item.leafs_items).to_not be_empty\r
161     item.leafs_items.map {|i| i.class }.each do |model|\r
162       expect(leaf_models).to include model\r
163     end\r
164   end\r
165   \r
166 end\r
167 \r
168 module OwnerMacros\r
169   # ぶら下がるそれぞれのリーフを取得\r
170   def define_leaf_items? item, leaf_models\r
171     expect(item.respond_to?(:leaf_items)).to be true\r
172     leaf_models.each do |model|\r
173       expect(item.leaf_items(model)).to_not be_empty\r
174       expect(item.leaf_items(model).first.class).to eq model\r
175     end\r
176   end\r
177   \r
178   def define_leafs_items? item, leaf_models\r
179     expect(item.respond_to?(:leafs_items)).to be true\r
180     expect(item.leafs_items).to_not be_empty\r
181     item.leafs_items.map {|i| i.class }.each do |model|\r
182       expect(leaf_models).to include model\r
183     end\r
184   end\r
185   \r
186 end\r
187 \r
188 module SystemResourceMacros\r
189   # ぶら下がるそれぞれのリーフを取得\r
190   def define_leaf_items? item, leaf_models\r
191     expect(item.respond_to?(:leaf_items)).to be true\r
192     leaf_models.each do |model|\r
193       expect(item.leaf_items(model)).to_not be_empty\r
194       expect(item.leaf_items(model).first.class).to eq model\r
195     end\r
196   end\r
197   \r
198   def define_leafs_items? item, leaf_models\r
199     expect(item.respond_to?(:leafs_items)).to be true\r
200     expect(item.leafs_items).to_not be_empty\r
201     item.leafs_items.map {|i| i.class }.each do |model|\r
202       expect(leaf_models).to include model\r
203     end\r
204   end\r
205   \r
206 end\r
207 \r
208 module TemplateMacros\r
209   # ぶら下がるそれぞれのリーフを取得\r
210   def define_leaf_items? item, leaf_models\r
211     expect(item.respond_to?(:leaf_items)).to be true\r
212     leaf_models.each do |model|\r
213       expect(item.leaf_items(model)).to_not be_empty\r
214       expect(item.leaf_items(model).first.class).to eq model\r
215     end\r
216   end\r
217   \r
218   def define_leafs_items? item, leaf_models\r
219     expect(item.respond_to?(:leafs_items)).to be true\r
220     expect(item.leafs_items).to_not be_empty\r
221     item.leafs_items.map {|i| i.class }.each do |model|\r
222       expect(leaf_models).to include model\r
223     end\r
224   end\r
225   \r
226 end\r
227 \r