brainstem 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDQ4OWNhYzY3M2FjZDI3NTAwMGY3MjhmNTc4NTFmZTY5NmU0MDc4YQ==
5
- data.tar.gz: !binary |-
6
- MjNhMGMzZjdlYTE0MzZkZjJmNzNhN2VkZDUwYzJmOWMyMGI4ZDRkZQ==
2
+ SHA1:
3
+ metadata.gz: 7c38b868345e5b3aaadc1c2746e6963d1daf1f1f
4
+ data.tar.gz: cccbd5c71854048fb2331fc909e2a7a98c0345ed
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZmI4MDIwN2JjODg0YWMxYzFjODBjYWY4ZDdmMDgzNzM4YWFjNGQyY2Q4NTg4
10
- ZGI2NDljNzdkNjBkYzNmNjkzZWUyNjIzZjBiNjc4OWUxMGUzZDFhYjY3Yzhj
11
- MzM2YTA5ZmY1OTM1MmU0MGU5NDM0ZTk4OGU1NDdhY2RlZTE4Mjg=
12
- data.tar.gz: !binary |-
13
- OWExMGE5Nzk5ODk2NzBjMjJhNzhjZWM4NTRiNjE4MWY5NDk0MDExNTNiZTk4
14
- ZmYzNzkwNzE0Mzc1MTIzYmQ1Y2ZhYjYzOTU1MGQ0MjI3N2YwMTNjODFlNGFm
15
- OTI5NDkwMjQzNDQwNDI1N2JiMWFjNGFmZjMxZGI3YjAzMGVlZGU=
6
+ metadata.gz: fec3d2771167970f5198ece98f6febc2d903599167ea2b15ac2d60558e50e8c8ef9cc650e1129cfb29c333dd8d080fcf8705615fb7b445c25ec7a49be9b8e826
7
+ data.tar.gz: 06a68af6770a08acf1c6ca3379eb5ee2b050b14acc80982af2afb2be8b65e60cc5f257f0de2cd8825741fa040c74c0121f397c9f400cff91b639d649adcc1028
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brainstem (0.2.5)
4
+ brainstem (0.2.6)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -251,8 +251,8 @@ module Brainstem
251
251
  return scope unless searching? options
252
252
 
253
253
  search_options = HashWithIndifferentAccess.new(
254
- :include => includes,
255
- :order => { :sort_order => sort_name, :direction => direction },
254
+ :include => includes,
255
+ :order => { :sort_order => sort_name, :direction => direction },
256
256
  )
257
257
 
258
258
  if options[:params][:limit].present? && options[:params][:offset].present?
@@ -297,11 +297,11 @@ module Brainstem
297
297
 
298
298
  case order
299
299
  when Proc
300
- order.call(scope, direction == "desc" ? "desc" : "asc")
300
+ order.call(scope, direction)
301
301
  when nil
302
302
  scope
303
303
  else
304
- scope.order(order.to_s + " " + (direction == "desc" ? "desc" : "asc"))
304
+ scope.order(order.to_s + " " + direction)
305
305
  end
306
306
  end
307
307
 
@@ -322,7 +322,7 @@ module Brainstem
322
322
  direction = default_direction
323
323
  end
324
324
 
325
- [sort_name, direction]
325
+ [sort_name, direction == 'desc' ? 'desc' : 'asc']
326
326
  end
327
327
 
328
328
  def perform_preloading(records, includes_hash)
@@ -1,3 +1,3 @@
1
1
  module Brainstem
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
Binary file
@@ -487,6 +487,7 @@ describe Brainstem::PresenterCollection do
487
487
  describe "search" do
488
488
  context "with search method defined" do
489
489
  before do
490
+ WorkspacePresenter.sort_order(:description, "workspaces.description")
490
491
  WorkspacePresenter.search do |string|
491
492
  [[5, 3], 2]
492
493
  end
@@ -541,14 +542,14 @@ describe Brainstem::PresenterCollection do
541
542
  expect(string).to eq("blah")
542
543
  expect(options[:include]).to eq(["tasks", "lead_user"])
543
544
  expect(options[:owned_by]).to eq(false)
544
- expect(options[:order][:sort_order]).to eq("updated_at")
545
+ expect(options[:order][:sort_order]).to eq("description")
545
546
  expect(options[:order][:direction]).to eq("desc")
546
547
  expect(options[:page]).to eq(2)
547
548
  expect(options[:per_page]).to eq(5)
548
549
  [[1], 1] # returned ids, count - not testing this in this set of specs
549
550
  end
550
551
 
551
- @presenter_collection.presenting("workspaces", :params => { :search => "blah", :include => "tasks,lead_user", :owned_by => "false", :order => "updated_at:desc", :page => 2, :per_page => 5 }) { Workspace.order("id asc") }
552
+ @presenter_collection.presenting("workspaces", :params => { :search => "blah", :include => "tasks,lead_user", :owned_by => "false", :order => "description:desc", :page => 2, :per_page => 5 }) { Workspace.order("id asc") }
552
553
  end
