salesflip-jobboersen_integration 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app/lib/account_extras.rb +16 -6
- data/lib/app/lib/contact_extras.rb +8 -3
- data/lib/app/lib/user_extras.rb +8 -5
- data/lib/jobboersen_integration/engine.rb +1 -1
- data/test/models/account.rb +1 -0
- data/test/unit/account_test.rb +69 -13
- data/test/unit/contact_test.rb +67 -25
- data/test/unit/user_test.rb +49 -12
- metadata +4 -4
@@ -3,8 +3,8 @@ module AccountExtras
|
|
3
3
|
base.class_eval do
|
4
4
|
field :tjb_id
|
5
5
|
|
6
|
-
after_create :create_in_tjb
|
7
|
-
after_update :update_in_tjb, :unless => :do_not_update
|
6
|
+
after_create :create_in_tjb, :if => :prospect_or_customer?
|
7
|
+
after_update :update_in_tjb, :unless => :do_not_update, :if => :prospect_or_customer?
|
8
8
|
|
9
9
|
attr_accessor :do_not_update
|
10
10
|
end
|
@@ -17,19 +17,29 @@ module AccountExtras
|
|
17
17
|
"/administration/accounts.xml?auth_token=#{self.user.tjb_auth_token}",
|
18
18
|
self.to_xml(:only => [:name]))
|
19
19
|
attributes = Hash.from_xml(response.body)['account']
|
20
|
-
self.update_attributes :tjb_id => attributes['_id'],
|
21
|
-
:do_not_update => true
|
20
|
+
self.update_attributes :tjb_id => attributes['_id'], :do_not_update => true
|
22
21
|
rescue
|
23
22
|
nil
|
24
23
|
end
|
25
24
|
|
26
25
|
def update_in_tjb
|
27
|
-
|
28
|
-
|
26
|
+
if self.tjb_id
|
27
|
+
connection.put(
|
28
|
+
"/administration/accounts/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}",
|
29
|
+
self.to_xml(:only => [:name]))
|
30
|
+
else
|
31
|
+
create_in_tjb
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
nil
|
29
35
|
end
|
30
36
|
|
31
37
|
def connection
|
32
38
|
ActiveResource::Connection.new(JobboersenIntegration.jobboersen_uri)
|
33
39
|
end
|
40
|
+
|
41
|
+
def prospect_or_customer?
|
42
|
+
%w(Prospect Customer).include?(self.account_type)
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
@@ -4,7 +4,7 @@ module ContactExtras
|
|
4
4
|
field :tjb_id
|
5
5
|
|
6
6
|
after_create :create_in_tjb
|
7
|
-
after_update :update_in_tjb, :unless => :
|
7
|
+
after_update :update_in_tjb, :unless => :do_not_update
|
8
8
|
|
9
9
|
attr_accessor :do_not_update
|
10
10
|
end
|
@@ -23,8 +23,13 @@ module ContactExtras
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def update_in_tjb
|
26
|
-
|
27
|
-
|
26
|
+
if self.tjb_id
|
27
|
+
connection.put(
|
28
|
+
"/administration/contacts/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}",
|
29
|
+
tjb_xml)
|
30
|
+
else
|
31
|
+
create_in_tjb
|
32
|
+
end
|
28
33
|
rescue
|
29
34
|
nil
|
30
35
|
end
|
data/lib/app/lib/user_extras.rb
CHANGED
@@ -20,17 +20,20 @@ module UserExtras
|
|
20
20
|
if response.code == '200'
|
21
21
|
attributes = Hash.from_xml(response.body)['administrator']
|
22
22
|
self.update_attributes :tjb_id => attributes['_id'],
|
23
|
-
:tjb_auth_token => attributes['authentication_token'],
|
24
|
-
:do_not_update => true
|
23
|
+
:tjb_auth_token => attributes['authentication_token'], :do_not_update => true
|
25
24
|
end
|
26
25
|
rescue
|
27
26
|
nil
|
28
27
|
end
|
29
28
|
|
30
29
|
def update_in_tjb
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
if self.tjb_id
|
31
|
+
connection.put(
|
32
|
+
"/administration/administrators/#{self.tjb_id}.xml?auth_token=#{self.tjb_auth_token}",
|
33
|
+
self.to_xml(:only => :email))
|
34
|
+
else
|
35
|
+
create_in_tjb
|
36
|
+
end
|
34
37
|
rescue
|
35
38
|
nil
|
36
39
|
end
|
data/test/models/account.rb
CHANGED
data/test/unit/account_test.rb
CHANGED
@@ -15,20 +15,76 @@ class AccountTest < ActiveSupport::TestCase
|
|
15
15
|
assert Account.instance_methods.include?('do_not_update=')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
context 'creating a new account' do
|
19
|
+
should 'should update the tjb_id when the account has been created in 1000jobboersen' do
|
20
|
+
FakeWeb.register_uri(:post,
|
21
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
22
|
+
:body => File.read('test/support/account_create_success.xml'))
|
23
|
+
account = Account.create! :name => 'test account', :user => @user, :account_type => 'Prospect'
|
24
|
+
assert_equal '4bcdbfea24d8f22230000011', account.tjb_id
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'not attempt to create in 1000jobboersen if the account is not type: "Prospect" or "Customer"' do
|
28
|
+
FakeWeb.register_uri(:post,
|
29
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
30
|
+
:body => File.read('test/support/account_create_success.xml'))
|
31
|
+
%w(Competitor Investor).each do |type|
|
32
|
+
account = Account.create! :name => 'test account', :user => @user, :account_type => type
|
33
|
+
assert account.tjb_id.blank?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'not blow up if a 500 response is returned' do
|
38
|
+
FakeWeb.register_uri(:post,
|
39
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
40
|
+
:status => '500')
|
41
|
+
account = Account.create! :name => 'test account', :user => @user, :account_type => 'Prospect'
|
42
|
+
assert account.id
|
43
|
+
assert !account.new_record?
|
44
|
+
end
|
24
45
|
end
|
25
46
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
47
|
+
context 'updating an account' do
|
48
|
+
context 'when the account exists in 1000jobboersen' do
|
49
|
+
setup do
|
50
|
+
FakeWeb.register_uri(:post,
|
51
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
52
|
+
:body => File.read('test/support/account_create_success.xml'))
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'not blow up when an error response is returned' do
|
56
|
+
account = Account.create! :name => 'test account', :user => @user
|
57
|
+
FakeWeb.register_uri(:put,
|
58
|
+
"http://1000jobboersen.de/administration/accounts/#{account.tjb_id}.xml?auth_token=#{@user.tjb_auth_token}",
|
59
|
+
:status => '500')
|
60
|
+
account = Account.find(account.id)
|
61
|
+
account.update_attributes! :name => 'test'
|
62
|
+
assert account.valid?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when the account does not exist in 1000jobboersen' do
|
67
|
+
setup do
|
68
|
+
FakeWeb.register_uri(:post,
|
69
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
70
|
+
:body => File.read('test/support/account_create_success.xml'))
|
71
|
+
FakeWeb.register_uri(:put,
|
72
|
+
"http://1000jobboersen.de/administration/accounts/.xml?auth_token=#{@user.tjb_auth_token}",
|
73
|
+
:status => '500')
|
74
|
+
@account = Account.create! :name => 'test account', :account_type => 'Investor', :user => @user
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'create the account in 1000jobboersen' do
|
78
|
+
assert @account.tjb_id.nil?
|
79
|
+
@account.update_attributes :account_type => 'Prospect'
|
80
|
+
assert_equal '4bcdbfea24d8f22230000011', @account.tjb_id
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'not attempt to create account in tjb unless account_type is "Prospect" or "Customer"' do
|
84
|
+
assert @account.tjb_id.nil?
|
85
|
+
@account.update_attributes :account_type => 'some other type'
|
86
|
+
assert @account.tjb_id.nil?
|
87
|
+
end
|
88
|
+
end
|
33
89
|
end
|
34
90
|
end
|
data/test/unit/contact_test.rb
CHANGED
@@ -15,33 +15,75 @@ class ContactTest < ActiveSupport::TestCase
|
|
15
15
|
assert Contact.instance_methods.include?('do_not_update=')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
context 'creating a new contact (user)' do
|
19
|
+
should 'only send first_name, last_name, email, password and password_confirmation in xml' do
|
20
|
+
contact = Contact.new :first_name => 'Matt', :last_name => 'Beedle',
|
21
|
+
:email => 'mattbeedle@googlemail.com', :password => 'berlin5000',
|
22
|
+
:password_confirmation => 'berlin5000', :another_field => 'asfewaf'
|
23
|
+
assert_match(/first\-name/, contact.tjb_xml)
|
24
|
+
assert_match(/last\-name/, contact.tjb_xml)
|
25
|
+
assert_match(/email/, contact.tjb_xml)
|
26
|
+
assert_match(/password/, contact.tjb_xml)
|
27
|
+
assert_match(/password\-confirmation/, contact.tjb_xml)
|
28
|
+
assert_no_match(/another\-field/, contact.tjb_xml)
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'set the tjb_id when the contact has been created in 1000jobboersen' do
|
32
|
+
FakeWeb.register_uri(:post,
|
33
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
34
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
35
|
+
contact = Contact.create! :first_name => 'Matt', :last_name => 'Beedle',
|
36
|
+
:email => 'mattbeedle@googlemail.com', :user => @user
|
37
|
+
assert_equal '4b8ead6a24d8f247be001073', contact.tjb_id
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
should 'not blow up when 1000jobboersen returns an error response' do
|
41
|
+
FakeWeb.register_uri(:post,
|
42
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
43
|
+
:status => '500')
|
44
|
+
contact = Contact.create! :first_name => 'Matt', :last_name => 'Beedle',
|
45
|
+
:email => 'mattbeedle@googlemail.com', :user => @user
|
46
|
+
assert !contact.new_record?
|
47
|
+
end
|
37
48
|
end
|
38
49
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
context 'updating a contact' do
|
51
|
+
context 'when the contact exists in 1000jobboersen' do
|
52
|
+
setup do
|
53
|
+
FakeWeb.register_uri(:post,
|
54
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
55
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'not blow up when an error response is returned' do
|
59
|
+
contact = Contact.create! :first_name => 'Matt', :last_name => 'Beedle',
|
60
|
+
:email => 'mattbeedle@googlemail.com', :user => @user
|
61
|
+
FakeWeb.register_uri(:put,
|
62
|
+
"http://1000jobboersen.de/administration/users/#{contact.tjb_id}.xml?auth_token=#{@user.tjb_auth_token}",
|
63
|
+
:status => '500')
|
64
|
+
contact = Contact.find(contact.id)
|
65
|
+
contact.update_attributes :first_name => 'test'
|
66
|
+
assert contact.valid?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the contact does not exist in 1000jobboersen' do
|
71
|
+
setup do
|
72
|
+
FakeWeb.register_uri(:post,
|
73
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
74
|
+
:status => '500')
|
75
|
+
@contact = Contact.create! :first_name => 'Matt', :last_name => 'Beedle',
|
76
|
+
:email => 'mattbeedle@googlemail.com', :user => @user
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'create the contact (user) in 1000jobboersen' do
|
80
|
+
FakeWeb.register_uri(:post,
|
81
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
82
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
83
|
+
assert @contact.tjb_id.blank?
|
84
|
+
@contact.update_attributes :first_name => 'someone'
|
85
|
+
assert_equal '4b8ead6a24d8f247be001073', @contact.tjb_id
|
86
|
+
end
|
87
|
+
end
|
46
88
|
end
|
47
89
|
end
|
data/test/unit/user_test.rb
CHANGED
@@ -17,19 +17,56 @@ class UserTest < ActiveSupport::TestCase
|
|
17
17
|
should 'have tjb_auth_token field' do
|
18
18
|
assert User.fields.map(&:first).include?('tjb_auth_token')
|
19
19
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
:
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
|
21
|
+
context 'creating a new user' do
|
22
|
+
should 'update the tjb_id when the administrator account has been created in 1000jobboersen' do
|
23
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
24
|
+
:body => File.read('test/support/administrator_create_success.xml'))
|
25
|
+
user = User.create! :email => 'test@test.com'
|
26
|
+
assert_equal '4bcdbfea24d8f22230000011', user.tjb_id
|
27
|
+
assert_equal 'La9Hbm8SnPJN-F-zUhlp', user.tjb_auth_token
|
28
|
+
end
|
29
|
+
|
30
|
+
should 'not blow up when an error response is returned' do
|
31
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
32
|
+
:status => '500')
|
33
|
+
user = User.create! :email => 'test@test.com'
|
34
|
+
assert !user.new_record?
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
38
|
+
context 'updating a user (administrator)' do
|
39
|
+
context 'when the administrator exists in 1000jobboersen' do
|
40
|
+
setup do
|
41
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
42
|
+
:body => File.read('test/support/administrator_create_success.xml'))
|
43
|
+
@user = User.create! :email => 'test@test.com'
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'not blow up when an error response is returned' do
|
47
|
+
FakeWeb.register_uri(:put,
|
48
|
+
"http://1000jobboersen.de/administration/administrators/#{@user.id}.xml?auth_token=#{@user.tjb_auth_token}",
|
49
|
+
:status => '500')
|
50
|
+
@user = User.find(@user.id)
|
51
|
+
@user.update_attributes :email => 'another_test@test.com'
|
52
|
+
assert @user.valid?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when the administrator does not exist in 1000jobboersen' do
|
57
|
+
setup do
|
58
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
59
|
+
:status => '500')
|
60
|
+
@user = User.create! :email => 'test@test.com'
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'attempt to create the administrator in 1000jobboersen' do
|
64
|
+
@user = User.find(@user.id)
|
65
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
66
|
+
:body => File.read('test/support/administrator_create_success.xml'))
|
67
|
+
@user.update_attributes! :email => 'another_test@test.com'
|
68
|
+
assert_equal '4bcdbfea24d8f22230000011', @user.tjb_id
|
69
|
+
end
|
70
|
+
end
|
34
71
|
end
|
35
72
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesflip-jobboersen_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|