ramen-rails 0.5.0 → 0.5.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: a4bdf745220103d28895c16d259b69f1e390fd44
4
- data.tar.gz: 4e9e118f904506cd55e13dfedb109ed4a313dd5f
3
+ metadata.gz: 9de77426d862cf8695c418cc468c76e3760a89cd
4
+ data.tar.gz: b09b033f511c2a342e1eac842a14068d2fb4fd98
5
5
  SHA512:
6
- metadata.gz: ae8cffe0b2ba0ee8b09d92c6aefb7c72c11dc2cd5799743a2a2d45de836256caab170ac8522c380c3a8161b5d044588da90c782d0649de7bf57c6a9b5b3e81e1
7
- data.tar.gz: 7b1593f7be00a1e2ce9a6c33440557ab92c37cc0663b8a160c8c7b87e593a6bcd08407884738e22f1f71f83ef54d397f9eb5c8313108e274ba3c30ff893ae815
6
+ metadata.gz: acb1e662f59381d32a1bc9fb764c94b2de8e6bf138aaf63d150c0afcba4e6f271d8dd2211d894d1430ddca5a5e262f951713ea80227f4e0868a7cd91f9938cad
7
+ data.tar.gz: 6937e82d0cf6a6bd1cd1a8472ec4f446d7e25a55a3d0a865b2914b54c5e7a563f1c33dc4059f14a9ad2c53607cb20670f02c895fd8e784793e94d8b82b160ae0
data/CHANGELOG CHANGED
@@ -16,3 +16,6 @@ in <script> tags.
16
16
 
17
17
  Version 0.5.0
18
18
  Add support for Companies
19
+
20
+ Version 0.5.1
21
+ Make importer support Companies. Add tests for importer.
@@ -10,9 +10,7 @@ module RamenRails
10
10
  :return_url,
11
11
  :return_label,
12
12
  :ramen_js_asset_uri,
13
- :custom_links,
14
- :import_user_labels,
15
- :import_user_value
13
+ :custom_links
16
14
 
17
15
  def ensure_not_lambda!(v)
18
16
  if v.lambda?
@@ -85,6 +83,31 @@ module RamenRails
85
83
  def current_user_labels
86
84
  @current_user_labels
87
85
  end
86
+
87
+ attr_reader :import_company_labels
88
+ def import_company_labels=(value)
89
+ raise ArgumentError, "import_company_labels should be a Proc" unless value.kind_of?(Proc)
90
+ ensure_not_lambda!(value)
91
+
92
+ @import_company_labels = value
93
+ end
94
+
95
+ attr_reader :import_user_labels
96
+ def import_user_labels=(value)
97
+ raise ArgumentError, "import_user_labels should be a Proc" unless value.kind_of?(Proc)
98
+ ensure_not_lambda!(value)
99
+
100
+ @import_user_labels = value
101
+ end
102
+
103
+ attr_reader :import_user_value
104
+ def import_user_value=(value)
105
+ raise ArgumentError, "import_user_value should be a Proc" unless value.kind_of?(Proc)
106
+ ensure_not_lambda!(value)
107
+
108
+ @import_user_value = value
109
+ end
110
+
88
111
 
89
112
  def organization_id=(value)
90
113
  @organization_id = value
@@ -12,9 +12,15 @@ module RamenRails
12
12
  end
13
13
 
14
14
  attr_accessor :user
15
+ attr_accessor :company
15
16
 
16
- def initialize(opts)
17
+ def initialize(opts = {})
17
18
  self.user = opts[:user]
19
+ self.company = opts[:company]
20
+ end
21
+
22
+ def can_get_company_labels?
23
+ RamenRails.config.import_company_labels.present?
18
24
  end
19
25
 
20
26
  def can_get_labels?
@@ -25,6 +31,11 @@ module RamenRails
25
31
  RamenRails.config.import_user_value.present?
26
32
  end
27
33
 
34
+ def get_company_labels
35
+ company.
36
+ instance_eval(&RamenRails.config.import_company_labels)
37
+ end
38
+
28
39
  def get_labels
29
40
  user.
30
41
  instance_eval(&RamenRails.config.import_user_labels)
@@ -36,10 +47,37 @@ module RamenRails
36
47
  end
37
48
 
38
49
  def import
