ramen-rails 0.6.0 → 0.6.1

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: 739a8cfacae68879c56af820125300e74c57b518
4
- data.tar.gz: 76475fc30d26b8dcd1470fbc54f1d37b1a1505b4
3
+ metadata.gz: 821f8dd4918426182f359794387fbd8a2f4bab85
4
+ data.tar.gz: 880aa7f4bc2641f5b46fdfa7da1a836b3a2f03cc
5
5
  SHA512:
6
- metadata.gz: 96fbb2673a786c57e93bdcb03f9e027b3c39dcd858a7e70dbe1bf5c9befd23bd488bed345bb024d223acc6adb4e5e07bafc8152a21f1aaf3fa41dc765d7c111d
7
- data.tar.gz: 17533a7f642eb7e3b8a39666035a250b0c16de1e35bd7070c4f680a884fdbe075ac0acbbbdaa76ff749e4c0afefb8b13c7e577d0968f76d553c0325bcea00acc
6
+ metadata.gz: 4da047101f00a72ac635f44cd00f20c64cd9241e59c5e651a97f845c2b916a8b303c36ba229227c6fc18af80c0c4c32b1220dd2540e2ed0d090b08799d16599e
7
+ data.tar.gz: 3fe409e377cba1f2e669d7fc0ebf92ec1cae4c89f354c612ad297260deb3813a42a389a68fe2b178c1e9fa8abf653c00e845bca21f8ea9a7908525f171fc5741
data/CHANGELOG CHANGED
@@ -22,3 +22,7 @@ Make importer support Companies. Add tests for importer.
22
22
 
23
23
  Version 0.6.0
24
24
  Support sending custom `trait` data into Ramen for Users & Companies.
25
+
26
+ Version 0.6.1
27
+ Check to see if `current_user` responds to `#persisted?` and, if so, and if it returns `false`,
28
+ don't render `ramenSettings`
@@ -134,17 +134,29 @@ module RamenRails
134
134
  end
135
135
 
136
136
  def ramen_user_object
137
+ user_to_return = nil
138
+
137
139
  POTENTIAL_RAMEN_USER_OBJECTS.each do |potential_user|
138
140
  begin
139
141
  user = controller.instance_eval &potential_user
140
- return user if user.present? &&
141
- (user.email.present? || user.id.present?)
142
+ if user.present? && (user.email.present? || user.id.present?)
143
+ user_to_return = user
144
+ break
145
+ end
146
+
142
147
  rescue NameError
143
148
  next
144
149
  end
145
150
  end
146
151
 
147
- nil
152
+ if user_to_return &&
153
+ user_to_return.respond_to?(:persisted?) &&
154
+ (user_to_return.persisted? == false)
155
+
156
+ nil
157
+ else
158
+ user_to_return
159
+ end
148
160
  end
149
161
 
150
162
  def ramen_user_value
@@ -1,3 +1,3 @@
1
1
  module RamenRails
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/ramen-rails.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency "rspec", "~>3.2"
19
19
  s.add_development_dependency "hashie", "~>3.4"
20
20
  s.add_development_dependency "timecop", "~>0.7"
21
+ s.add_development_dependency "byebug"
21
22
 
22
23
  s.add_dependency "activesupport", ">= 3.0"
23
24
 
@@ -1,18 +1,49 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module Dummy
4
+ Controller = Struct.new(:request, :response, :current_user, :ramen_script_tag_options)
5
+ Request = Struct.new(:original_url)
6
+ Response = Struct.new(:content_type, :body)
7
+
8
+ class User
9
+ def self.with(attrs)
10
+ user_class = Struct.new(*attrs.keys) do
11
+ def set(attrs)
12
+ @extras ||= Hashie::Mash.new
13
+ attrs.each {|k,v| @extras[k.to_s] = v }
14
+ end
15
+
16
+ def method_missing(name, *args, &block)
17
+ @extras ||= Hashie::Mash.new
18
+ if @extras.key?(name.to_s)
19
+ @extras[name.to_s]
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def respond_to?(name)
26
+ @extras ||= Hashie::Mash.new
27
+ @extras.key?(name.to_s) or super
28
+ end
29
+
30
+ end
31
+
32
+ user = user_class.new
33
+
34
+ attrs.each {|k, v| user.send("#{k}=", v) }
35
+
36
+ user
37
+ end
38
+ end
39
+ end
40
+
3
41
  describe 'After filter' do
