bitrix_on_rails 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class ActiveRecordTest < Test::Unit::TestCase
4
+ context 'has_infoblock' do
5
+ setup do
6
+ @iblock = Factory.create(:iblock3)
7
+ BitrixOnRails.define_iblock_class @iblock.id
8
+
9
+ id = @iblock.id
10
+
11
+ class Post < ActiveRecord::Base
12
+ end
13
+
14
+ Post.instance_eval do
15
+ has_infoblock id, :property_13
16
+ end
17
+ end
18
+
19
+ should 'create associations' do
20
+ assert Post.reflections.include?("iblock_element_prop_s#{@iblock.id}".to_sym)
21
+ assert Post.reflections.include?(:iblock_element)
22
+ assert Object.const_get("IblockElementPropS#{@iblock.id}").reflections.include?(:post)
23
+ end
24
+
25
+ should 'delegate property methods to iblock_element' do
26
+ post = Post.new
27
+ [:preview_mpage, :glob_class, :preview_mpage=].each { |m|
28
+ assert_respond_to post, m
29
+ }
30
+ end
31
+
32
+ should 'not delegete multiple property assignment methods to iblock_element' do
33
+ assert_not_respond_to Post, :glob_class=
34
+ end
35
+ end
36
+ end
@@ -1,20 +1,25 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require 'helper'
3
4
 
4
5
  class TestBitrixOnRails < Test::Unit::TestCase
5
- should "автоматичеки создает модели свойств для всех инфоблоков при инициализации" do
6
- assert_equal 2, BitrixOnRails.init.count, '2 инфоблока в нашей схеме'
7
- # assert defined?(IblockElementPropM7), 'должен определиться автоматически'
8
- puts IblockElementPropM7
6
+ def tests
7
+ assert_respond_to BitrixOnRails, :configure
9
8
  end
10
9
 
11
- should "Брать свойства для блока и кешировать их" do
10
+ # should "автоматичеки создает модели свойств для всех инфоблоков при инициализации" do
11
+ # assert_equal 2, BitrixOnRails.init.count, '2 инфоблока в нашей схеме'
12
+ # # assert defined?(IblockElementPropM7), 'должен определиться автоматически'
13
+ # puts IblockElementPropM7
14
+ # end
12
15
 
13
- Iblock.get_properties(3)
16
+ # should "Брать свойства для блока и кешировать их" do
14
17
 
15
- # А этот запрос уже кеширован
16
- Iblock.get_properties(3)
17
- end
18
+ # Iblock.get_properties(3)
19
+
20
+ # # А этот запрос уже кеширован
21
+ # Iblock.get_properties(3)
22
+ # end
18
23
  end
19
24
 
20
25
 
@@ -0,0 +1,77 @@
1
+ require 'helper'
2
+
3
+ class IblockElementTest < Test::Unit::TestCase
4
+
5
+ context 'define_iblock_class' do
6
+
7
+ context 'with class_name set to nil' do
8
+ setup do
9
+ BitrixOnRails.define_iblock_class(3)
10
+ end
11
+
12
+ should 'create class IblockElement3 in global namespace' do
13
+ assert_not_nil Object.const_defined?('IblockElement3')
14
+ end
15
+ end
16
+
17
+ context 'with class name in global namespace' do
18
+ setup do
19
+ BitrixOnRails.define_iblock_class(3, :class_name => 'PostProperties')
20
+ end
21
+
22
+ should 'create class PostProperties in global namespace' do
23
+ assert_not_nil Object.const_defined?('PostProperties')
24
+ end
25
+ end
26
+
27
+ context 'with class name in non global namespace' do
28
+ setup do
29
+ Object.const_set('Post', Class.new)
30
+ BitrixOnRails.define_iblock_class(3, :class_name => 'Post::Element')
31
+ end
32
+
33
+ should 'create class Element in Post namespace' do
34
+ assert_not_nil Post.const_defined?('Element')
35
+ end
36
+ end
37
+
38
+ context 'behaviour' do
39
+ setup do
40
+ BitrixOnRails.define_iblock_class(3)
41
+ end
42
+
43
+ should 'create association with property classes' do
44
+ assert_not_nil IblockElement3.reflections[:property_set]
45
+ assert_not_nil IblockElement3.reflections[:m_props]
46
+ end
47
+
48
+ should 'create property classes' do
49
+ assert_not_nil Object.const_defined?('IblockElementPropS3')
50
+ assert_not_nil Object.const_defined?('IblockElementPropM3')
51
+ end
52
+
53
+ should 'create associations for property classes in IblockElement' do
54
+ assert_not_nil IblockElement.reflections[:iblock_element_prop_s3]
55
+ assert_not_nil IblockElement.reflections[:iblock_element_prop_m3]
56
+ end
57
+
58
+ should 'add class information in BitrixOnRails.infoblocks' do
59
+ assert_equal IblockElement3, BitrixOnRails.infoblocks[3]
60
+ end
61
+ end
62
+
63
+ context 'with passed :extended_by' do
64
+ setup do
65
+ Object.const_set('IblockElementExtension', Module.new{ def some_method ; end})
66
+ BitrixOnRails.define_iblock_class(3, :extended_by => 'IblockElementExtension')
67
+ end
68
+
69
+ should 'extend created class with given module' do
70
+ # Не нашел другого способа проверить, что модуль был включен в класс
71
+ assert IblockElement3.methods.include?(:some_method)
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,111 @@
1
+ # encoding: UTF-8
2
+ require 'helper'
3
+
4
+ class IblockElementPropSTest < Test::Unit::TestCase
5
+ PROP_S_VALUES = [
6
+ 11286, nil, # post_id
7
+ 'a:2:{s:4:"TEXT";s:22:"Полемика по повышению.";s:4:"TYPE";s:4:"html";}', nil, #preview_mpage
8
+ nil, nil # glob_class
9
+ ]
10
+
11
+ def create_iblock(iblock_factory, iblock_element_factory, prop_s_values = [], prop_m_values = [])
12
+ iblock = Factory.create(iblock_factory)
13
+
14
+ BitrixOnRails.define_iblock_class(iblock.id)
15
+
16
+ @s_prop_class = Object.const_get("IblockElementPropS#{iblock.id}")
17
+ @m_prop_class = Object.const_get("IblockElementPropM#{iblock.id}")
18
+
19
+ properties = @s_prop_class.columns.collect { |c| c.name }
20
+
21
+ @iblock_element = Factory.create(iblock_element_factory, :iblock => iblock)
22
+
23
+ prop_m_values.each { |v|
24
+ @m_prop_class.create(:iblock_element_id => @iblock_element.id, :iblock_property_id => iblock.iblock_properties.last.id, :value => v)
25
+ }
26
+
27
+ prop_s_values = [@iblock_element.id] + prop_s_values
28
+ @iblock_element_prop_s = @s_prop_class.create(properties.inject({}){ |a,e| a[e] = prop_s_values[properties.find_index(e)]; a})
29
+ end
30
+
31
+ context 'acts_as_iblock_prop_s' do
32
+ setup do
33
+ @iblock = Factory.create(:iblock3)
34
+
35
+ BitrixOnRails.define_iblock_class(@iblock.id)
36
+
37
+ @s_prop_class = Object.const_get("IblockElementPropS#{@iblock.id}")
38
+ end
39
+
40
+ should 'set table name to b_iblock_element_prop_s#{id}' do
41
+ assert_equal "b_iblock_element_prop_s#{@iblock.id}", @s_prop_class.table_name
42
+ end
43
+
44
+ should 'set association with iblock_element' do
45
+ assert @s_prop_class.reflections.include?(:iblock_element)
46
+ assert_equal BitrixOnRails.infoblocks[@iblock.id].name, @s_prop_class.reflections[:iblock_element].class_name
47
+ end
48
+
49
+ should 'define access methods for single properties' do
50
+ [:post_id, :post_id=, :find_by_post_id].each { |m|
51
+ assert @s_prop_class.instance_methods.include?(m)
52
+ }
53
+
54
+ [:preview_mpage, :preview_mpage=, :find_by_preview_mpage].each { |m|
55
+ assert @s_prop_class.instance_methods.include?(m)
56
+ }
57
+ end
58
+ end
59
+
60
+ context 'instance methods' do
61
+ setup do
62
+ create_iblock :iblock3, :iblock_element3, PROP_S_VALUES, [144, 1394860, 35, 6, 165]
63
+ end
64
+
65
+ should 'return unserialized values' do
66
+ assert_equal 11286, @iblock_element_prop_s.post_id
67
+ assert_equal 'Полемика по повышению.', @iblock_element_prop_s.preview_mpage
68
+ end
69
+
70
+ should 'return instance of MPropValuesWrapper for multiple property' do
71
+ assert @iblock_element_prop_s.glob_class.is_a?(BitrixOnRails::IblockElementPropS::MPropValuesWrapper)
72
+ end
73
+ end
74
+
75
+ context 'MPropValuesWrapper' do
76
+ setup do
77
+ create_iblock :iblock3, :iblock_element3, PROP_S_VALUES, [10]
78
+ end
79
+
80
+ should 'add new record to b_iblock_element_prop_m on add' do
81
+ assert_difference("#{@iblock_element_prop_s.m_prop_class}.count") do
82
+ @iblock_element_prop_s.glob_class.add(16)
83
+ end
84
+ end
85
+
86
+ should 'delete record on destroy' do
87
+ assert_difference("#{@iblock_element_prop_s.m_prop_class}.count", -1) do
88
+ @iblock_element_prop_s.glob_class.remove(10)
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'serialize' do
94
+ setup do
95
+ create_iblock :iblock3, :iblock_element3, PROP_S_VALUES
96
+ end
97
+
98
+ should 'convert value into serialized hash if user_type is HTML' do
99
+ @iblock_element_prop_s.preview_mpage = 'BitrixOnRails is awesome, bro!'
100
+ assert_equal 'a:2:{s:4:"TEXT";s:30:"BitrixOnRails is awesome, bro!";s:4:"TYPE";s:4:"html";}',
101
+ @iblock_element_prop_s.send("property_#{@s_prop_class.s_props[:preview_mpage][:id]}")
102
+ end
103
+
104
+ should 'convert value into specially formatted string if user_type is DateTime' do
105
+ t = Time.parse '15 Aug 2011 16:32:18'
106
+ @iblock_element_prop_s.publication_date = t
107
+ assert_equal '2011-08-15 16:32:18',
108
+ @iblock_element_prop_s.send("property_#{@s_prop_class.s_props[:publication_date][:id]}")
109
+ end
110
+ end
111
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitrix_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-04 00:00:00.000000000 +04:00
13
- default_executable:
12
+ date: 2011-08-29 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- requirement: &2156264660 !ruby/object:Gem::Requirement
16
+ requirement: &19514180 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,21 @@ dependencies:
22
21
  version: '3.0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2156264660
