ardm 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.ruby-version +1 -0
  2. data/Gemfile +14 -2
  3. data/ardm.gemspec +1 -1
  4. data/lib/ardm.rb +8 -0
  5. data/lib/ardm/active_record.rb +0 -5
  6. data/lib/ardm/active_record/associations.rb +27 -10
  7. data/lib/ardm/active_record/predicate_builder/rails4.rb +12 -5
  8. data/lib/ardm/active_record/property.rb +4 -3
  9. data/lib/ardm/active_record/record.rb +10 -6
  10. data/lib/ardm/active_record/relation.rb +67 -2
  11. data/lib/ardm/data_mapper.rb +2 -0
  12. data/lib/ardm/data_mapper/record.rb +19 -22
  13. data/lib/ardm/property/support/paranoid_base.rb +1 -1
  14. data/lib/ardm/query/expression.rb +5 -15
  15. data/lib/ardm/query/operator.rb +3 -3
  16. data/lib/ardm/version.rb +1 -1
  17. data/spec/fixtures/article.rb +1 -1
  18. data/spec/fixtures/resource_blog.rb +53 -0
  19. data/spec/integration/comma_separated_list_spec.rb +4 -4
  20. data/spec/integration/dirty_minder_spec.rb +1 -1
  21. data/spec/integration/enum_spec.rb +2 -2
  22. data/spec/integration/epoch_time_spec.rb +2 -2
  23. data/spec/integration/file_path_spec.rb +4 -4
  24. data/spec/integration/flag_spec.rb +5 -3
  25. data/spec/integration/json_spec.rb +3 -3
  26. data/spec/public/model_spec.rb +78 -8
  27. data/spec/public/property_spec.rb +10 -6
  28. data/spec/public/resource_spec.rb +9 -64
  29. data/spec/shared/{finder_shared_spec.rb → finder_shared.rb} +134 -128
  30. data/spec/shared/{flags_shared_spec.rb → flags_shared.rb} +0 -0
  31. data/spec/shared/{public_property_spec.rb → public_property.rb} +0 -0
  32. data/spec/shared/{resource_spec.rb → resource.rb} +46 -31
  33. data/spec/shared/{semipublic_property_spec.rb → semipublic_property.rb} +0 -0
  34. data/spec/spec_helper.rb +11 -5
  35. data/spec/support/logger.rb +38 -0
  36. data/spec/unit/dirty_minder_spec.rb +4 -2
  37. data/spec/unit/paranoid_boolean_spec.rb +3 -3
  38. data/spec/unit/paranoid_datetime_spec.rb +3 -3
  39. metadata +59 -30
  40. checksums.yaml +0 -7
@@ -628,7 +628,7 @@ shared_examples 'A public Resource' do
628
628
  describe 'on a resource that is changed outside another resource' do
629
629
  before do
630
630
  rescue_if @skip do
631
- @user.dup.update(:description => 'Changed')
631
+ @user.clone.update(:description => 'Changed')
632
632
  end
633
633
  end
634
634
 
@@ -825,33 +825,39 @@ shared_examples 'A public Resource' do
825
825
  end
826
826
 
827
827
  it 'should save resource' do
828
- pending_if !@user.respond_to?(:comments)
829
- expect(@return).to be(true)
828
+ skip_if !@user.respond_to?(:comments) do
829
+ expect(@return).to be(true)
830
+ end
830
831
  end
831
832
 
832
833
  it 'should save the first resource created through new' do
833
- pending_if !@user.respond_to?(:comments)
834
- expect(@first_comment.new?).to be(false)
834
+ skip_if !@user.respond_to?(:comments) do
835
+ expect(@first_comment.new?).to be(false)
836
+ end
835
837
  end
836
838
 
837
839
  it 'should save the correct foreign key for the first resource' do
838
- pending_if !@user.respond_to?(:comments)
839
- expect(@first_comment.user).to eql(@user)
840
+ skip_if !@user.respond_to?(:comments) do
841
+ expect(@first_comment.user).to eql(@user)
842
+ end
840
843
  end
