ramen-rails 0.0.7 → 0.0.8

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: 8cb736f36bad50e4c22b9379354fe0a1b3c9b012
4
- data.tar.gz: df380aa7ae3534a9cc8d7cc31f6b0358909dc264
3
+ metadata.gz: 0304673a1479bb4520012e46b5b5c3bcc04b0921
4
+ data.tar.gz: ac116b3c00a3f5f47ddafc7d03e2e4bef8712a4d
5
5
  SHA512:
6
- metadata.gz: 98def56c695d1dbac82f9855541fa8a8a3bfe4914bf68e1cbba883f3ce634223d6b68aefd488be79bfc4abce3c505e66e50c70d05d5dead10d130427deaa39a9
7
- data.tar.gz: a16d8186bb9cea6f3a6fd490fd9f7aaaa1bdb3bbf99f4dc853b34b35ede18ba7f3dc400513a669e14918c06bb37c706e9e28e020800db27742e1c0fb84c6c431
6
+ metadata.gz: baf021f697ff2ed7a24b52feb9598a87f7180dac43ad3966186af524d5bbaa5ec02006f17689cbcff23a660547bf63e75315c8479637918c81536f9fddcb2a4c
7
+ data.tar.gz: bc3321d94ebc3f498492a316cdd016a452433d526bcf94dd07920afe0aa6b0eca14270cca73ae3c029c962037320ff599688034aa25ee82cbc80c0743465ca4a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ramen-rails (0.0.6)
4
+ ramen-rails (0.0.7)
5
5
  activesupport (~> 4.0)
6
6
 
7
7
  GEM
@@ -37,12 +37,20 @@ RamenRails.config do |config|
37
37
  # config.current_user_value = Proc.new { current_user_value }
38
38
 
39
39
 
40
- ## How we access the current company in user. This object
41
- ## must respond to #id(string), #name(string), #url(string).
42
- ## It MAY respond to #value (a float)
43
- ##
44
- ## If config.current_user is empty, this will be ignored
40
+ ## Custom Links to add to the Ramen Tray
41
+ ## You can add up to 3. Each requires a `title`.
42
+ ## Each requires a `callback` or an `href`.
43
+ ## Links w/ `href` will have target="_blank".
44
+ ## Callbacks are *strings* not JS functions.
45
45
  #
46
- # config.current_company = Proc.new { current_company }
47
-
46
+ # config.custom_links = [
47
+ # {
48
+ # title: "Submit a bug",
49
+ # callback: "$('#submit_bug').modal('show')" #<-- String!
50
+ # },
51
+ # {
52
+ # title: "Knowledge Base",
53
+ # href: "/knowedge_base"
54
+ # }
55
+ # ]
48
56
  end
@@ -4,7 +4,12 @@ module RamenRails
4
4
 
5
5
  class << self
6
6
 
7
- attr_accessor :manual_opt_in, :return_url, :return_label
7
+ attr_accessor :manual_opt_in,
8
+ :environment,
9
+ :return_url,
10
+ :return_label,
11
+ :ramen_js_asset_uri,
12
+ :custom_links
8
13
 
9
14
  def ensure_not_lambda!(v)
10
15
  if v.lambda?
@@ -127,30 +127,10 @@ module RamenRails
127
127
  nil
128
128
  end
129
129
 
130
- def ramen_company
131
- return nil unless ramen_user_object
132
-
133
- begin
134
- company = controller.instance_eval(&RamenRails.config.current_company) if RamenRails.config.current_company.present?
135
- rescue NameError => e
136
- Rails.logger.debug "Swallowing NameError. We're probably in an Engine or some other context like Devise."
137
- Rails.logger.debug e
138
-
139
- company = nil
140
- end
141
-
142
- return nil unless company
143
-
144
- obj = {}
145
- [:url, :id, :value, :name].each do |attr|
146
- obj[attr] = company.send(attr) if company.respond_to?(attr) &&
147
- company.send(attr).present?
148
- end
149
-
150
- obj
130
+ def ramen_custom_links
131
+ RamenRails.config.custom_links
151
132
  end