4
42
 
5
43
  before :each do
6
- @dummy = Hashie::Mash.new({
7
- request: {
8
- original_url: "http://hiryan.com",
9
- },
10
-
11
- response: {
12
- content_type: 'text/html',
13
- body: "<html><body>hi</body>"
14
- }
15
- })
44
+ req = Dummy::Request.new("http://hiryan.com")
45
+ resp = Dummy::Response.new("text/html", "<html><body>hi</body></html>")
46
+ @dummy = Dummy::Controller.new(req, resp)
16
47
 
17
48
  module Rails
18
49
  class LogProxy
@@ -55,15 +86,15 @@ describe 'After filter' do
55
86
 
56
87
  describe "and a user" do
57
88
  before :each do
58
- @dummy.current_user = {email: 'ryan@ramen.is', name: 'Ryan Angilly', id: 'person-1234'}
89
+ @dummy.current_user = Dummy::User.with(email: 'ryan@ramen.is', name: 'Ryan Angilly', id: 'person-1234')
59
90
  end
60
91
 
61
92
  context "that does not respond to name" do
62
93
  before :each do
63
- @dummy.current_user = {email: 'ryan@ramen.is', id: 'person-1234'}
94
+ @dummy.current_user = Dummy::User.with(email: 'ryan@ramen.is', id: 'person-1234')
64
95
  end
65
96
 
66
- it "should render a comment erro" do
97
+ it "should render a comment error" do
67
98
  RamenRails::RamenAfterFilter.filter(@dummy)
68
99
  expect(@dummy.response.body).to include("See logs")
69
100
  end
@@ -71,7 +102,7 @@ describe 'After filter' do
71
102
 
72
103
  context "with a value proc set" do
73
104
  before :each do |c|
74
- @dummy.current_user.value = 1000
105
+ @dummy.current_user.set value: 1000
75
106
  RamenRails.config do |c|
76
107
  c.current_user_value = Proc.new { current_user.value }
77
108
  end
@@ -101,7 +132,7 @@ describe 'After filter' do
101
132
 
102
133
  context "that responds to traits" do
103
134
  before :each do
104
- @dummy.current_user.traits = {bucket: 6, is_friend: true, original_name: "Netflix"}
135
+ @dummy.current_user.set(traits: {bucket: 6, is_friend: true, original_name: "Netflix"})
105
136
  end
106
137
 
107
138
  it "should attach traits to company" do
@@ -110,11 +141,32 @@ describe 'After filter' do
110
141
  end
111
142
  end
112
143
 
144
+ context "that responds to #persisted? with false" do
145
+ before :each do
146
+ @dummy.current_user.set persisted?: false
147
+ end
148
+
149
+ it "should not render anything" do
150
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
151
+ expect(@dummy.response.body).to_not include("ramenSettings")
152
+ end
153
+ end
154
+
155
+ context "that responds to #persisted? with true" do
156
+ before :each do
157
+ @dummy.current_user.set persisted?: true
158
+ end
159
+
160
+ it "should render the tag" do
161
+ filter = RamenRails::RamenAfterFilter.filter(@dummy)
162
+ expect(@dummy.response.body).to include("ramenSettings")
163
+ end
164
+ end
113
165
 
114
166
  context "that responds to created_at" do
115
167
  before :each do
116
168
  @time = Time.new(2014, 11, 10)
117
- @dummy.current_user.created_at = @time
169
+ @dummy.current_user.set created_at: @time
118
170
  end
119
171
 
120
172
  it "should include created_at in output" do
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rspec'
2
2
  require 'ramen-rails'
3
3
  require 'hashie/mash'
4
4
  require 'timecop'
5
+ require 'byebug'
5
6
 
6
7
  RSpec.configure do |config|
7
8
 
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.6.0
4
+ version: 0.6.1
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-07-01 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: activesupport
85
99
  requirement: !ruby/object:Gem::Requirement