50
+ h = generate_hash
51
+ json = h.to_json
52
+
53
+ endpoint = ENV['RAMEN_IMPORT_URI'] || "https://ramen.is/po.json"
54
+ uri = URI("#{endpoint}?json_payload=#{CGI.escape(json)}")
55
+ start = Time.now.to_f
56
+ resp = Net::HTTP.get_response(uri)
57
+ total = Time.now.to_f - start
58
+
59
+ if resp.code == "200"
60
+ puts "Imported #{obj[:name]} <#{obj[:email]}> in #{total} seconds"
61
+ else
62
+ puts "ERROR (#{resp.code}) Importing #{obj[:name]} <#{obj[:email]}>. Continuing...."
63
+ puts resp.body.to_s
64
+ end
65
+ end
66
+
67
+ def generate_hash
39
68
  obj = {}
40
69
  [:email, :name, :id].each do |attr|
41
70
  obj[attr] = user.send(attr)
42
71
  end
72
+
73
+ company_obj = {}
74
+ if company
75
+ [:url, :name, :id].each do |attr|
76
+ company_obj[attr] = user.send(attr)
77
+ end
78
+
79
+ company_obj[:labels] = get_company_labels if can_get_company_labels?
80
+ end
43
81
 
44
82
  obj[:labels] = get_labels if can_get_labels?
45
83
  obj[:value] = get_value if can_get_value?
@@ -60,20 +98,9 @@ module RamenRails
60
98
  import: true
61
99
  }
62
100
 
63
- json = h.to_json
64
-
65
- endpoint = ENV['RAMEN_IMPORT_URI'] || "https://ramen.is/po.json"
66
- uri = URI("#{endpoint}?json_payload=#{CGI.escape(json)}")
67
- start = Time.now.to_f
68
- resp = Net::HTTP.get_response(uri)
69
- total = Time.now.to_f - start
70
-
71
- if resp.code == "200"
72
- puts "Imported #{obj[:name]} <#{obj[:email]}> in #{total} seconds"
73
- else
74
- puts "ERROR (#{resp.code}) Importing #{obj[:name]} <#{obj[:email]}>. Continuing...."
75
- puts resp.body.to_s
76
- end
101
+ h[:company] = company_obj if company_obj.present?
102
+
103
+ h
77
104
  end
78
105
  end
79
106
  end
@@ -1,3 +1,3 @@
1
1
  module RamenRails
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RamenRails::Import" do
4
+
5
+ before :each do
6
+ @user = Hashie::Mash.new(name: 'Ryan', email: 'ryan@ramen.is', id: '1234')
7
+ @organization_id = rand(1_000_000)
8
+ @organization_secret = rand(1_000_000)
9
+
10
+ RamenRails.config do |config|
11
+ config.organization_id = @organization_id
12
+ config.organization_secret = @organization_secret
13
+ config.current_user = Proc.new { @user }
14
+ end
15
+
16
+ @importer = RamenRails::Import.new
17
+ @importer.user = @user
18
+ end
19
+
20
+ it "should have user info in hash" do
21
+ expect(@importer.generate_hash[:user][:email]).
22
+ to eq('ryan@ramen.is')
23
+ end
24
+
25
+ it "should not have company data" do
26
+ expect(@importer.generate_hash[:company]).to be_nil
27
+ end
28
+
29
+ it "should set :import true" do
30
+ expect(@importer.generate_hash[:import]).to eq(true)
31
+ end
32
+
33
+ context "with a company" do
34
+ before :each do
35
+ @company = Hashie::Mash.new({id: 1234, url: 'https://ramen.is', name: 'Fake Rake'})
36
+ @importer.company = @company
37
+ end
38
+
39
+ it "should have company data" do
40
+ expect(@importer.generate_hash[:company][:id]).
41
+ to eq("1234")
42
+ end
43
+ end
44
+ 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.5.0
4
+ version: 0.5.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-06-03 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -123,6 +123,7 @@ files:
123
123
  - lib/ramen-rails/version.rb
124
124
  - ramen-rails.gemspec
125
125
  - spec/lib/config_spec.rb
126
+ - spec/lib/import_spec.rb
126
127
  - spec/lib/ramen_after_filter_spec.rb
127
128
  - spec/lib/script_tag_helper_spec.rb
128
129
  - spec/spec_helper.rb
@@ -152,6 +153,7 @@ specification_version: 4
152
153
  summary: Rails gem for Ramen (https://ramen.is)
153
154
  test_files:
154
155
  - spec/lib/config_spec.rb
156
+ - spec/lib/import_spec.rb
155
157
  - spec/lib/ramen_after_filter_spec.rb
156
158
  - spec/lib/script_tag_helper_spec.rb
157
159
  - spec/spec_helper.rb