terrain 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/terrain/resource.rb +9 -5
- data/spec/support/blank_policy.rb +7 -0
- data/spec/terrain/resource_spec.rb +12 -0
- data/terrain.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1a10bf232abf55b96aaf0f5809519e15e02fc8
|
4
|
+
data.tar.gz: eb8f11a4cb927851d7d306d45fb9560038d71f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 462efae4c908fb0eabdae60d9d0d22e492ea0c6778390a06e5a0fb30cab618a18ab24b9ee3e381d5d2ccede8937419774cfc11b04f9d41fe09c4c1a20c11ca13
|
7
|
+
data.tar.gz: 9d48ba7b2c0f69b6db24ffca860074118f5f136218c2683ecf09e7248e8601e1329466c02931aa1e8d9dd261a5e23e00ae19d66b6dfe29ddb630a42e2a1da2c1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Terrain
|
2
2
|
|
3
|
-
[](https://travis-ci.org/scttnlsn/terrain)
|
4
4
|
|
5
5
|
Opinionated toolkit for building CRUD APIs with Rails
|
6
6
|
|
data/lib/terrain/resource.rb
CHANGED
@@ -89,11 +89,13 @@ module Terrain
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
def pundit_policy?(object)
|
93
|
+
finder = Pundit::PolicyFinder.new(object)
|
94
|
+
finder.policy.present?
|
95
|
+
end
|
96
|
+
|
92
97
|
def authorize_record(record)
|
93
|
-
|
94
|
-
if finder.policy
|
95
|
-
authorize(record)
|
96
|
-
end
|
98
|
+
authorize(record) if pundit_policy?(record)
|
97
99
|
end
|
98
100
|
|
99
101
|
def order(scope)
|
@@ -116,7 +118,9 @@ module Terrain
|
|
116
118
|
end
|
117
119
|
|
118
120
|
def resource_scope
|
119
|
-
preloaded_resource.all
|
121
|
+
scope = preloaded_resource.all
|
122
|
+
scope = policy_scope(scope) if pundit_policy?(scope)
|
123
|
+
scope
|
120
124
|
end
|
121
125
|
|
122
126
|
def load_record
|
@@ -72,6 +72,18 @@ describe 'Terrain::Resource', type: :controller do
|
|
72
72
|
expect(response.body).to eq serialize(Example.order('foo desc', 'bar asc')).to_json
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
context 'with restricted policy' do
|
77
|
+
before do
|
78
|
+
allow(Example).to receive(:policy_class) { BlankPolicy }
|
79
|
+
allow_any_instance_of(BlankPolicy::Scope).to receive(:resolve) { Example.where('1 = 0') }
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns policy scoped results' do
|
83
|
+
get :index
|
84
|
+
expect(response.body).to eq serialize([]).to_json
|
85
|
+
end
|
86
|
+
end
|
75
87
|
end
|
76
88
|
|
77
89
|
context 'paged' do
|
data/terrain.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terrain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/terrain/page.rb
|
71
71
|
- lib/terrain/resource.rb
|
72
72
|
- spec/spec_helper.rb
|
73
|
+
- spec/support/blank_policy.rb
|
73
74
|
- spec/support/example.rb
|
74
75
|
- spec/support/example_factory.rb
|
75
76
|
- spec/support/example_serializer.rb
|
@@ -100,12 +101,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
103
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.5.1
|
104
105
|
signing_key:
|
105
106
|
specification_version: 4
|
106
107
|
summary: Terrain
|
107
108
|
test_files:
|
108
109
|
- spec/spec_helper.rb
|
110
|
+
- spec/support/blank_policy.rb
|
109
111
|
- spec/support/example.rb
|
110
112
|
- spec/support/example_factory.rb
|
111
113
|
- spec/support/example_serializer.rb
|