ramen-rails 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2fd11f0f2fdbc4b14251faddb4ec35e2f89902e
4
- data.tar.gz: 6f6110a19e75baa8d0fb3143975bc253a9744bde
3
+ metadata.gz: a4bdf745220103d28895c16d259b69f1e390fd44
4
+ data.tar.gz: 4e9e118f904506cd55e13dfedb109ed4a313dd5f
5
5
  SHA512:
6
- metadata.gz: a3b9575bbbf23fa8b13f90b1624c9b342e0c194f5b5d1486f90bed683935fddf3732f51824906047ff558dd76bfa9aa1733cbfff7ca23b0db38bc5f38f824cef
7
- data.tar.gz: f6f8dba80bfa1cd796b55e871e55b9a35f37d67ca8d7985fa648de5515ba937bdb183fcaefe08055c221217320b89398e265ba3f236777cb03bf0fd7e3c5e7cf
6
+ metadata.gz: ae8cffe0b2ba0ee8b09d92c6aefb7c72c11dc2cd5799743a2a2d45de836256caab170ac8522c380c3a8161b5d044588da90c782d0649de7bf57c6a9b5b3e81e1
7
+ data.tar.gz: 7b1593f7be00a1e2ce9a6c33440557ab92c37cc0663b8a160c8c7b87e593a6bcd08407884738e22f1f71f83ef54d397f9eb5c8313108e274ba3c30ff893ae815
data/CHANGELOG CHANGED
@@ -13,3 +13,6 @@ Version 0.4.0
13
13
  Add support for window.ramenSettings.onload and window.ramenOnload. Change the way
14
14
  ramenSettings is set so that it can be merged with other options previously defined
15
15
  in <script> tags.
16
+
17
+ Version 0.5.0
18
+ Add support for Companies
@@ -30,6 +30,18 @@ module RamenRails
30
30
  end
31
31
  end
32
32
 
33
+ def current_company_labels=(value)
34
+ raise ArgumentError, "current_company_labels should be a Proc" unless value.kind_of?(Proc)
35
+ ensure_not_lambda!(value)
36
+
37
+ @current_company_labels = value
38
+ end
39
+
40
+ def current_company_labels
41
+ @current_company_labels
42
+ end
43
+
44
+
33
45
  def current_company=(value)
34
46
  raise ArgumentError, "current_company should be a Proc" unless value.kind_of?(Proc)
35
47
  ensure_not_lambda!(value)
@@ -85,6 +85,38 @@ module RamenRails
85
85
  controller.instance_variable_get(SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)
86
86
  end
87
87
 
88
+ POTENTIAL_RAMEN_COMPANY_OBJECTS = [
89
+ Proc.new { instance_eval(&RamenRails.config.current_company) if RamenRails.config.current_company.present? },
90
+ Proc.new { current_company },
91
+ Proc.new { @company }
92
+ ]
93
+
94
+ def ramen_company_labels
95
+ return nil unless ramen_company_object
96
+ controller.instance_eval(&RamenRails.config.current_company_labels) if RamenRails.config.current_company_labels.present?
97
+ rescue NameError => e
98
+ Rails.logger.debug "Swallowing NameError. We're probably in an Engine or some other context like Devise."
99
+ Rails.logger.debug e
100
+
101
+ nil
102
+ end
103
+
104
+ def ramen_company_object
105
+ POTENTIAL_RAMEN_COMPANY_OBJECTS.each do |potential_company|
106
+ begin
107
+ company = controller.instance_eval &potential_company
108
+ if (company.present? && company.name.present? && company.id.present?)
109
+ return company
110
+ end
111
+
112
+ rescue NameError
113
+ next
114
+ end
115
+ end
116
+
117
+ nil
118
+ end
119
+
88
120
  POTENTIAL_RAMEN_USER_OBJECTS = [
89
121
  Proc.new { instance_eval(&RamenRails.config.current_user) if RamenRails.config.current_user.present? },
90
122
  Proc.new { current_user },
@@ -173,6 +205,16 @@ module RamenRails
173
205
  obj[:user][:labels] = ramen_user_labels unless ramen_user_labels.nil?
174
206
  obj[:custom_links] = ramen_custom_links if ramen_custom_links.present?
175
207
 
208
+ company = ramen_company_object
209
+ if company
210
+ obj[:company] = {}
211
+
212
+ [:url, :name, :id].each do |attr|
213
+ obj[:company][attr] = company.send(attr)
214
+ end
215
+
216
+ obj[:company][:labels] = ramen_company_labels unless ramen_company_labels.nil?
217
+ end
176
218
 
177
219
  obj = obj.deep_merge(ramen_script_tag_options) if ramen_script_tag_options.present?
178
220
 
@@ -1,3 +1,3 @@
1
1
  module RamenRails
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -171,23 +171,44 @@ describe 'After filter' do
171
171
  end
172
172
 
173
173
  context "and a company" do
174
- before :each do
175
- RamenRails.config do |c|
176
- c.current_company = Proc.new { Hashie::Mash.new(name: 'Scrubber', url: 'https://scrubber.social') }
177
- c.current_user_labels = Proc.new { ["ryan", "gold"] }
174
+
175
+ context "that has no id" do
176
+ before :each do
177
+ RamenRails.config do |c|
178
+ c.current_company = Proc.new { Hashie::Mash.new(name: 'Scrubber', url: 'https://scrubber.social') }
179
+ c.current_company_labels = Proc.new { ["ryan", "gold"] }
180
+ end
181
+ end
182
+
183
+ it "should not attach user & company" do
184
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
185
+ expect(@dummy.response.body).to include("script")
186
+ expect(@dummy.response.body).to include("Angilly")
187
+ expect(@dummy.response.body).not_to include("company")
188
+ expect(@dummy.response.body).not_to include("Scrubber")
189
+ expect(@dummy.response.body).not_to include("gold")
178
190
  end
179
191
  end
192
+
193
+ context "that has an id" do
194
+ before :each do
195
+ RamenRails.config do |c|
196
+ c.current_company = Proc.new { Hashie::Mash.new(id: "1245", name: 'Scrubber', url: 'https://scrubber.social') }
197
+ c.current_company_labels = Proc.new { ["ryan", "gold"] }
198
+ end
199
+ end
180
200
 
181
- pending "should attach user & company" do
182
- filter = RamenRails::RamenAfterFilter.filter(@dummy)
183
- expect(@dummy.response.body).to include("script")
184
- expect(@dummy.response.body).to include("Angilly")
185
- expect(@dummy.response.body).to include("company")
186
- expect(@dummy.response.body).to include("Scrubber")
187
- expect(@dummy.response.body).to include("gold")
201
+ it "should attach user & company" do
202
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
203
+ expect(@dummy.response.body).to include("script")
204
+ expect(@dummy.response.body).to include("Angilly")
205
+ expect(@dummy.response.body).to include("company")
206
+ expect(@dummy.response.body).to include("Scrubber")
207
+ expect(@dummy.response.body).to include("1245")
208
+ expect(@dummy.response.body).to include("gold")
209
+ end
188
210
  end
189
211
  end
190
-
191
212
  end
192
213
  end
193
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramen-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Angilly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack