praxis 2.0.pre.2 → 2.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,10 +23,21 @@ Dir["#{File.dirname(__FILE__)}/../lib/praxis/plugins/*.rb"].each do |file|
23
23
  require file
24
24
  end
25
25
 
26
+
26
27
  Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
27
28
  require file
28
29
  end
29
30
 
31
+ def suppress_output
32
+ original_stdout, original_stderr = $stdout.clone, $stderr.clone
33
+ $stderr.reopen File.new('/dev/null', 'w')
34
+ $stdout.reopen File.new('/dev/null', 'w')
35
+ yield
36
+ ensure
37
+ $stdout.reopen original_stdout
38
+ $stderr.reopen original_stderr
39
+ end
40
+
30
41
  RSpec.configure do |config|
31
42
  config.include Rack::Test::Methods
32
43
 
@@ -0,0 +1,39 @@
1
+ # Copied verbatim from: https://github.com/amogil/rspec-deep-ignore-order-matcher
2
+
3
+ RSpec::Matchers.define :be_deep_equal do |expected|
4
+ match { |actual| match? actual, expected }
5
+
6
+ failure_message do |actual|
7
+ "expected that #{actual} would be deep equal with #{expected}"
8
+ end
9
+
10
+ failure_message_when_negated do |actual|
11
+ "expected that #{actual} would not be deep equal with #{expected}"
12
+ end
13
+
14
+ description do
15
+ "be deep equal with #{expected}"
16
+ end
17
+
18
+ def match?(actual, expected)
19
+ return arrays_match?(actual, expected) if expected.is_a?(Array) && actual.is_a?(Array)
20
+ return hashes_match?(actual, expected) if expected.is_a?(Hash) && actual.is_a?(Hash)
21
+ expected == actual
22
+ end
23
+
24
+ def arrays_match?(actual, expected)
25
+ exp = expected.clone
26
+ actual.each do |a|
27
+ index = exp.find_index { |e| match? a, e }
28
+ return false if index.nil?
29
+ exp.delete_at(index)
30
+ end
31
+ exp.empty?
32
+ end
33
+
34
+ def hashes_match?(actual, expected)
35
+ return false unless actual.keys.sort == expected.keys.sort
36
+ actual.each { |key, value| return false unless match? value, expected[key] }
37
+ true
38
+ end
39
+ end
@@ -8,12 +8,16 @@ class SimpleModel < OpenStruct
8
8
  parent: {
9
9
  model: ParentModel,
10
10
  primary_key: :id,
11
- type: :many_to_one
11
+ type: :many_to_one,
12
+ local_key_columns: [:parent_id],
13
+ remote_key_columns: [:id]
12
14
  },
13
15
  other_model: {
14
16
  model: OtherModel,
15
17
  primary_key: :id,
16
- type: :many_to_one
18
+ type: :many_to_one,
19
+ local_key_columns: [:other_model_id],
20
+ remote_key_columns: [:id]
17
21
  }
18
22
  }
19
23
  end
@@ -23,14 +27,20 @@ class OtherModel < OpenStruct
23
27
  include Praxis::Mapper::ActiveModelCompat
24
28
  def self._praxis_associations
25
29
  {
26
- }
27
- end
28
- end
29
-
30
- class PersonModel < OpenStruct
31
- include Praxis::Mapper::ActiveModelCompat
32
- def self._praxis_associations
33
- {
30
+ parent: {
31
+ model: ParentModel,
32
+ primary_key: :id,
33
+ type: :many_to_one,
34
+ local_key_columns: [:parent_id],
35
+ remote_key_columns: [:id]
36
+ },
37
+ simple_models: {
38
+ model: SimpleModel,
39
+ primary_key: :id,
40
+ type: :many_to_many,
41
+ local_key_columns: [:id],
42
+ remote_key_columns: [:id] # The through table is in the middle where the FKs are...
43
+ }
34
44
  }
35
45
  end
36
46
  end
@@ -39,6 +49,13 @@ class ParentModel < OpenStruct
39
49
  include Praxis::Mapper::ActiveModelCompat
40
50
  def self._praxis_associations
41
51
  {
52
+ simple_children: {
53
+ model: SimpleModel,
54
+ primary_key: :id,
55
+ type: :one_to_many,
56
+ local_key_columns: [:id],
57
+ remote_key_columns: [:parent_id]
58
+ }
42
59
  }
43
60
  end
44
61
  end
@@ -50,7 +67,9 @@ class YamlArrayModel < OpenStruct
50
67
  parents: {
51
68
  model: ParentModel,
52
69
  primary_key: :id,
53
- type: :one_to_many
70
+ type: :one_to_many,
71
+ local_key_columns: [:id],
72
+ remote_key_columns: [:parent_id]
54
73
  }
55
74
  }
56
75
  end
@@ -66,12 +85,10 @@ class BaseResource < Praxis::Mapper::Resource
66
85
  property :href, dependencies: [:id]
67
86
  end
68
87
 
69
- # class CompositeIdResource < BaseResource
70
- # model CompositeIdModel
71
- # end
72
-
73
88
  class OtherResource < BaseResource
74
89
  model OtherModel
90
+
91
+ property :display_name, dependencies: [:name]
75
92
  end
76
93
 
77
94
  class ParentResource < BaseResource