152
133
 
153
-
154
134
  def ramen_script_tag
155
135
  obj = {}
156
136
  obj[:organization_id] = ramen_org_id
@@ -170,8 +150,7 @@ module RamenRails
170
150
 
171
151
  obj[:user][:value] = ramen_user_value if ramen_user_value.present?
172
152
  obj[:user][:labels] = ramen_user_labels unless ramen_user_labels.nil?
173
-
174
- obj[:company] = ramen_company if ramen_company.present?
153
+ obj[:custom_links] = ramen_custom_links if ramen_custom_links.present?
175
154
 
176
155
  super(obj, organization_secret: ramen_org_secret)
177
156
  end
@@ -17,18 +17,24 @@ module RamenRails
17
17
  self.options = options
18
18
  end
19
19
 
20
+ def ramen_js_asset_uri
21
+ RamenRails.config.ramen_js_asset_uri || "https://cdn.ramen.is/assets/ramen.js"
22
+ end
23
+
20
24
  def generate
21
25
  if ramen_settings.blank?
22
26
  raise EmptySettings.new("need to pass ramen_script_tag a non-empty ramen_settings argument")
23
27
  end
24
28
 
29
+ ramen_settings[:timestamp] ||= Time.now.to_i
30
+
25
31
  add_auth_hash!
26
32
 
27
33
  ramen_script = <<-RAMEN_SCRIPT
28
34
  <script id="RamenSettingsScriptTag">
29
35
  window.ramenSettings = #{ActiveSupport::JSON.encode(ramen_settings)};
30
36
  </script>
31
- <script src="https://cdn.ramen.is/assets/ramen.js" async></script>
37
+ <script src="#{ramen_js_asset_uri}" async></script>
32
38
  RAMEN_SCRIPT
33
39
 
34
40
  if controller
@@ -46,11 +52,7 @@ module RamenRails
46
52
 
47
53
  user = ramen_settings[:user]
48
54
 
49
- if ramen_settings[:timestamp]
50
- secret_string = "#{user[:email]}:#{user[:id]}:#{user[:name]}:#{ramen_settings[:timestamp]}:#{options[:organization_secret]}"
51
- else
52
- secret_string = "#{user[:email]}:#{user[:id]}:#{user[:name]}:#{options[:organization_secret]}"
53
- end
55
+ secret_string = "#{user[:email]}:#{user[:id]}:#{user[:name]}:#{ramen_settings[:timestamp]}:#{options[:organization_secret]}"
54
56
 
55
57
  ramen_settings[:auth_hash] = (Digest::SHA2.new << secret_string).to_s
56
58
  end
@@ -1,3 +1,3 @@
1
1
  module RamenRails
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/ramen-rails.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Ryan Angilly"]
10
10
  s.email = ["ryan@ramen.is"]
11
11
  s.homepage = "https://ramen.is"
