active_model_serializers_cancancan 0.1.0 → 0.1.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c73184a79fdd879b8191cb33131026be82a74a4
|
4
|
+
data.tar.gz: a3b5dcad57c29c664b7af657e8713530594318ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6abdaa71b6e3ed251c6e31caa8376b66e33f69af1d79662d756d8c55199957fda5ebe1d2833cf291a3da1067d4aea02addafd59aa1c3015690231cda1a1e4e5
|
7
|
+
data.tar.gz: 8ba3ced18b6092081ce2efdaa1d7b7f0e4e28d3586f80fd264890728bdd9c64619e64ada9c88d882861958828f6cfd24381b9f9cc122259f74c084895e72d682
|
@@ -113,4 +113,42 @@ describe ActiveModel::Serializer::Associations do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
context 'when serializing has_many current_user should be available' do
|
117
|
+
before do
|
118
|
+
Object.send(:remove_const, :CategorySerializer) if defined?(CategorySerializer)
|
119
|
+
Object.send(:remove_const, :ProjectSerializer) if defined?(ProjectSerializer)
|
120
|
+
Object.send(:remove_const, :Ability) if defined?(Ability)
|
121
|
+
|
122
|
+
CategorySerializer = Class.new(ActiveModel::Serializer) do
|
123
|
+
attributes :id
|
124
|
+
has_many :projects
|
125
|
+
has_one :project
|
126
|
+
end
|
127
|
+
|
128
|
+
ProjectSerializer = Class.new(ActiveModel::Serializer) do
|
129
|
+
attributes :id
|
130
|
+
def id
|
131
|
+
if current_user.nil?
|
132
|
+
nil
|
133
|
+
else
|
134
|
+
current_user.id
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
Ability = Class.new do
|
140
|
+
include CanCan::Ability
|
141
|
+
def initialize(user)
|
142
|
+
can :read, :category
|
143
|
+
can :read, :project
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should serialize authorized has_one records' do
|
150
|
+
expect(CategorySerializer.new(category, scope: User.find(2)).serializable_hash[:project]).to_not be_nil
|
151
|
+
expect(CategorySerializer.new(category, scope: User.find(2)).serializable_hash[:project][:id]).to eq 2
|
152
|
+
end
|
153
|
+
end
|
116
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers_cancancan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTv
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_model_serializers
|