841
844
 
842
845
  it 'should save the second resource created through the constructor' do
843
- skip "Changing a belongs_to parent should add the resource to the correct association"
844
- expect(@second_comment.new?).to be(false)
846
+ skip "Changing a belongs_to parent should add the resource to the correct association" do
847
+ expect(@second_comment.new?).to be(false)
848
+ end
845
849
  end
846
850
 
847
851
  it 'should save the correct foreign key for the second resource' do
848
- pending_if !@user.respond_to?(:comments)
849
- expect(@second_comment.user).to eql(@user)
852
+ skip_if !@user.respond_to?(:comments) do
853
+ expect(@second_comment.user).to eql(@user)
854
+ end
850
855
  end
851
856
 
852
857
  it 'should create 2 extra resources in persistent storage' do
853
- skip "Changing a belongs_to parent should add the resource to the correct association"
854
- expect(@user.comments.size).to eq(@initial_comments + 2)
858
+ skip "Changing a belongs_to parent should add the resource to the correct association" do
859
+ expect(@user.comments.size).to eq(@initial_comments + 2)
860
+ end
855
861
  end
856
862
  end
857
863
 
@@ -870,8 +876,9 @@ shared_examples 'A public Resource' do
870
876
  end
871
877
 
872
878
  it 'should return true' do
873
- pending_if !@user.respond_to?(:comments)
874
- expect(@return).to be(true)
879
+ skip_if !@user.respond_to?(:comments) do
880
+ expect(@return).to be(true)
881
+ end
875
882
  end
876
883
 
877
884
  it 'should not be dirty' do
@@ -879,13 +886,15 @@ shared_examples 'A public Resource' do
879
886
  end
880
887
 
881
888
  it 'should have saved the first child resource' do
882
- pending_if !@user.respond_to?(:comments)
883
- expect(@first_comment.model.get(*@first_comment.key).body).to eq('It still has rough edges')
889
+ skip_if !@user.respond_to?(:comments) do
890
+ expect(@first_comment.model.get(*@first_comment.key).body).to eq('It still has rough edges')
891
+ end
884
892
  end
885
893
 
886
894
  it 'should not have saved the second child resource' do
887
- pending_if !@user.respond_to?(:comments)
888
- expect(@second_comment.model.get(*@second_comment.key).body).to eq('is it really?')
895
+ skip_if !@user.respond_to?(:comments) do
896
+ expect(@second_comment.model.get(*@second_comment.key).body).to eq('is it really?')
897
+ end
889
898
  end
890
899
  end
891
900
 
@@ -896,8 +905,9 @@ shared_examples 'A public Resource' do
896
905
  end
897
906
 
898
907
  it 'should not raise an exception when saving the resource' do
899
- skip
900
- expect { expect(@first_comment.send(method)).to be(false) }.not_to raise_error
908
+ skip do
909
+ expect { expect(@first_comment.send(method)).to be(false) }.not_to raise_error
910
+ end
901
911
  end
902
912
  end
903
913
 
@@ -937,23 +947,27 @@ shared_examples 'A public Resource' do
937
947
  end
938
948
 
939
949
  it 'should not be dirty' do
940
- pending_if !@article.respond_to?(:paragraphs)
941
- expect(@article).not_to be_dirty
950
+ skip_if !@article.respond_to?(:paragraphs) do
951
+ expect(@article).not_to be_dirty
952
+ end
942
953
  end
943
954
 
944
955
  it 'should not be dirty' do
945
- pending_if !@article.respond_to?(:paragraphs)
946
- expect(@paragraph).not_to be_dirty
956
+ skip_if !@article.respond_to?(:paragraphs) do
957
+ expect(@paragraph).not_to be_dirty
958
+ end
947
959
  end
948
960
 
949
961
  it 'should set the related resource' do
