salesflip-jobboersen_integration 0.2.3 → 0.2.4
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.
- data/lib/app/lib/contact_extras.rb +6 -2
- data/lib/jobboersen_integration/engine.rb +1 -4
- data/test/models/contact.rb +1 -0
- data/test/unit/contact_test.rb +81 -37
- metadata +4 -4
@@ -3,8 +3,8 @@ module ContactExtras
|
|
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 => :has_account?
|
7
|
+
after_update :update_in_tjb, :unless => :do_not_update, :if => :has_account?
|
8
8
|
|
9
9
|
attr_accessor :do_not_update
|
10
10
|
end
|
@@ -47,5 +47,9 @@ module ContactExtras
|
|
47
47
|
def generate_password
|
48
48
|
Array.new(10/2) { rand(256) }.pack('C*').unpack('H*').first
|
49
49
|
end
|
50
|
+
|
51
|
+
def has_account?
|
52
|
+
!account.blank?
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
@@ -19,7 +19,7 @@ module JobboersenIntegration
|
|
19
19
|
Salesflip::Plugin.register(:jobboersen_integration) do
|
20
20
|
name 'JobBoersen Integration'
|
21
21
|
author 'Matt Beedle'
|
22
|
-
version '0.2.
|
22
|
+
version '0.2.4'
|
23
23
|
description 'Everything to seemlessly integrate 1000jobboersen.de'
|
24
24
|
end
|
25
25
|
|
@@ -29,9 +29,6 @@ module JobboersenIntegration
|
|
29
29
|
require 'app/lib/user_extras'
|
30
30
|
User.send(:include, UserExtras)
|
31
31
|
|
32
|
-
require 'app/lib/contact_extras'
|
33
|
-
Contact.send(:include, ContactExtras)
|
34
|
-
|
35
32
|
require 'app/lib/controller_hooks'
|
36
33
|
end
|
37
34
|
end
|
data/test/models/contact.rb
CHANGED
data/test/unit/contact_test.rb
CHANGED
@@ -2,8 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ContactTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
+
FakeWeb.register_uri(:post,
|
6
|
+
'http://1000jobboersen.de/administration/accounts.xml?auth_token=La9Hbm8SnPJN-F-zUhlp',
|
7
|
+
:body => File.read('test/support/account_create_success.xml'))
|
8
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
9
|
+
:body => File.read('test/support/administrator_create_success.xml'))
|
5
10
|
Contact.send(:include, ContactExtras)
|
6
11
|
@user = User.create :email => 'test@test.com', :tjb_auth_token => 'La9Hbm8SnPJN-F-zUhlp'
|
12
|
+
@account = Account.create :name => 'test account', :user => @user
|
7
13
|
end
|
8
14
|
|
9
15
|
should 'have tjb_id field' do
|
@@ -16,74 +22,112 @@ class ContactTest < ActiveSupport::TestCase
|
|
16
22
|
end
|
17
23
|
|
18
24
|
context 'creating a new contact (user)' do
|
19
|
-
|
20
|
-
|
21
|
-
:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
context 'when the contact has an associated account' do
|
26
|
+
setup do
|
27
|
+
@contact = Contact.new :first_name => 'Matt', :last_name => 'Beedle',
|
28
|
+
:email => 'mattbeedle@googlemail.com', :password => 'berlin5000',
|
29
|
+
:password_confirmation => 'berlin5000', :another_field => 'asfewaf',
|
30
|
+
:account => @account, :user => @user
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'only send first_name, last_name, email, password and password_confirmation in xml' do
|
34
|
+
assert_match(/first\-name/, @contact.tjb_xml)
|
35
|
+
assert_match(/last\-name/, @contact.tjb_xml)
|
36
|
+
assert_match(/email/, @contact.tjb_xml)
|
37
|
+
assert_match(/password/, @contact.tjb_xml)
|
38
|
+
assert_match(/password\-confirmation/, @contact.tjb_xml)
|
39
|
+
assert_no_match(/another\-field/, @contact.tjb_xml)
|
40
|
+
end
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
42
|
+
should 'set the tjb_id when the contact has been created in 1000jobboersen' do
|
43
|
+
FakeWeb.register_uri(:post,
|
44
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
45
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
46
|
+
@contact.save!
|
47
|
+
assert_equal '4b8ead6a24d8f247be001073', @contact.tjb_id
|
48
|
+
end
|
39
49
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
should 'not blow up when 1000jobboersen returns an error response' do
|
51
|
+
FakeWeb.register_uri(:post,
|
52
|
+
"http://1000jobboersen.de/administration/contacts.xml?auth_token=#{@user.tjb_auth_token}",
|
53
|
+
:status => '500')
|
54
|
+
@contact.save!
|
55
|
+
assert !@contact.new_record?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the contact does not have an associated account' do
|
60
|
+
setup do
|
61
|
+
@contact = Contact.new :first_name => 'Matt', :last_name => 'Beedle',
|
62
|
+
:email => 'mattbeedle@googlemail.com', :password => 'berlin5000',
|
63
|
+
:password_confirmation => 'berlin5000', :another_field => 'asfewaf',
|
64
|
+
:user => @user
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'not attempt to create a user in 1000jb' do
|
68
|
+
FakeWeb.register_uri(:post,
|
69
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
70
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
71
|
+
@contact.save!
|
72
|
+
assert @contact.tjb_id.blank?
|
73
|
+
end
|
47
74
|
end
|
48
75
|
end
|
49
76
|
|
50
77
|
context 'updating a contact' do
|
78
|
+
setup do
|
79
|
+
@contact = Contact.new :first_name => 'Matt', :last_name => 'Beedle',
|
80
|
+
:email => 'mattbeedle@googlemail.com', :user => @user, :account => @account
|
81
|
+
end
|
82
|
+
|
51
83
|
context 'when the contact exists in 1000jobboersen' do
|
52
84
|
setup do
|
53
85
|
FakeWeb.register_uri(:post,
|
54
|
-
"http://1000jobboersen.de/administration/
|
86
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
55
87
|
:body => File.read('test/support/contact_create_success.xml'))
|
56
88
|
end
|
57
89
|
|
58
90
|
should 'not blow up when an error response is returned' do
|
59
|
-
contact
|
60
|
-
:email => 'mattbeedle@googlemail.com', :user => @user
|
91
|
+
@contact.save!
|
61
92
|
FakeWeb.register_uri(:put,
|
62
|
-
"http://1000jobboersen.de/administration/users/#{contact.tjb_id}.xml?auth_token=#{@user.tjb_auth_token}",
|
93
|
+
"http://1000jobboersen.de/administration/users/#{@contact.tjb_id}.xml?auth_token=#{@user.tjb_auth_token}",
|
63
94
|
:status => '500')
|
64
|
-
contact = Contact.find(contact.id)
|
65
|
-
contact.update_attributes :first_name => 'test'
|
66
|
-
assert contact.valid?
|
95
|
+
@contact = Contact.find(@contact.id)
|
96
|
+
@contact.update_attributes :first_name => 'test'
|
97
|
+
assert @contact.valid?
|
67
98
|
end
|
68
99
|
end
|
69
100
|
|
70
101
|
context 'when the contact does not exist in 1000jobboersen' do
|
71
102
|
setup do
|
72
103
|
FakeWeb.register_uri(:post,
|
73
|
-
"http://1000jobboersen.de/administration/
|
104
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
74
105
|
:status => '500')
|
75
|
-
@contact
|
76
|
-
:email => 'mattbeedle@googlemail.com', :user => @user
|
106
|
+
@contact.save!
|
77
107
|
end
|
78
108
|
|
79
109
|
should 'create the contact (user) in 1000jobboersen' do
|
80
110
|
FakeWeb.register_uri(:post,
|
81
|
-
"http://1000jobboersen.de/administration/
|
111
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
82
112
|
:body => File.read('test/support/contact_create_success.xml'))
|
83
113
|
assert @contact.tjb_id.blank?
|
84
114
|
@contact.update_attributes :first_name => 'someone'
|
85
115
|
assert_equal '4b8ead6a24d8f247be001073', @contact.tjb_id
|
86
116
|
end
|
117
|
+
|
118
|
+
context 'when the contact does not have an account' do
|
119
|
+
setup do
|
120
|
+
@contact.account = nil
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'not attempt to create the user in 1000jobboersen' do
|
124
|
+
FakeWeb.register_uri(:post,
|
125
|
+
"http://1000jobboersen.de/administration/users.xml?auth_token=#{@user.tjb_auth_token}",
|
126
|
+
:body => File.read('test/support/contact_create_success.xml'))
|
127
|
+
@contact.save!
|
128
|
+
assert @contact.tjb_id.blank?
|
129
|
+
end
|
130
|
+
end
|
87
131
|
end
|
88
132
|
end
|
89
133
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-02 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|