surus 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,12 @@
1
1
  require 'surus'
2
2
  require 'yaml'
3
-
3
+ require 'factory_girl'
4
+ require 'faker'
4
5
  require 'rspec'
5
6
 
6
7
  database_config = YAML.load_file(File.expand_path("../database.yml", __FILE__))
7
8
  ActiveRecord::Base.establish_connection database_config["test"]
8
9
 
9
-
10
-
11
10
  class HstoreRecord < ActiveRecord::Base
12
11
  serialize :properties, Surus::Hstore::Serializer.new
13
12
  end
@@ -28,14 +27,55 @@ class DecimalArrayRecord < ActiveRecord::Base
28
27
  serialize :decimals, Surus::Array::DecimalSerializer.new
29
28
  end
30
29
 
30
+ class User < ActiveRecord::Base
31
+ has_many :posts, foreign_key: :author_id
32
+ has_many :posts_with_order,
33
+ foreign_key: :author_id,
34
+ class_name: 'Post',
35
+ order: 'posts.id desc'
36
+ has_many :posts_with_conditions,
37
+ foreign_key: :author_id,
38
+ class_name: 'Post',
39
+ conditions: {subject: 'foo'}
40
+ end
41
+
42
+ class Forum < ActiveRecord::Base
43
+ has_many :posts
44
+ end
45
+
46
+ class Post < ActiveRecord::Base
47
+ belongs_to :forum
48
+ belongs_to :author, class_name: 'User'
49
+ belongs_to :forum_with_impossible_conditions,
50
+ foreign_key: :forum_id,
51
+ class_name: 'Forum',
52
+ conditions: '1=2'
53
+ has_and_belongs_to_many :tags
54
+ end
55
+
56
+ class Tag < ActiveRecord::Base
57
+ has_and_belongs_to_many :posts
58
+ end
31
59
 
60
+ FactoryGirl.find_definitions
32
61
 
33
62
  RSpec.configure do |config|
34
- config.around :disable_transactions => nil do |example|
35
- ActiveRecord::Base.transaction do
63
+ config.around do |example|
64
+ if example.metadata[:disable_transactions]
36
65
  example.call
37
- raise ActiveRecord::Rollback
66
+ else
67
+ ActiveRecord::Base.transaction do
68
+ begin
69
+ example.call
70
+ ensure
71
+ raise ActiveRecord::Rollback
72
+ end
73
+ end
38
74
  end
39
75
  end
76
+
77
+ config.expect_with :rspec do |c|
78
+ c.syntax = :expect
79
+ end
40
80
  end
41
81
 
@@ -4,92 +4,100 @@ describe Surus::SynchronousCommit::Connection, :disable_transactions => true do
4
4
  let(:conn) { ActiveRecord::Base.connection }
5
5
  before { conn.execute "SET synchronous_commit TO ON;" }
6
6
  after { conn.execute "SET synchronous_commit TO ON;" }
7
-
7
+
8
8
  describe "synchronous_commit" do
9
9
  context "without parameter" do
10
10
  subject { conn.synchronous_commit }
11
-
11
+
12
12
  context "when synchronous_commit commit is off" do
13
13
  before { conn.execute "SET synchronous_commit TO OFF;" }
14
14
  it { should == false }
15
15
  end
16
-
16
+
17
17
  context "when synchronous_commit commit is on" do
18
18
  before { conn.execute "SET synchronous_commit TO ON;" }
19
19
  it { should == true }
20
20
  end
21
21
  end
22
-
22
+
23
23
  context "with parameter" do
24
24
  context "true" do
25
25
  before { conn.execute "SET synchronous_commit TO OFF;" }
26
26
  it "sets synchronous_commit to on" do
27
27
  conn.synchronous_commit true
28
- conn.select_value("SHOW synchronous_commit").should == "on"
28
+ value = conn.select_value("SHOW synchronous_commit")
29
+ expect(value).to eq("on")
29
30
  end
30
31
  end
31
-
32
+
32
33
  context "false" do
33
34
  before { conn.execute "SET synchronous_commit TO ON;" }
34
35
  it "sets synchronous_commit to off" do
35
36
  conn.synchronous_commit false