950
- pending_if !@article.respond_to?(:paragraphs)
951
- expect(@paragraph.article).to eq(@article)
962
+ skip_if !@article.respond_to?(:paragraphs) do
963
+ expect(@paragraph.article).to eq(@article)
964
+ end
952
965
  end
953
966
 
954
967
  it 'should set the foreign key properly' do
955
- pending_if !@article.respond_to?(:paragraphs)
956
- expect(@paragraph.article_id).to eq(@article.id)
968
+ skip_if !@article.respond_to?(:paragraphs) do
969
+ expect(@paragraph.article_id).to eq(@article.id)
970
+ end
957
971
  end
958
972
  end
959
973
 
@@ -1211,8 +1225,9 @@ shared_examples 'A public Resource' do
1211
1225
  end
1212
1226
 
1213
1227
  it 'should not overwrite dirty key' do
1214
- skip
1215
- expect(@user.name).to eq('dkubb')
1228
+ skip do
1229
+ expect(@user.name).to eq('dkubb')
1230
+ end
1216
1231
  end
1217
1232
  end
1218
1233
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,10 @@
1
- require 'pry'
2
- require 'database_cleaner'
1
+ Bundler.require(:default, :test)
3
2
 
4
3
  ENV['ORM'] ||= 'active_record'
5
4
  require 'ardm/env'
6
5
 
6
+ Dir["#{Pathname(__FILE__).dirname.expand_path}/{shared,support}/*.rb"].each { |file| require file }
7
+
7
8
  Ardm.active_record do