12
- s.summary = %q{Rails gem for Ramen}
13
- s.description = %q{Ramen helps B2B SaaS product teams build better products through workflow-enhance customer development}
12
+ s.summary = %q{Rails gem for Ramen (https://ramen.is)}
13
+ s.description = %q{Ramen helps B2B SaaS product teams build better products through workflow-enhanced customer development}
14
14
 
15
15
 
16
16
  s.add_development_dependency "actionpack", "~>4.0"
@@ -4,7 +4,6 @@ describe "RamenRails::Config" do
4
4
 
5
5
  before :each do
6
6
  @user = Hashie::Mash.new(name: 'Ryan', email: 'ryan@ramen.is', id: '1234')
7
- @company = Hashie::Mash.new(name: 'Scrubber', url: 'http://scrubber.social', id: 'comp-1234')
8
7
  @organization_id = rand(1_000_000)
9
8
  @organization_secret = rand(1_000_000)
10
9
  end
@@ -14,14 +13,11 @@ describe "RamenRails::Config" do
14
13
  config.organization_id = @organization_id
15
14
  config.organization_secret = @organization_secret
16
15
  config.current_user = Proc.new { @user }
17
- config.current_company = Proc.new { @company }
18
16
  end
19
17
 
20
18
  expect(instance_eval(&RamenRails.config.current_user).id).to eq('1234')
21
- expect(instance_eval(&RamenRails.config.current_company).id).to eq('comp-1234')
22
19
 
23
20
  expect(RamenRails.config.current_user.call.id).to eq('1234')
24
- expect(RamenRails.config.current_company.call.id).to eq('comp-1234')
25
21
  expect(RamenRails.config.organization_id).to eq(@organization_id)
26
22
  expect(RamenRails.config.organization_secret).to eq(@organization_secret)
27
23
  end
@@ -5,13 +5,13 @@ describe 'After filter' do
5
5
  before :each do
6
6
  @dummy = Hashie::Mash.new({
7
7
  request: {
8
- original_url: "http://hiryan.com",
9
- },
8
+ original_url: "http://hiryan.com",
9
+ },
10
10
 
11
- response: {
12
- content_type: 'text/html',
13
- body: "<html><body>hi</body>"
14
- }
11
+ response: {
12
+ content_type: 'text/html',
13
+ body: "<html><body>hi</body>"
14
+ }
15
15
  })
16
16
  end
17
17
 
@@ -45,19 +45,57 @@ describe 'After filter' do
45
45
  ts = Time.now.to_i
46
46
  auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:5678").to_s
47
47
  ts_auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:#{ts}:5678").to_s
48
-
48
+
49
49
  filter = RamenRails::RamenAfterFilter.filter(@dummy)
50
-
50
+
51
51
  expect(@dummy.response.body).to_not include(auth_hash)
52
52
  expect(@dummy.response.body).to include(ts_auth_hash)
53
53
  expect(@dummy.response.body).to include("script")
54
54
  expect(@dummy.response.body).to include("Angilly")
55
55
  expect(@dummy.response.body).to include("hiryan.com")
56
56
  expect(@dummy.response.body).to_not include("company")
57
+ expect(@dummy.response.body).to_not include("custom_links")
58
+ end
59
+ end
60
+
61
+ context "and custom links" do
62
+ before :each do
63
+ RamenRails.config do |c|
64
+ c.custom_links = [
65
+ {
66
+ title: "Submit a bug",
67
+ callback: "$('#submit_bug').modal('show')"
68
+ },
69
+
70
+ {
71
+ title: "Knowledge Base",
72
+ href: "/knowedge_base"
73
+ }
74
+ ]
75
+ end
76
+ end
77
+
78
+ it "should attach tag" do
79
+ Timecop.freeze do
80
+ ts = Time.now.to_i
81
+ auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:5678").to_s
82
+ ts_auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:#{ts}:5678").to_s
83
+
84
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
85
+
86
+ expect(@dummy.response.body).to_not include(auth_hash)
87
+ expect(@dummy.response.body).to include(ts_auth_hash)
88
+ expect(@dummy.response.body).to include("script")
89
+ expect(@dummy.response.body).to include("Angilly")
90
+ expect(@dummy.response.body).to include("hiryan.com")
91
+ expect(@dummy.response.body).to_not include("company")
92
+ expect(@dummy.response.body).to include("custom_links")
93
+ end
94
+
57
95
  end
58
96
  end
59
97
 
60
- describe "and a company" do
98
+ context "and a company" do
61
99
  before :each do
62
100
  RamenRails.config do |c|
63
101
  c.current_company = Proc.new { Hashie::Mash.new(name: 'Scrubber', url: 'https://scrubber.social') }
@@ -65,7 +103,7 @@ describe 'After filter' do
65
103
  end
66
104
  end
67
105
 
68
- it "should attach user & company" do
106
+ pending "should attach user & company" do
69
107
  filter = RamenRails::RamenAfterFilter.filter(@dummy)
70
108
  expect(@dummy.response.body).to include("script")
71
109
  expect(@dummy.response.body).to include("Angilly")
@@ -46,26 +46,62 @@ describe 'Script Tag Helper' do
46
46
  end
47
47
 
48
48
  it "should calculate auth_hash correctly" do
49
+ ts = Time.now.to_i
49
50
  ramen_settings = {
50
51
  organization_id: rand(1_000_000),
51
52
  user: {
52
53
  email: 'ryan@ramen.is',
53
54
  name: 'Ryan Angilly',
54
55
  id: '346656'
55
- }
56
+ },
57
+ timestamp: ts
56
58
  }