36
- conn.select_value("SHOW synchronous_commit").should == "off"
37
+ value = conn.select_value("SHOW synchronous_commit")
38
+ expect(value).to eq("off")
37
39
  end
38
40
  end
39
-
41
+
40
42
  context "invalid value" do
41
43
  it "raises ArgumentError" do
42
44
  expect{conn.synchronous_commit "foo"}.to raise_error(ArgumentError)
43
45
  end
44
- end
45
-
46
+ end
47
+
46
48
  context "inside transaction" do
47
49
  before { conn.execute "SET synchronous_commit TO OFF;" }
48
-
50
+
49
51
  it "only persists for duration of transaction" do
50
52
  conn.transaction do
51
53
  conn.synchronous_commit true
52
- conn.select_value("SHOW synchronous_commit").should == "on"
54
+ value = conn.select_value("SHOW synchronous_commit")
55
+ expect(value).to eq("on")
53
56
  end
54
- conn.select_value("SHOW synchronous_commit").should == "off"
57
+ value = conn.select_value("SHOW synchronous_commit")
58
+ expect(value).to eq("off")
55
59
  end
56
60
  end
57
61
  end
58
62
  end
59
-
63
+
60
64
  describe "synchronous_commit=" do
61
65
  context "true" do
62
66
  before { conn.execute "SET synchronous_commit TO OFF;" }
63
67
  it "sets synchronous_commit to on" do
64
68
  conn.synchronous_commit true
65
- conn.select_value("SHOW synchronous_commit").should == "on"
69
+ value = conn.select_value("SHOW synchronous_commit")
70
+ expect(value).to eq("on")
66
71
  end
67
72
  end
68
-
73
+
69
74
  context "false" do
70
75
  before { conn.execute "SET synchronous_commit TO ON;" }
71
76
  it "sets synchronous_commit to off" do
72
77
  conn.synchronous_commit false
73
- conn.select_value("SHOW synchronous_commit").should == "off"
78
+ value = conn.select_value("SHOW synchronous_commit")
79
+ expect(value).to eq("off")
74
80
  end
75
81
  end
76
-
82
+
77
83
  context "invalid value" do
78
84
  it "raises ArgumentError" do
79
85
  expect{conn.synchronous_commit "foo"}.to raise_error(ArgumentError)
80
86
  end
81
- end
82
-
87
+ end
88
+
83
89
  context "inside transaction" do
84
90
  before { conn.execute "SET synchronous_commit TO OFF;" }
85
-
91
+
86
92
  it "only persists for duration of transaction" do
87
93
  conn.transaction do
88
94
  conn.synchronous_commit true
89
- conn.select_value("SHOW synchronous_commit").should == "on"
95
+ value = conn.select_value("SHOW synchronous_commit")
96
+ expect(value).to eq("on")
90
97
  end
91
- conn.select_value("SHOW synchronous_commit").should == "off"
98
+ value = conn.select_value("SHOW synchronous_commit")
99
+ expect(value).to eq("off")
92
100
  end
93
101
  end
94
- end
102
+ end
95
103
  end
@@ -25,8 +25,13 @@ Gem::Specification.new do |s|
25
25
  # specify any dependencies here; for example:
26
26
  s.add_dependency 'pg'
27
27
  s.add_dependency 'activerecord', ">= 3.1.0"
28
-
29
- s.add_development_dependency 'rspec', "~> 2.8.0"
28
+
29
+ s.add_development_dependency 'rspec', "~> 2.12.0"
30
30
  s.add_development_dependency 'guard', ">= 0.10.0"
31
- s.add_development_dependency 'guard-rspec', ">= 0.6.0"
31
+ s.add_development_dependency 'guard-rspec', ">= 0.6.0"
32
+ s.add_development_dependency 'rb-fsevent', '~> 0.9.1'
33
+ s.add_development_dependency 'oj', '~> 2.0.2'
34
+ s.add_development_dependency 'pry', '~> 0.9.11'
35
+ s.add_development_dependency 'factory_girl', '~> 4.2.0'
36
+ s.add_development_dependency 'faker', '~> 1.1.2'
32
37
  end
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-10 00:00:00.000000000 Z
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
16
- requirement: &9002920 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9002920
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activerecord
27
- requirement: &9002400 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: 3.1.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *9002400
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.1.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &9018280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 2.8.0
53
+ version: 2.12.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *9018280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: guard
49
- requirement: &9017820 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,18 +69,108 @@ dependencies:
54
69
  version: 0.10.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *9017820
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.10.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: guard-rspec
60
- requirement: &9017360 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.6.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
61
89
  none: false