8
9
  ActiveRecord::Base.configurations = { "ardm" => {
9
10
  "database" => "db/test.sqlite",
@@ -20,12 +21,17 @@ Ardm.active_record do
20
21
  end
21
22
 
22
23
  Ardm.data_mapper do
23
- raise "TODO: DataMapper setup."
24
+ Bundler.require(:datamapper)
25
+ DataMapper.setup(:default, "sqlite3://#{File.expand_path("../../db/test.sqlite", __FILE__)}")
26
+ DataMapper.auto_migrate!
24
27
  end
25
28
 
26
- Dir["#{Pathname(__FILE__).dirname.expand_path}/shared/*.rb"].each { |file| require file }
27
-
28
29
  RSpec.configure do |config|
30
+ config.treat_symbols_as_metadata_keys_with_true_values = true
31
+ if ENV["ORM"] == "active_record"
32
+ config.filter_run_excluding(:dm => true)
33
+ end
34
+
29
35
  config.before(:suite) do
30
36
  DatabaseCleaner.strategy = :transaction
31
37
  DatabaseCleaner.clean_with(:truncation)
@@ -0,0 +1,38 @@
1
+ if defined?(::DataMapper)
2
+ module DataMapper::LogListener
3
+ def log(message)
4
+ DataMapper.logger.info("#{message.query}")
5
+ super
6
+ rescue Exception => e
7
+ ::DataMapper.logger.error "[datamapper] #{e.class.name}: #{e.message}: #{message.inspect}}"
8
+ end
9
+ end
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:each) do
14
+ require 'logger'
15
+ logger = Logger.new(nil)
16
+
17
+ if Ardm.rails4?
18
+ require 'active_support/logger'
19
+ logger = if ENV["VERBOSE"]
20
+ ActiveSupport::Logger.new(STDOUT)
21
+ end
22
+ end
23
+
24
+ if defined?(::ActiveRecord::Base)
25
+ ::ActiveRecord::Base.logger = logger
26
+ elsif defined?(::DataMapper)
27
+ require 'active_support/inflector'
28
+ driver = DataObjects.const_get(ActiveSupport::Inflector.camelize('sqlite3'), false)
29
+
30
+ DataObjects::Connection.send(:include, DataMapper::LogListener)
31
+ # FIXME Setting DataMapper::Logger.new($stdout, :off) alone won't work because the #log
32
+ # method is currently only available in DO and needs an explicit DO Logger instantiated.
33
+ # We turn the logger :off because ActiveSupport::Notifications handles displaying log messages
34
+ driver.logger = DataObjects::Logger.new($stdout, :off)
35
+ ::DataMapper.logger = logger
36
+ end
37
+ end
38
+ end
@@ -31,8 +31,10 @@ describe Ardm::Property::DirtyMinder,'set!' do
31
31
  end
32
32
 
33
33
  shared_examples_for 'a hooked value' do
34
- it 'should extend value with hook', pending: true do
35
- expect(object.get!(resource)).to be_kind_of(Ardm::Property::DirtyMinder::Hooker)
34
+ it 'should extend value with hook' do
35
+ skip "FIXME: This probably should pass" do
36
+ expect(object.get!(resource)).to be_kind_of(Ardm::Property::DirtyMinder::Hooker)
37
+ end
36
38
  end
37
39
  end
38
40
 
@@ -7,7 +7,7 @@ module ::ParanoidBooleanBlog
7
7
  property :deleted, ParanoidBoolean
8
8
  timestamps :at
9
9
 
10
- before_destroy :before_destroy
10
+ before(:destroy, :before_destroy)
11
11
 
12
12
  def before_destroy; end
13
13
  end
@@ -50,7 +50,7 @@ describe Ardm::Property::ParanoidBoolean do
50
50
  @resource = @model.create
51
51
  end
52
52
 
53
- it { expect(!!subject).to be true }
53
+ it { expect(subject).to be_truthy }
54
54
 
55
55
  it 'should not delete the resource from the datastore' do
56
56
  expect(method(:subject)).not_to change { @model.with_deleted.size }.from(1)
@@ -94,7 +94,7 @@ describe Ardm::Property::ParanoidBoolean do
94
94
  @resource = @model.create
95
95
  end
96
96
 
97
- it { expect(!!subject).to be true }
97
+ it { expect(subject).to be_truthy }
98
98
 
99
99
  it 'should delete the resource from the datastore' do
100
100
  expect(method(:subject)).to change { @model.with_deleted.size }.from(1).to(0)
@@ -8,7 +8,7 @@ module ::ParanoidDateTimeBlog
8
8
  property :deleted_at, ParanoidDateTime
9
9
  timestamps :at
10
10
 
11
- before_destroy :before_destroy
11
+ before(:destroy, :before_destroy)
12
12
 
13
13
  def before_destroy; end
14
14
  end
@@ -56,7 +56,7 @@ describe Ardm::Property::ParanoidDateTime do
56
56
  @resource = @model.create
57
57
  end
58
58
 
59
- it { expect(!!subject).to be true }
59
+ it { expect(subject).to be_truthy }
60
60
 
61
61
  it 'should not delete the resource from the datastore' do
62
62
  expect(method(:subject)).not_to change { @model.with_deleted.size }.from(1)
@@ -100,7 +100,7 @@ describe Ardm::Property::ParanoidDateTime do
100
100
  @resource = @model.create
101
101
  end
102
102
 
103
- it { expect(!!subject).to be true }
103
+ it { expect(subject).to be_truthy }
104
104
 
105
105
  it 'should delete the resource from the datastore' do
106
106
  expect(method(:subject)).to change { @model.with_deleted.size }.from(1).to(0)
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ardm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Martin Emde
@@ -14,127 +15,151 @@ dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activesupport
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
- - - ">="
20
+ - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: '3.2'
23
+ - - <
24
+ - !ruby/object:Gem::Version
25
+ version: '4.1'
21
26
  type: :runtime
22
27
  prerelease: false
23
28
  version_requirements: !ruby/object:Gem::Requirement
29
+ none: false
24
30
  requirements:
25
- - - ">="
31
+ - - ! '>='
26
32
  - !ruby/object:Gem::Version
27
33
  version: '3.2'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '4.1'
28
37
  - !ruby/object:Gem::Dependency
29
38
  name: bcrypt-ruby
30
39
  requirement: !ruby/object:Gem::Requirement
40
+ none: false
31
41
  requirements:
32
- - - "~>"
42
+ - - ~>
33
43
  - !ruby/object:Gem::Version
34
44
  version: 3.0.0
35
45
  type: :runtime
36
46
  prerelease: false
37
47
  version_requirements: !ruby/object:Gem::Requirement
48
+ none: false
38
49
  requirements:
39
- - - "~>"
50
+ - - ~>
40
51
  - !ruby/object:Gem::Version
41
52
  version: 3.0.0
42
53
  - !ruby/object:Gem::Dependency
43
54
  name: fastercsv
44
55
  requirement: !ruby/object:Gem::Requirement
56
+ none: false
45
57
  requirements:
46
- - - "~>"
58
+ - - ~>
47
59
  - !ruby/object:Gem::Version
48
60
  version: 1.5.4
49
61
  type: :runtime
50
62
  prerelease: false
51
63
  version_requirements: !ruby/object:Gem::Requirement
64
+ none: false
52
65
  requirements:
53
- - - "~>"
66
+ - - ~>
54
67
  - !ruby/object:Gem::Version
55
68
  version: 1.5.4
56
69
  - !ruby/object:Gem::Dependency
57
70
  name: multi_json
58
71
  requirement: !ruby/object:Gem::Requirement
72
+ none: false
59
73
  requirements:
60
- - - ">"
74
+ - - ! '>'
61
75
  - !ruby/object:Gem::Version
62
76
  version: 1.3.2
63
77
  type: :runtime
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
80
+ none: false
66
81
  requirements:
67
- - - ">"
82
+ - - ! '>'
68
83
  - !ruby/object:Gem::Version
69
84
  version: 1.3.2
70
85
  - !ruby/object:Gem::Dependency
71
86
  name: stringex
72
87
  requirement: !ruby/object:Gem::Requirement
88
+ none: false
73
89
  requirements:
74
- - - "~>"
90
+ - - ~>
75
91
  - !ruby/object:Gem::Version
76
92
  version: 1.3.3
77
93
  type: :runtime
78
94
  prerelease: false
79
95
  version_requirements: !ruby/object:Gem::Requirement
96
+ none: false
80
97
  requirements:
81
- - - "~>"
98
+ - - ~>
82
99
  - !ruby/object:Gem::Version
83
100
  version: 1.3.3
84
101
  - !ruby/object:Gem::Dependency
85
102
  name: uuidtools
86
103
  requirement: !ruby/object:Gem::Requirement
104
+ none: false
87
105
  requirements:
88
- - - "~>"
106
+ - - ~>
89
107
  - !ruby/object:Gem::Version
90
108
  version: 2.1.2
91
109
  type: :runtime
92
110
  prerelease: false
93
111
  version_requirements: !ruby/object:Gem::Requirement
112
+ none: false
94
113
  requirements:
95
- - - "~>"
114
+ - - ~>
96
115
  - !ruby/object:Gem::Version
97
116
  version: 2.1.2
98
117
  - !ruby/object:Gem::Dependency
99
118
  name: coercible
100
119
  requirement: !ruby/object:Gem::Requirement
120
+ none: false
101
121
  requirements:
102
- - - ">="
122
+ - - ! '>='
103
123
  - !ruby/object:Gem::Version
104
124
  version: '0'
105
125
  type: :runtime
106
126
  prerelease: false
107
127
  version_requirements: !ruby/object:Gem::Requirement
128
+ none: false
108
129
  requirements:
109
- - - ">="
130
+ - - ! '>='
110
131
  - !ruby/object:Gem::Version
111
132
  version: '0'
112
133
  - !ruby/object:Gem::Dependency
113
134
  name: rake
114
135
  requirement: !ruby/object:Gem::Requirement
136
+ none: false
115
137
  requirements:
116
- - - "~>"
138
+ - - ~>
117
139
  - !ruby/object:Gem::Version
118
140
  version: 0.9.2
119
141
  type: :development
120
142
  prerelease: false
121
143
  version_requirements: !ruby/object:Gem::Requirement
144
+ none: false
122
145
  requirements:
123
- - - "~>"
146
+ - - ~>
124
147
  - !ruby/object:Gem::Version
125
148
  version: 0.9.2
126
149
  - !ruby/object:Gem::Dependency
127
150
  name: rspec
128
151
  requirement: !ruby/object:Gem::Requirement
152
+ none: false
129
153
  requirements:
130
- - - "~>"
154
+ - - ~>
131
155
  - !ruby/object:Gem::Version
132
156
  version: '2.0'
133
157
  type: :development
134
158
  prerelease: false
135
159
  version_requirements: !ruby/object:Gem::Requirement
160
+ none: false
136
161
  requirements:
137
- - - "~>"
162
+ - - ~>
138
163
  - !ruby/object:Gem::Version
139
164
  version: '2.0'
140
165
  description: ActiveRecord plugin to provide a smooth migration from DataMapper to
@@ -147,7 +172,8 @@ extra_rdoc_files:
147
172
  - LICENSE
148
173
  - README.md
149
174
  files:
150
- - ".gitignore"
175
+ - .gitignore
176
+ - .ruby-version
151
177
  - Gemfile
152
178
  - LICENSE
153
179
  - README.md
@@ -255,6 +281,7 @@ files:
255
281
  - spec/fixtures/invention.rb
256
282
  - spec/fixtures/network_node.rb
257
283
  - spec/fixtures/person.rb
284
+ - spec/fixtures/resource_blog.rb
258
285
  - spec/fixtures/software_package.rb
259
286
  - spec/fixtures/ticket.rb
260
287
  - spec/fixtures/tshirt.rb
@@ -306,14 +333,15 @@ files:
306
333
  - spec/semipublic/property/text_spec.rb
307
334
  - spec/semipublic/property/time_spec.rb
308
335
  - spec/semipublic/property_spec.rb
309
- - spec/shared/finder_shared_spec.rb
310
- - spec/shared/flags_shared_spec.rb
336
+ - spec/shared/finder_shared.rb
337
+ - spec/shared/flags_shared.rb
311
338
  - spec/shared/identity_function_group.rb
312
- - spec/shared/public_property_spec.rb
313
- - spec/shared/resource_spec.rb
314
- - spec/shared/semipublic_property_spec.rb
339
+ - spec/shared/public_property.rb
340
+ - spec/shared/resource.rb
341
+ - spec/shared/semipublic_property.rb
315
342
  - spec/spec.opts
316
343
  - spec/spec_helper.rb
344
+ - spec/support/logger.rb
317
345
  - spec/unit/bcrypt_hash_spec.rb
318
346
  - spec/unit/csv_spec.rb
319
347
  - spec/unit/dirty_minder_spec.rb
@@ -334,25 +362,26 @@ files:
334
362
  homepage: http://github.com/engineyard/ardm
335
363
  licenses:
336
364
  - MIT
337
- metadata: {}
338
365
  post_install_message:
339
366
  rdoc_options: []
340
367
  require_paths:
341
368
  - lib
342
369
  required_ruby_version: !ruby/object:Gem::Requirement
370
+ none: false
343
371
  requirements:
344
- - - ">="
372
+ - - ! '>='
345
373
  - !ruby/object:Gem::Version
346
374
  version: '0'
347
375
  required_rubygems_version: !ruby/object:Gem::Requirement
376
+ none: false
348
377
  requirements:
349
- - - ">="
378
+ - - ! '>='
350
379
  - !ruby/object:Gem::Version
351
380
  version: '0'
352
381
  requirements: []
353
382
  rubyforge_project:
354
- rubygems_version: 2.2.2
383
+ rubygems_version: 1.8.23.2
355
384
  signing_key:
356
- specification_version: 4
385
+ specification_version: 3
357
386
  summary: ActiveRecord plugin to provide a smooth migration from DataMapper to ActiveRecord
358
387
  test_files: []