24
+ version_requirements: *19514180
25
+ - !ruby/object:Gem::Dependency
26
+ name: php_serialize
27
+ requirement: &19513460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19513460
26
36
  - !ruby/object:Gem::Dependency
27
37
  name: sqlite3
28
- requirement: &2156263400 !ruby/object:Gem::Requirement
38
+ requirement: &19512780 !ruby/object:Gem::Requirement
29
39
  none: false
30
40
  requirements:
31
41
  - - ! '>='
@@ -33,10 +43,10 @@ dependencies:
33
43
  version: '0'
34
44
  type: :development
35
45
  prerelease: false
36
- version_requirements: *2156263400
46
+ version_requirements: *19512780
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: shoulda
39
- requirement: &2156261940 !ruby/object:Gem::Requirement
49
+ requirement: &19512200 !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,10 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *2156261940
57
+ version_requirements: *19512200
48
58
  - !ruby/object:Gem::Dependency
49
59
  name: bundler
50
- requirement: &2156260820 !ruby/object:Gem::Requirement
60
+ requirement: &19511460 !ruby/object:Gem::Requirement
51
61
  none: false
52
62
  requirements:
53
63
  - - ~>
@@ -55,10 +65,10 @@ dependencies:
55
65
  version: 1.0.0
56
66
  type: :development
57
67
  prerelease: false
58
- version_requirements: *2156260820
68
+ version_requirements: *19511460
59
69
  - !ruby/object:Gem::Dependency
60
70
  name: jeweler
61
- requirement: &2156259780 !ruby/object:Gem::Requirement
71
+ requirement: &19509100 !ruby/object:Gem::Requirement
62
72
  none: false
63
73
  requirements:
64
74
  - - ~>
@@ -66,10 +76,10 @@ dependencies:
66
76
  version: 1.6.4
67
77
  type: :development
68
78
  prerelease: false
69
- version_requirements: *2156259780
79
+ version_requirements: *19509100
70
80
  - !ruby/object:Gem::Dependency
71
81
  name: rcov
72
- requirement: &2156258340 !ruby/object:Gem::Requirement
82
+ requirement: &19508220 !ruby/object:Gem::Requirement
73
83
  none: false
74
84
  requirements:
75
85
  - - ! '>='
@@ -77,21 +87,10 @@ dependencies:
77
87
  version: '0'
78
88
  type: :development
79
89
  prerelease: false
80
- version_requirements: *2156258340
90
+ version_requirements: *19508220
81
91
  - !ruby/object:Gem::Dependency
82
92
  name: ruby-debug19