@@ -87,45 +104,21 @@ class SimpleResource < BaseResource
87
104
  self.other_model
88
105
  end
89
106
 
107
+ property :aliased_method, dependencies: [:column1, :other_model]
90
108
  property :other_resource, dependencies: [:other_model]
91
109
 
110
+ property :parent, dependencies: [:parent, :added_column]
111
+
92
112
  property :name, dependencies: [:simple_name]
93
- end
113
+ property :direct_other_name, dependencies: [ 'other_model.name' ]
114
+ property :aliased_other_name, dependencies: [ 'other_model.display_name' ]
94
115
 
95
- # class SimplerResource < BaseResource
96
- # model SimplerModel
97
- # end
116
+ property :everything, dependencies: [:*]
117
+ property :everything_from_parent, dependencies: ['parent.*']
118
+ property :circular_dep, dependencies: [ :circular_dep, :column1 ]
119
+ property :no_deps, dependencies: []
120
+ end
98
121
 
99
122
  class YamlArrayResource < BaseResource
100
123
  model YamlArrayModel
101
124
  end
102
-
103
- class PersonResource < BaseResource
104
- model PersonModel
105
-
106
- def href
107
- "/people/#{self.id}"
108
- end
109
-
110
- end
111
-
112
- # class AddressResource < BaseResource
113
- # model AddressModel
114
-
115
-
116
- # def href
117
- # "/addresses/#{self.id}"
118
- # end
119
- # property :href, dependencies: [:id]
120
-
121
- # def owner_name
122
- # self.owner.name
123
- # end
124
- # property :owner_name, dependencies: ['owner.name']
125
-
126
- # def resident_count
127
- # self.residents.size
128
- # end
129
- # property :resident_count, dependencies: [:residents]
130
-
131
- # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.pre.2
4
+ version: 2.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-01 00:00:00.000000000 Z
12
+ date: 2020-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -381,6 +381,34 @@ dependencies:
381
381
  - - ">="
382
382
  - !ruby/object:Gem::Version
383
383
  version: '0'
384
+ - !ruby/object:Gem::Dependency
385
+ name: sequel
386
+ requirement: !ruby/object:Gem::Requirement
387
+ requirements:
388
+ - - "~>"
389
+ - !ruby/object:Gem::Version
390
+ version: '5'
391
+ type: :development
392
+ prerelease: false
393
+ version_requirements: !ruby/object:Gem::Requirement
394
+ requirements:
395
+ - - "~>"
396
+ - !ruby/object:Gem::Version
397
+ version: '5'
398
+ - !ruby/object:Gem::Dependency
399
+ name: activerecord
400
+ requirement: !ruby/object:Gem::Requirement
401
+ requirements:
402
+ - - ">"
403
+ - !ruby/object:Gem::Version
404
+ version: '4'
405
+ type: :development
406
+ prerelease: false
407
+ version_requirements: !ruby/object:Gem::Requirement
408
+ requirements:
409
+ - - ">"
410
+ - !ruby/object:Gem::Version
411
+ version: '4'
384
412
  description:
385
413
  email:
386
414
  - blanquer@gmail.com
@@ -610,7 +638,11 @@ files:
610
638
  - spec/praxis/controller_spec.rb
611
639
  - spec/praxis/dispatcher_spec.rb
612
640
  - spec/praxis/extensions/field_expansion_spec.rb
641
+ - spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb
613
642
  - spec/praxis/extensions/field_selection/field_selector_spec.rb
643
+ - spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb
644
+ - spec/praxis/extensions/field_selection/support/spec_resources_active_model.rb
645
+ - spec/praxis/extensions/field_selection/support/spec_resources_sequel.rb
614
646
  - spec/praxis/extensions/rendering_spec.rb
615
647
  - spec/praxis/file_group_spec.rb
616
648
  - spec/praxis/handlers/json_spec.rb
@@ -648,7 +680,6 @@ files:
648
680
  - spec/spec_app/app/controllers/base_class.rb
649
681
  - spec/spec_app/app/controllers/instances.rb
650
682
  - spec/spec_app/app/controllers/volumes.rb
651
- - spec/spec_app/app/models/person.rb
652
683
  - spec/spec_app/app/responses/bulk_response.rb
653
684
  - spec/spec_app/app/responses/multipart.rb
654
685
  - spec/spec_app/app/responses/other_response.rb
@@ -670,6 +701,7 @@ files:
670
701
  - spec/spec_app/design/resources/volume_snapshots.rb
671
702
  - spec/spec_app/design/resources/volumes.rb
672
703
  - spec/spec_helper.rb
704
+ - spec/support/be_deep_equal_matcher.rb
673
705
  - spec/support/spec_authorization_plugin.rb
674
706
  - spec/support/spec_complex_authentication_plugin.rb
675
707
  - spec/support/spec_media_types.rb
@@ -723,7 +755,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
723
755
  - !ruby/object:Gem::Version
724
756
  version: 1.3.1
725
757
  requirements: []
726
- rubygems_version: 3.0.3
758
+ rubyforge_project:
759
+ rubygems_version: 2.6.14
727
760
  signing_key:
728
761
  specification_version: 4
729
762
  summary: Building APIs the way you want it.
@@ -1,3 +0,0 @@
1
- # class PersonModel #< Praxis::Mapper::Model
2
- # # table_name 'people'
3
- # end