57
59
 
58
60
  options = {organization_secret: "1234"}
59
61
 
60
- auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:1234").to_s
62
+ auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:#{ts}:1234").to_s
61
63
 
62
64
  output = @template.ramen_script_tag(ramen_settings, options)
63
65
 
66
+ expect(output).to include("https://cdn.ramen.is/assets/ramen.js")
64
67
  expect(output).to include("Ryan Angilly")
65
68
  expect(output).to include("auth_hash")
66
69
  expect(output).to include(auth_hash)
67
70
  end
68
71
 
72
+ context "with a changed asset config" do
73
+ before :each do
74
+ @js_uri = "http://cdn.ramen.dev/assets/ramen.js"
75
+ RamenRails.config do |c|
76
+ c.ramen_js_asset_uri = @js_uri
77
+ end
78
+ end
79
+
80
+ it "should calculate auth_hash correctly" do
81
+ ts = Time.now.to_i
82
+ ramen_settings = {
83
+ organization_id: rand(1_000_000),
84
+ user: {
85
+ email: 'ryan@ramen.is',
86
+ name: 'Ryan Angilly',
87
+ id: '346656'
88
+ },
89
+ timestamp: ts
90
+ }
91
+
92
+ options = {organization_secret: "1234"}
93
+
94
+ auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:#{ts}:1234").to_s
95
+
96
+ output = @template.ramen_script_tag(ramen_settings, options)
97
+
98
+ expect(output).to include(@js_uri)
99
+ expect(output).to include("Ryan Angilly")
100
+ expect(output).to include("auth_hash")
101
+ expect(output).to include(auth_hash)
102
+ end
103
+ end
104
+
69
105
  it "should work timestamp into hash if provided" do
70
106
  ts = Time.now.to_i
71
107
  ramen_settings = {
@@ -105,14 +141,11 @@ describe 'Script Tag Helper' do
105
141
 
106
142
  options = {organization_secret: "1234"}
107
143
 
108
- auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:1234").to_s
109
-
110
144
  output = @template.ramen_script_tag(ramen_settings, options)
111
145
 
112
146
  expect(output).to include("Ryan Angilly")
113
147
  expect(output).to include("auth_hash")
114
148
  expect(output).to include("hello")
115
- expect(output).to_not include(auth_hash)
116
149
 
117
150
  expect(@template.controller.instance_variable_get(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)).to eq(true)
118
151
  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.0.7
4
+ version: 0.0.8
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-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '4.0'
97
- description: Ramen helps B2B SaaS product teams build better products through workflow-enhance
97
+ description: Ramen helps B2B SaaS product teams build better products through workflow-enhanced
98
98
  customer development
99
99
  email:
100
100
  - ryan@ramen.is
@@ -146,7 +146,7 @@ rubyforge_project: ramen-rails
146
146
  rubygems_version: 2.2.2
147
147
  signing_key:
148
148
  specification_version: 4
149
- summary: Rails gem for Ramen
149
+ summary: Rails gem for Ramen (https://ramen.is)
150
150
  test_files:
151
151
  - spec/lib/config_spec.rb
152
152
  - spec/lib/ramen_after_filter_spec.rb