553
554
 
554
555
  describe "includes" do
@@ -614,6 +615,16 @@ describe Brainstem::PresenterCollection do
614
615
 
615
616
  @presenter_collection.presenting("workspaces", :params => { :search => "blah", :order => "created_at:asc"}) { Workspace.order("id asc") }
616
617
  end
618
+
619
+ it "sanitizes sort orders" do
620
+ WorkspacePresenter.search do |string, options|
621
+ expect(options[:order][:sort_order]).to eq("description")
622
+ expect(options[:order][:direction]).to eq("asc")
623
+ [[1], 1]
624
+ end
625
+
626
+ @presenter_collection.presenting("workspaces", :params => { :search => "blah", :order => "description:owned"}) { Workspace.order("id asc") }
627
+ end
617
628
  end
618
629
 
619
630
  describe "pagination" do
@@ -738,15 +749,38 @@ describe Brainstem::PresenterCollection do
738
749
  end
739
750
 
740
751
  it "cleans the params" do
741
- WorkspacePresenter.sort_order(:description, "workspaces.description")
752
+ last_direction = nil
753
+ WorkspacePresenter.sort_order(:description, "workspaces.description") do |scope, direction|
754
+ last_direction = direction
755
+ scope
756
+ end
757
+ WorkspacePresenter.sort_order(:title, "workspaces.title")
742
758
  WorkspacePresenter.default_sort_order("description:desc")
743
759
 
744
- result = @presenter_collection.presenting("workspaces", :params => { :order => "updated_at:drop table" }) { Workspace.where("id is not null") }
760
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "description:drop table" }) { Workspace.where("id is not null") }
761
+ expect(last_direction).to eq('asc')
745
762
  expect(result.keys).to match_array([:count, :workspaces, :results])
746
763
 
764
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "description:;;hacker;;" }) { Workspace.where("id is not null") }
765
+ expect(last_direction).to eq('asc')
766
+
767
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "description:desc" }) { Workspace.where("id is not null") }
768
+ expect(last_direction).to eq('desc')
769
+
770
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "description:asc" }) { Workspace.where("id is not null") }
771
+ expect(last_direction).to eq('asc')
772
+
747
773
  result = @presenter_collection.presenting("workspaces", :params => { :order => "drop table:desc" }) { Workspace.where("id is not null") }
748
- expect(result.keys).to match_array([:count, :workspaces, :results])
749
- expect(result[:results].map {|i| result[:workspaces][i[:id]][:description] }).to eq(%w(c b a 3 2 1))
774
+ expect(last_direction).to eq('desc')
775
+
776
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "title:desc" }) { Workspace.where("id is not null") }
777
+ expect(result[:results].map {|i| result[:workspaces][i[:id]][:title] }).to eq(["jane workspace 2", "jane workspace 1", "bob workspace 4", "bob workspace 3", "bob workspace 2", "bob workspace 1"])
778
+
779
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "title:hacker" }) { Workspace.where("id is not null") }
780
+ expect(result[:results].map {|i| result[:workspaces][i[:id]][:title] }).to eq(["bob workspace 1", "bob workspace 2", "bob workspace 3", "bob workspace 4", "jane workspace 1", "jane workspace 2"])
781
+
782
+ result = @presenter_collection.presenting("workspaces", :params => { :order => "title:;;;drop table;;" }) { Workspace.where("id is not null") }
783
+ expect(result[:results].map {|i| result[:workspaces][i[:id]][:title] }).to eq(["bob workspace 1", "bob workspace 2", "bob workspace 3", "bob workspace 4", "jane workspace 1", "jane workspace 2"])
750
784
  end
751
785
 
752
786
  it "can take a proc" do
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainstem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mavenlink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2015-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Brainstem allows you to create rich API presenters that know how to filter,
@@ -134,6 +134,7 @@ files:
134
134
  - lib/brainstem/test_helpers.rb
135
135
  - lib/brainstem/time_classes.rb
136
136
  - lib/brainstem/version.rb
137
+ - pkg/brainstem-0.2.5.gem
137
138
  - spec/brainstem/controller_methods_spec.rb
138
139
  - spec/brainstem/presenter_collection_spec.rb
139
140
  - spec/brainstem/presenter_spec.rb
@@ -152,17 +153,17 @@ require_paths:
152
153
  - lib
153
154
  required_ruby_version: !ruby/object:Gem::Requirement
154
155
  requirements:
155
- - - ! '>='
156
+ - - ">="
156
157
  - !ruby/object:Gem::Version
157
158
  version: '0'
158
159
  required_rubygems_version: !ruby/object:Gem::Requirement
159
160
  requirements:
160
- - - ! '>='
161
+ - - ">="
161
162
  - !ruby/object:Gem::Version
162
163
  version: '0'
163
164
  requirements: []
164
165
  rubyforge_project:
165
- rubygems_version: 2.2.2
166
+ rubygems_version: 2.4.3
166
167
  signing_key:
167
168
  specification_version: 4
168
169
  summary: ActiveRecord presenters with a rich request API