62
90
  requirements:
63
91
  - - ! '>='
64
92
  - !ruby/object:Gem::Version
65
93
  version: 0.6.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: rb-fsevent
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.9.1
66
102
  type: :development
67
103
  prerelease: false
68
- version_requirements: *9017360
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.1
110
+ - !ruby/object:Gem::Dependency
111
+ name: oj
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 2.0.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.9.11
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.9.11
142
+ - !ruby/object:Gem::Dependency
143
+ name: factory_girl
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 4.2.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 4.2.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: faker
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: 1.1.2
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 1.1.2
69
174
  description: ! "Surus accelerates ActiveRecord with PostgreSQL specific types and\n
70
175
  \ functionality. It enables indexed searching of serialized arrays
71
176
  and hashes.\n It also can control PostgreSQL synchronous commit
@@ -94,6 +199,7 @@ files:
94
199
  - bench/hstore_create.rb
95
200
  - bench/hstore_find.rb
96
201
  - bench/hstore_serialize.rb
202
+ - bench/json_generation.rb
97
203
  - bench/synchronous_commit.rb
98
204
  - lib/generators/surus/hstore/install_generator.rb
99
205
  - lib/generators/surus/hstore/templates/install_hstore.rb
@@ -105,6 +211,14 @@ files:
105
211
  - lib/surus/array/text_serializer.rb
106
212
  - lib/surus/hstore/scope.rb
107
213
  - lib/surus/hstore/serializer.rb
214
+ - lib/surus/json/array_agg_query.rb
215
+ - lib/surus/json/association_scope_builder.rb
216
+ - lib/surus/json/belongs_to_scope_builder.rb
217
+ - lib/surus/json/has_and_belongs_to_many_scope_builder.rb
218
+ - lib/surus/json/has_many_scope_builder.rb
219
+ - lib/surus/json/model.rb
220
+ - lib/surus/json/query.rb
221
+ - lib/surus/json/row_query.rb
108
222
  - lib/surus/synchronous_commit/connection.rb
109
223
  - lib/surus/synchronous_commit/model.rb
110
224
  - lib/surus/version.rb
@@ -115,12 +229,15 @@ files:
115
229
  - spec/array/text_serializer_spec.rb
116
230
  - spec/database.yml
117
231
  - spec/database_structure.sql
232
+ - spec/factories.rb
118
233
  - spec/hstore/scope_spec.rb
119
234
  - spec/hstore/serializer_spec.rb
235
+ - spec/json/json_spec.rb
120
236
  - spec/spec_helper.rb
121
237
  - spec/synchronous_commit/connection_spec.rb
122
238
  - spec/synchronous_commit/model_spec.rb
123
239
  - surus.gemspec
240
+ - tmp/rspec_guard_result
124
241
  homepage: https://github.com/JackC/surus
125
242
  licenses: []
126
243
  post_install_message:
@@ -141,8 +258,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
258
  version: '0'
142
259
  requirements: []
143
260
  rubyforge_project: ''
144
- rubygems_version: 1.8.17
261
+ rubygems_version: 1.8.23
145
262
  signing_key:
146
263
  specification_version: 3
147
264
  summary: PostgreSQL Acceleration for ActiveRecord
148
- test_files: []
265
+ test_files:
266
+ - spec/array/decimal_serializer_spec.rb
267
+ - spec/array/float_serializer_spec.rb
268
+ - spec/array/integer_serializer_spec.rb
269
+ - spec/array/scope_spec.rb
270
+ - spec/array/text_serializer_spec.rb
271
+ - spec/database.yml
272
+ - spec/database_structure.sql
273
+ - spec/factories.rb
274
+ - spec/hstore/scope_spec.rb
275
+ - spec/hstore/serializer_spec.rb
276
+ - spec/json/json_spec.rb
277
+ - spec/spec_helper.rb
278
+ - spec/synchronous_commit/connection_spec.rb
279
+ - spec/synchronous_commit/model_spec.rb