ramen-rails 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 111502efcd48f7a5aed23061c7660baf7d0db589
4
+ data.tar.gz: b52797f58a2979fd1c1aed4b9d1961f3c05f0895
5
+ SHA512:
6
+ metadata.gz: 7ae146cee640ef1adc7923f7baf4dae76081fec24fa9e47348154a4270961f20a3f1257faf54f82e26e5dbd7441aba62b35e9cfafc1efbe85ded45211247b091
7
+ data.tar.gz: 40a10679f67dc5916e7f3fd9a27c593e215897d2bdc4fc3a41ba88afaf45c6e90d54f8cfb0eb5b27779600025fe4e79677a6e64b62f5839aa531af43886e3ab4
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ramen-rails-dev
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ramen-rails (0.0.1)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (4.2.0)
11
+ actionview (= 4.2.0)
12
+ activesupport (= 4.2.0)
13
+ rack (~> 1.6.0)
14
+ rack-test (~> 0.6.2)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
+ actionview (4.2.0)
18
+ activesupport (= 4.2.0)
19
+ builder (~> 3.1)
20
+ erubis (~> 2.7.0)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ activesupport (4.2.0)
24
+ i18n (~> 0.7)
25
+ json (~> 1.7, >= 1.7.7)
26
+ minitest (~> 5.1)
27
+ thread_safe (~> 0.3, >= 0.3.4)
28
+ tzinfo (~> 1.1)
29
+ builder (3.2.2)
30
+ diff-lcs (1.2.5)
31
+ erubis (2.7.0)
32
+ hashie (3.4.0)
33
+ i18n (0.7.0)
34
+ json (1.8.2)
35
+ loofah (2.0.1)
36
+ nokogiri (>= 1.5.9)
37
+ mini_portile (0.6.2)
38
+ minitest (5.5.1)
39
+ nokogiri (1.6.6.2)
40
+ mini_portile (~> 0.6.0)
41
+ rack (1.6.0)
42
+ rack-test (0.6.3)
43
+ rack (>= 1.0)
44
+ rails-deprecated_sanitizer (1.0.3)
45
+ activesupport (>= 4.2.0.alpha)
46
+ rails-dom-testing (1.0.5)
47
+ activesupport (>= 4.2.0.beta, < 5.0)
48
+ nokogiri (~> 1.6.0)
49
+ rails-deprecated_sanitizer (>= 1.0.1)
50
+ rails-html-sanitizer (1.0.2)
51
+ loofah (~> 2.0)
52
+ rake (10.4.2)
53
+ rspec (3.2.0)
54
+ rspec-core (~> 3.2.0)
55
+ rspec-expectations (~> 3.2.0)
56
+ rspec-mocks (~> 3.2.0)
57
+ rspec-core (3.2.2)
58
+ rspec-support (~> 3.2.0)
59
+ rspec-expectations (3.2.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.2.0)
62
+ rspec-mocks (3.2.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.2.0)
65
+ rspec-support (3.2.2)
66
+ thread_safe (0.3.5)
67
+ tzinfo (1.2.2)
68
+ thread_safe (~> 0.1)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ actionpack
75
+ hashie
76
+ rake
77
+ ramen-rails!
78
+ rspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2015- Ramen, Inc. (https://ramen.is)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ module Ramen
2
+ module Generators
3
+ class ConfigGenerator < ::Rails::Generators::Base
4
+
5
+ def self.source_root
6
+ File.dirname(__FILE__)
7
+ end
8
+
9
+ argument :organization_id, :desc => "Your Ramen organization ID"
10
+ argument :organization_secret, :desc => "Your Ramen organization Secret"
11
+
12
+ def create_config_file
13
+ @organization_id = organization_id
14
+ @organization_secret = organization_secret
15
+ template("ramen.rb.erb", "config/initializers/ramen.rb")
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ RamenRails.config do |config|
2
+ # Your Ramen Organization ID
3
+ config.organization_id = "<%= @organization_id %>"
4
+
5
+ # Your Ramen Organization Secret
6
+ <%- if @organization_secret -%>
7
+ config.organization_secret = "<%= @organization_secret %>"
8
+ <%- else -%>
9
+ # config.organization_secret = "SEKRIT"
10
+ <%- end -%>
11
+
12
+
13
+ ## Important note regarding `-> {}` vs. `Proc.new {}`
14
+ ##
15
+ ## Use `Proc.new {}` and not `-> {}`. There's some weirdness
16
+ ## in how instance_eval works that will bite you in the butt
17
+ ## otherwise.
18
+
19
+
20
+ ## How we access the currently logged in user. This object
21
+ ## must respond to #email(string), #id(string), and #name(string)
22
+ #
23
+ # config.current_user = Proc.new { current_user }
24
+
25
+
26
+ ## How we access the labels for the currently logged in user.
27
+ ## This is an array of strings.
28
+ #
29
+ # config.current_user_labels = Proc.new { current_user.labels.map(&:name) }
30
+
31
+
32
+ ## How we access the current user "value". This is
33
+ ## a Float. It can represent whatever you want.
34
+ ##
35
+ ## If config.current_user is empty, this will be ignored
36
+ #
37
+ # config.current_user_value = Proc.new { current_user_value }
38
+
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
45
+ #
46
+ # config.current_company = Proc.new { current_company }
47
+
48
+
49
+ ## How we access the current company "value". This is
50
+ ## a Float. It can represent whatever you want.
51
+ ##
52
+ ## If config.current_user is empty, this will be ignored
53
+ #
54
+ # config.current_company_value = Proc.new { current_company_value }
55
+
56
+
57
+ end
@@ -0,0 +1,85 @@
1
+ module RamenRails
2
+ module Config
3
+ class NoLambdasPlease < StandardError; end
4
+
5
+ class << self
6
+
7
+ def ensure_not_lambda!(v)
8
+ if v.lambda?
9
+ raise NoLambdasPlease.new <<-ERR
10
+ You passed me a lambda (ie. `-> { a_thing }`) and not a Proc (ie. `Proc.new { a_thing }`).
11
+ This is important because of some inconsistencies in the way different versions of Ruby
12
+ yield arguments to blocks. Please pass me a Proc, not a lambda :)
13
+ ERR
14
+ end
15
+ end
16
+
17
+ def reset!
18
+ instance_variables.each do |v|
19
+ instance_variable_set v, nil
20
+ end
21
+ end
22
+
23
+ def current_company=(value)
24
+ raise ArgumentError, "current_company should be a Proc" unless value.kind_of?(Proc)
25
+ ensure_not_lambda!(value)
26
+
27
+ @current_company = value
28
+ end
29
+
30
+ def current_company
31
+ @current_company
32
+ end
33
+
34
+ def current_user=(value)
35
+ raise ArgumentError, "current_user should be a Proc" unless value.kind_of?(Proc)
36
+ ensure_not_lambda!(value)
37
+
38
+ @current_user = value
39
+ end
40
+
41
+ def current_user
42
+ @current_user
43
+ end
44
+
45
+ def current_user_value=(value)
46
+ raise ArgumentError, "current_user_value should be a Proc" unless value.kind_of?(Proc)
47
+ ensure_not_lambda!(value)
48
+
49
+ @current_user_value = value
50
+ end
51
+
52
+ def current_user_value
53
+ @current_user_value
54
+ end
55
+
56
+ def current_user_labels=(value)
57
+ raise ArgumentError, "current_user_labels should be a Proc" unless value.kind_of?(Proc)
58
+ ensure_not_lambda!(value)
59
+
60
+ @current_user_labels = value
61
+ end
62
+
63
+ def current_user_labels
64
+ @current_user_labels
65
+ end
66
+
67
+ def organization_id=(value)
68
+ @organization_id = value
69
+ end
70
+
71
+ def organization_id
72
+ @organization_id
73
+ end
74
+
75
+ def organization_secret=(value)
76
+ @organization_secret = value
77
+ end
78
+
79
+ def organization_secret
80
+ @organization_secret
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,16 @@
1
+ require 'ramen-rails/script_tag_helper'
2
+ require 'ramen-rails/ramen_after_filter'
3
+
4
+ module RamenRails
5
+ class Railtie < Rails::Railtie
6
+ initializer "ramen_rails.script_tag_helper.rb" do |app|
7
+ ActionView::Base.send :include,
8
+ ScriptTagHelper
9
+ end
10
+
11
+ initializer "ramen_rails.auto_include_filter.rb" do |app|
12
+ ActionController::Base.send :after_filter,
13
+ RamenAfterFilter
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,123 @@
1
+ module RamenRails
2
+
3
+ class RamenAfterFilter
4
+ include ScriptTagHelper
5
+ CLOSING_BODY_TAG = %r{</body>}
6
+
7
+ def self.filter(controller)
8
+ auto_include_filter = new(controller)
9
+ return unless auto_include_filter.include_javascript?
10
+
11
+ auto_include_filter.include_javascript!
12
+ end
13
+
14
+ attr_reader :controller
15
+
16
+ def initialize(kontroller)
17
+ @controller = kontroller
18
+ end
19
+
20
+ def include_javascript!
21
+ response.body = response.body.gsub(CLOSING_BODY_TAG, ramen_script_tag + '\\0')
22
+ end
23
+
24
+ def include_javascript?
25
+ !ramen_script_tag_called_manually? &&
26
+ html_content_type? &&
27
+ response_has_closing_body_tag? &&
28
+ ramen_org_id.present? &&
29
+ ramen_user_object.present?
30
+ end
31
+
32
+ private
33
+ def response
34
+ controller.response
35
+ end
36
+
37
+ def html_content_type?
38
+ response.content_type == 'text/html'
39
+ end
40
+
41
+ def response_has_closing_body_tag?
42
+ !!(response.body[CLOSING_BODY_TAG])
43
+ end
44
+
45
+ def ramen_script_tag_called_manually?
46
+ controller.instance_variable_get(SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)
47
+ end
48
+
49
+ POTENTIAL_RAMEN_USER_OBJECTS = [
50
+ Proc.new { instance_eval(&RamenRails.config.current_user) if RamenRails.config.current_user.present? },
51
+ Proc.new { current_user },
52
+ Proc.new { @user }
53
+ ]
54
+
55
+ def ramen_user_labels
56
+ return nil unless ramen_user_object
57
+ instance_eval(&RamenRails.config.current_user_labels) if RamenRails.config.current_user_labels.present?
58
+ end
59
+
60
+ def ramen_user_object
61
+ POTENTIAL_RAMEN_USER_OBJECTS.each do |potential_user|
62
+ begin
63
+ user = controller.instance_eval &potential_user
64
+ return user if user.present? &&
65
+ (user.email.present? || user.id.present?)
66
+ rescue NameError
67
+ next
68
+ end
69
+ end
70
+
71
+ nil
72
+ end
73
+
74
+ def ramen_user_value
75
+ return nil unless ramen_user_object
76
+ instance_eval(&RamenRails.config.current_user_value) if RamenRails.config.current_user_value.present?
77
+ end
78
+
79
+ def ramen_org_id
80
+ return ENV['RAMEN_ORGANIZATION_ID'] if ENV['RAMEN_ORGANIZATION_ID'].present?
81
+ return RamenRails.config.organization_id if RamenRails.config.organization_id.present?
82
+ return 'organization-id' if defined?(Rails) && Rails.env.development?
83
+
84
+ nil
85
+ end
86
+
87
+ def ramen_org_secret
88
+ return ENV['RAMEN_ORGANIZATION_SECRET'] if ENV['RAMEN_ORGANIZATION_SECRET'].present?
89
+ return RamenRails.config.organization_secret if RamenRails.config.organization_secret.present?
90
+ return 'organization-secret' if defined?(Rails) && Rails.env.development?
91
+
92
+ nil
93
+ end
94
+
95
+ def ramen_company
96
+ return nil unless ramen_user_object
97
+ instance_eval(&RamenRails.config.current_company) if RamenRails.config.current_company.present?
98
+ end
99
+
100
+
101
+ def ramen_script_tag
102
+ obj = {}
103
+ obj[:organization_id] = ramen_org_id
104
+ obj[:user] = {}
105
+
106
+ user = ramen_user_object
107
+
108
+ obj[:user][:id] = user.id if user.respond_to?(:id) && user.id.present?
109
+
110
+ [:email, :name].each do |attr|
111
+ obj[:user][attr] = user.send(attr) if user.respond_to?(attr) && user.send(attr).present?
112
+ end
113
+
114
+ obj[:user][:value] = ramen_user_value if ramen_user_value.present?
115
+ obj[:user][:labels] = ramen_user_labels unless ramen_user_labels.nil?
116
+
117
+ obj[:company] = ramen_company if ramen_company.present?
118
+
119
+ super(obj, organization_secret: ramen_org_secret)
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,33 @@
1
+ require "active_support/json"
2
+ require "active_support/core_ext/hash/indifferent_access"
3
+
4
+ module RamenRails
5
+ SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE = :@_ramen_script_tag_helper_called
6
+
7
+ module ScriptTagHelper
8
+
9
+ class EmptySettings < StandardError; end
10
+
11
+ def ramen_script_tag(ramen_settings, options = {})
12
+ if ramen_settings.blank?
13
+ raise EmptySettings.new("need to pass ramen_script_tag a non-empty ramen_settings argument")
14
+ end
15
+
16
+ if ramen_settings[:user].present? && options[:organization_secret].present? && ramen_settings[:auth_hash].blank?
17
+ user_details = ramen_settings[:user]
18
+ secret_string = "#{user_details[:email]}:#{user_details[:id]}:#{user_details[:name]}:#{options[:organization_secret]}"
19
+ ramen_settings[:auth_hash] = (Digest::SHA2.new << secret_string).to_s
20
+ end
21
+
22
+ ramen_script = <<-RAMEN_SCRIPT
23
+ <script id="RamenSettingsScriptTag">
24
+ var ramenSettings = #{ActiveSupport::JSON.encode(ramen_settings)};
25
+ </script>
26
+ <script src="https://cdn.ramen.is/assets/ramen.js" async></script>
27
+ RAMEN_SCRIPT
28
+
29
+ controller.instance_variable_set(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE, true) if defined?(controller)
30
+ ramen_script.respond_to?(:html_safe) ? ramen_script.html_safe : ramen_script
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module RamenRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'ramen-rails/railtie' if defined?(Rails) && defined?(Rails::Railtie)
2
+ require 'ramen-rails/config'
3
+ require 'ramen-rails/script_tag_helper'
4
+ require 'ramen-rails/ramen_after_filter'
5
+
6
+ module RamenRails
7
+ def self.config
8
+ block_given? ? yield(Config) : Config
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ramen-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ramen-rails"
7
+ s.version = RamenRails::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ryan Angilly"]
10
+ s.email = ["ryan@ramen.is"]
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}
14
+
15
+
16
+ s.add_development_dependency "actionpack"
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec"
19
+ s.add_development_dependency "hashie"
20
+
21
+ s.add_dependency "activesupport"
22
+
23
+ s.rubyforge_project = "ramen-rails"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RamenRails::Config" do
4
+
5
+ before :each do
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
+ @organization_id = rand(1_000_000)
9
+ @organization_secret = rand(1_000_000)
10
+ end
11
+
12
+ it "should set things" do
13
+ RamenRails.config do |config|
14
+ config.organization_id = @organization_id
15
+ config.organization_secret = @organization_secret
16
+ config.current_user = Proc.new { @user }
17
+ config.current_company = Proc.new { @company }
18
+ end
19
+
20
+ 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
+
23
+ expect(RamenRails.config.current_user.call.id).to eq('1234')
24
+ expect(RamenRails.config.current_company.call.id).to eq('comp-1234')
25
+ expect(RamenRails.config.organization_id).to eq(@organization_id)
26
+ expect(RamenRails.config.organization_secret).to eq(@organization_secret)
27
+ end
28
+
29
+ it "should error if passed a lambda" do
30
+ expect do
31
+ RamenRails.config do |c|
32
+ c.current_user = -> { @user }
33
+ end
34
+ end.to raise_error(RamenRails::Config::NoLambdasPlease)
35
+ end
36
+
37
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'After filter' do
4
+
5
+ before :each do
6
+ @dummy = Hashie::Mash.new({
7
+ response: {
8
+ content_type: 'text/html',
9
+ body: "<html><body>hi</body>"
10
+ }
11
+ })
12
+ end
13
+
14
+ describe "with no config" do
15
+ it "should not attach tag" do
16
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
17
+ expect(@dummy.response.body).to_not include("script")
18
+ end
19
+ end
20
+
21
+ describe "with a config" do
22
+ before :each do
23
+ RamenRails.config do |c|
24
+ c.organization_id = 1234
25
+ c.organization_secret = 5678
26
+ end
27
+ end
28
+
29
+ it "should not attach tag" do
30
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
31
+ expect(@dummy.response.body).to_not include("script")
32
+ end
33
+
34
+ describe "and a user" do
35
+ before :each do
36
+ @dummy.current_user = {email: 'ryan@ramen.is', name: 'Ryan Angilly', id: 'person-1234'}
37
+ end
38
+
39
+ it "should attach tag" do
40
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
41
+ expect(@dummy.response.body).to include("script")
42
+ expect(@dummy.response.body).to include("Angilly")
43
+ expect(@dummy.response.body).to_not include("company")
44
+ end
45
+
46
+ describe "and a company" do
47
+ before :each do
48
+ RamenRails.config do |c|
49
+ c.current_company = Proc.new { Hashie::Mash.new(name: 'Scrubber', url: 'https://scrubber.social') }
50
+ end
51
+ end
52
+
53
+ it "should attach user & company" do
54
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
55
+ expect(@dummy.response.body).to include("script")
56
+ expect(@dummy.response.body).to include("Angilly")
57
+ expect(@dummy.response.body).to include("company")
58
+ expect(@dummy.response.body).to include("Scrubber")
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ class DummyTemplate
4
+ def controller
5
+ @controller ||= Hashie::Mash.new
6
+ end
7
+
8
+ include RamenRails::ScriptTagHelper
9
+ end
10
+
11
+
12
+ describe 'Script Tag Helper' do
13
+
14
+ before :each do
15
+ @template = DummyTemplate.new
16
+ end
17
+
18
+ it "should have the false variable" do
19
+ expect(@template.controller.instance_variable_get(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)).to be(nil)
20
+ end
21
+
22
+ it "should raise if the script tag helper is passed a blank object" do
23
+ expect do
24
+ @template.ramen_script_tag({})
25
+ end.to raise_error(RamenRails::ScriptTagHelper::EmptySettings)
26
+ end
27
+
28
+ it "should render the tag" do
29
+ expect(@template.ramen_script_tag({organization_id: 1234})).to include("1234")
30
+ end
31
+
32
+ it "should not add auth_hash unless secret is given" do
33
+ ramen_settings = {
34
+ organization_id: rand(1_000_000),
35
+ user: {
36
+ email: 'ryan@ramen.is',
37
+ name: 'Ryan Angilly',
38
+ id: '346656'
39
+ }
40
+ }
41
+
42
+ output = @template.ramen_script_tag(ramen_settings)
43
+
44
+ expect(output).to include("Ryan Angilly")
45
+ expect(output).to_not include("auth_hash")
46
+ end
47
+
48
+ it "should calculate auth_hash correctly" do
49
+ ramen_settings = {
50
+ organization_id: rand(1_000_000),
51
+ user: {
52
+ email: 'ryan@ramen.is',
53
+ name: 'Ryan Angilly',
54
+ id: '346656'
55
+ }
56
+ }
57
+
58
+ options = {organization_secret: "1234"}
59
+
60
+ auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:1234").to_s
61
+
62
+ output = @template.ramen_script_tag(ramen_settings, options)
63
+
64
+ expect(output).to include("Ryan Angilly")
65
+ expect(output).to include("auth_hash")
66
+ expect(output).to include(auth_hash)
67
+ end
68
+
69
+ it "should not override auth_hash if it is provided" do
70
+ ramen_settings = {
71
+ organization_id: rand(1_000_000),
72
+ user: {
73
+ email: 'ryan@ramen.is',
74
+ name: 'Ryan Angilly',
75
+ id: '346656'
76
+ },
77
+ auth_hash: "hello"
78
+ }
79
+
80
+ options = {organization_secret: "1234"}
81
+
82
+ auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:1234").to_s
83
+
84
+ output = @template.ramen_script_tag(ramen_settings, options)
85
+
86
+ expect(output).to include("Ryan Angilly")
87
+ expect(output).to include("auth_hash")
88
+ expect(output).to include("hello")
89
+ expect(output).to_not include(auth_hash)
90
+
91
+ expect(@template.controller.instance_variable_get(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)).to eq(true)
92
+ end
93
+
94
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'ramen-rails'
3
+ require 'hashie/mash'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.before :each do
8
+ RamenRails.config.reset!
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ramen-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Angilly
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ramen helps B2B SaaS product teams build better products through workflow-enhance
84
+ customer development
85
+ email:
86
+ - ryan@ramen.is
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".ruby-gemset"
92
+ - ".ruby-version"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - MIT-LICENSE
96
+ - Rakefile
97
+ - lib/rails/generators/ramen/config/config_generator.rb
98
+ - lib/rails/generators/ramen/config/ramen.rb.erb
99
+ - lib/ramen-rails.rb
100
+ - lib/ramen-rails/config.rb
101
+ - lib/ramen-rails/railtie.rb
102
+ - lib/ramen-rails/ramen_after_filter.rb
103
+ - lib/ramen-rails/script_tag_helper.rb
104
+ - lib/ramen-rails/version.rb
105
+ - ramen-rails.gemspec
106
+ - spec/lib/config_spec.rb
107
+ - spec/lib/ramen_after_filter_spec.rb
108
+ - spec/lib/script_tag_helper_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://ramen.is
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project: ramen-rails
129
+ rubygems_version: 2.2.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Rails gem for Ramen
133
+ test_files:
134
+ - spec/lib/config_spec.rb
135
+ - spec/lib/ramen_after_filter_spec.rb
136
+ - spec/lib/script_tag_helper_spec.rb
137
+ - spec/spec_helper.rb