83
- requirement: &2156257140 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- type: :development
90
- prerelease: false
91
- version_requirements: *2156257140
92
- - !ruby/object:Gem::Dependency
93
- name: test-unit
94
- requirement: &2156255520 !ruby/object:Gem::Requirement
93
+ requirement: &19507400 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ! '>='
@@ -99,10 +98,10 @@ dependencies:
99
98
  version: '0'
100
99
  type: :development
101
100
  prerelease: false
102
- version_requirements: *2156255520
101
+ version_requirements: *19507400
103
102
  - !ruby/object:Gem::Dependency
104
- name: rb-fsevent
105
- requirement: &2156236280 !ruby/object:Gem::Requirement
103
+ name: factory_girl
104
+ requirement: &19506560 !ruby/object:Gem::Requirement
106
105
  none: false
107
106
  requirements:
108
107
  - - ! '>='
@@ -110,10 +109,10 @@ dependencies:
110
109
  version: '0'
111
110
  type: :development
112
111
  prerelease: false
113
- version_requirements: *2156236280
112
+ version_requirements: *19506560
114
113
  - !ruby/object:Gem::Dependency
115
- name: growl
116
- requirement: &2156220420 !ruby/object:Gem::Requirement
114
+ name: test-unit
115
+ requirement: &19505960 !ruby/object:Gem::Requirement
117
116
  none: false
118
117
  requirements:
119
118
  - - ! '>='
@@ -121,10 +120,10 @@ dependencies:
121
120
  version: '0'
122
121
  type: :development
123
122
  prerelease: false
124
- version_requirements: *2156220420
123
+ version_requirements: *19505960
125
124
  - !ruby/object:Gem::Dependency
126
125
  name: guard-test
127
- requirement: &2156216740 !ruby/object:Gem::Requirement
126
+ requirement: &19505320 !ruby/object:Gem::Requirement
128
127
  none: false
129
128
  requirements:
130
129
  - - ! '>='
@@ -132,10 +131,10 @@ dependencies:
132
131
  version: '0'
133
132
  type: :development
134
133
  prerelease: false
135
- version_requirements: *2156216740
134
+ version_requirements: *19505320
136
135
  - !ruby/object:Gem::Dependency
137
136
  name: test-unit-rr
138
- requirement: &2156214480 !ruby/object:Gem::Requirement
137
+ requirement: &19504640 !ruby/object:Gem::Requirement
139
138
  none: false
140
139
  requirements:
141
140
  - - ! '>='
@@ -143,7 +142,7 @@ dependencies:
143
142
  version: '0'
144
143
  type: :development
145
144
  prerelease: false
146
- version_requirements: *2156214480
145
+ version_requirements: *19504640
147
146
  description: Использование инфоблоков 1С-Битрикс в Ruby On Rails проектах
148
147
  email: danil@orionet.ru
149
148
  executables: []
@@ -175,15 +174,20 @@ files:
175
174
  - lib/active_record/connection_adapters/mysql2_downcase_adapter.rb
176
175
  - lib/bitrix_on_rails.rb
177
176
  - lib/bitrix_on_rails/active_record.rb
177
+ - lib/bitrix_on_rails/configuration.rb
178
178
  - lib/bitrix_on_rails/engine.rb
179
+ - lib/bitrix_on_rails/iblock_element.rb
179
180
  - lib/bitrix_on_rails/iblock_element_prop_m.rb
180
181
  - lib/bitrix_on_rails/iblock_element_prop_s.rb
181
182
  - test/dump.sql
183
+ - test/factories.rb
182
184
  - test/get_dump.sh
183
185
  - test/helper.rb
184
186
  - test/schema.rb
187
+ - test/test_active_record.rb
185
188
  - test/test_bitrix_on_rails.rb
186
- has_rdoc: true
189
+ - test/test_iblock_element.rb
190
+ - test/test_iblock_element_prop_s.rb
187
191
  homepage: http://github.com/dapi/bitrix_on_rails
188
192
  licenses:
189
193
  - MIT
@@ -199,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
203
  version: '0'
200
204
  segments:
201
205
  - 0
202
- hash: 4502115155340295236
206
+ hash: 3075423241846664278
203
207
  required_rubygems_version: !ruby/object:Gem::Requirement
204
208
  none: false
205
209
  requirements:
@@ -208,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
212
  version: '0'
209
213
  requirements: []
210
214
  rubyforge_project:
211
- rubygems_version: 1.6.2
215
+ rubygems_version: 1.8.6
212
216
  signing_key:
213
217
  specification_version: 3
214
218
  summary: Работа с инфоблоками 1С-Битрикс