activity_consumer 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +15 -0
  5. data/app/assets/images/activity_consumer/cross.png +0 -0
  6. data/app/assets/images/activity_consumer/tick.png +0 -0
  7. data/app/assets/javascripts/activity_consumer/application.js +15 -0
  8. data/app/assets/stylesheets/activity_consumer/application.scss +43 -0
  9. data/app/assets/stylesheets/activity_consumer/table.scss +10 -0
  10. data/app/controllers/activity_consumer/application_controller.rb +3 -0
  11. data/app/controllers/activity_consumer/remote_activities_controller.rb +63 -0
  12. data/app/helpers/activity_consumer/application_helper.rb +4 -0
  13. data/app/models/activity_consumer/remote_activity.rb +21 -0
  14. data/app/services/activity_consumer/configuration.rb +24 -0
  15. data/app/services/activity_consumer/remote_activity_importer.rb +40 -0
  16. data/app/services/activity_consumer/remote_activity_rest_client.rb +77 -0
  17. data/app/views/activity_consumer/remote_activities/index.html.erb +32 -0
  18. data/app/views/activity_consumer/remote_activities/show.html.erb +37 -0
  19. data/app/views/layouts/activity_consumer/application.html.erb +17 -0
  20. data/config/locales/de.yml +18 -0
  21. data/config/routes.rb +9 -0
  22. data/db/migrate/20130725170303_create_activity_consumer_remote_activities.rb +16 -0
  23. data/db/migrate/20130817171648_add_etag_to_remote_activities.rb +5 -0
  24. data/lib/activity_consumer/engine.rb +13 -0
  25. data/lib/activity_consumer/version.rb +3 -0
  26. data/lib/activity_consumer.rb +26 -0
  27. data/lib/tasks/activity_consumer_tasks.rake +4 -0
  28. data/spec/controllers/activity_consumer/remote_activities_controller_spec.rb +72 -0
  29. data/spec/dummy/README.rdoc +261 -0
  30. data/spec/dummy/Rakefile +7 -0
  31. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  32. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/config/application.rb +67 -0
  37. data/spec/dummy/config/boot.rb +10 -0
  38. data/spec/dummy/config/database.yml +25 -0
  39. data/spec/dummy/config/environment.rb +5 -0
  40. data/spec/dummy/config/environments/development.rb +37 -0
  41. data/spec/dummy/config/environments/production.rb +67 -0
  42. data/spec/dummy/config/environments/test.rb +37 -0
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/dummy/config/initializers/inflections.rb +15 -0
  45. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  46. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  47. data/spec/dummy/config/initializers/session_store.rb +8 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  49. data/spec/dummy/config/locales/en.yml +5 -0
  50. data/spec/dummy/config/routes.rb +4 -0
  51. data/spec/dummy/config.ru +4 -0
  52. data/spec/dummy/db/development.sqlite3 +0 -0
  53. data/spec/dummy/db/schema.rb +28 -0
  54. data/spec/dummy/db/test.sqlite3 +0 -0
  55. data/spec/dummy/log/development.log +295 -0
  56. data/spec/dummy/log/test.log +45193 -0
  57. data/spec/dummy/public/404.html +26 -0
  58. data/spec/dummy/public/422.html +26 -0
  59. data/spec/dummy/public/500.html +25 -0
  60. data/spec/dummy/public/favicon.ico +0 -0
  61. data/spec/dummy/script/rails +6 -0
  62. data/spec/dummy/tmp/cache/assets/CB9/640/sprockets%2F055df7094ed3c73903db121ec7947478 +0 -0
  63. data/spec/dummy/tmp/cache/assets/CDD/880/sprockets%2F0994815802d4bd56bf29a9c53bab6520 +0 -0
  64. data/spec/dummy/tmp/cache/assets/CEF/070/sprockets%2F833e7786517acf485f377186a1eb1ea6 +0 -0
  65. data/spec/dummy/tmp/cache/assets/CF3/F30/sprockets%2Fc0fff716a78291e8e6e3659a50b59824 +0 -0
  66. data/spec/dummy/tmp/cache/assets/D26/790/sprockets%2F4928ff8fb0382efb99f6362f4f1e2831 +0 -0
  67. data/spec/dummy/tmp/cache/assets/D26/A70/sprockets%2Fe8aae21d8889a7c4473672ff0c5396e7 +0 -0
  68. data/spec/dummy/tmp/cache/assets/DA5/890/sprockets%2F849c2c9c50783eb3f65bc4b2d5feb0e6 +0 -0
  69. data/spec/dummy/tmp/cache/assets/DCB/E30/sprockets%2F9c1335eaffea6e3a58425adc4c28a35f +0 -0
  70. data/spec/dummy/tmp/cache/assets/DD8/8A0/sprockets%2Ffb4d7aea2f81d5c9837b9e02586f1acf +0 -0
  71. data/spec/dummy/tmp/cache/assets/E3F/5B0/sprockets%2Fc4ab6ddfbe50dfb200e08f2ad0b21e1f +0 -0
  72. data/spec/fixtures/vcr_cassettes/activities-controller.yml +36 -0
  73. data/spec/fixtures/vcr_cassettes/activities-delta.yml +36 -0
  74. data/spec/fixtures/vcr_cassettes/activities-etag-abc123.yml +40 -0
  75. data/spec/fixtures/vcr_cassettes/activities-etag-def456.yml +40 -0
  76. data/spec/fixtures/vcr_cassettes/activities-etag-xyz789.yml +36 -0
  77. data/spec/fixtures/vcr_cassettes/activities-foo-and-bar.yml +38 -0
  78. data/spec/fixtures/vcr_cassettes/activities-foo.yml +36 -0
  79. data/spec/fixtures/vcr_cassettes/activities.yml +36 -0
  80. data/spec/fixtures/vcr_cassettes/unknown-activities.yml +36 -0
  81. data/spec/models/activity_consumer/remote_activity_spec.rb +22 -0
  82. data/spec/services/activity_consumer/configuration_spec.rb +17 -0
  83. data/spec/services/activity_consumer/remote_activity_importer_spec.rb +121 -0
  84. data/spec/services/activity_consumer/remote_activity_rest_client_spec.rb +157 -0
  85. data/spec/spec_helper.rb +23 -0
  86. metadata +312 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"4072b6370a0e53d89e0321f855af2a21"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - 655f16c5e6000e7d73b933b81e648126
27
+ X-Runtime:
28
+ - '0.009323'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-09T10:51:15+02:00","activity_type":"Foo","payload":{}},{"action":"update","timestamp":"2013-06-09T10:51:26+02:00","activity_type":"Foo","payload":{}},{"action":"destroy","timestamp":"2013-06-09T10:51:30+02:00","activity_type":"Foo","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Sun, 09 Jun 2013 09:01:35 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json?since=2013-06-12T20:00:00%2002:00
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"6614e547c7951a51573f018180488b91"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - ea26017460320b813fecdd6890ff2c01
27
+ X-Runtime:
28
+ - '0.008383'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-12T20:03:00+02:00","activity_type":"Foo","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Wed, 12 Jun 2013 19:49:32 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ If-None-Match:
11
+ - ! '"abc123"'
12
+ response:
13
+ status:
14
+ code: 304
15
+ message: Not Modified
16
+ headers:
17
+ Etag:
18
+ - ! '"abc123"'
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ X-Meta-Request-Version:
24
+ - 0.2.2
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ X-Request-Id:
28
+ - 44ea316e53b3f25ed60eb634a291b7ab
29
+ X-Runtime:
30
+ - '0.690518'
31
+ Date:
32
+ - Mon, 19 Aug 2013 14:43:06 GMT
33
+ Connection:
34
+ - close
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ http_version:
39
+ recorded_at: Mon, 19 Aug 2013 14:43:06 GMT
40
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ If-None-Match:
11
+ - ! '"abc123"'
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Etag:
18
+ - ! '"def456"'
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ X-Meta-Request-Version:
24
+ - 0.2.2
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ X-Request-Id:
28
+ - 44ea316e53b3f25ed60eb634a291b7ab
29
+ X-Runtime:
30
+ - '0.690518'
31
+ Date:
32
+ - Mon, 19 Aug 2013 14:43:06 GMT
33
+ Connection:
34
+ - close
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ''
38
+ http_version:
39
+ recorded_at: Mon, 19 Aug 2013 14:43:06 GMT
40
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"xyz789"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - 655f16c5e6000e7d73b933b81e648126
27
+ X-Runtime:
28
+ - '0.009323'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-09T10:51:15+02:00","activity_type":"Foo","payload":{}},{"action":"update","timestamp":"2013-06-09T10:51:26+02:00","activity_type":"Foo","payload":{}},{"action":"destroy","timestamp":"2013-06-09T10:51:30+02:00","activity_type":"Foo","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Sun, 09 Jun 2013 09:01:35 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"86f06a84b88c7173a711a488573dcb16"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - cdb61a1cbaf91c0b3648a796fd978f0d
27
+ X-Runtime:
28
+ - '0.078328'
29
+ Date:
30
+ - Thu, 15 Aug 2013 16:48:56 GMT
31
+ Connection:
32
+ - close
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-07-22T21:50:42+02:00","activity_type":"Foo","payload":{}},{"action":"create","timestamp":"2013-07-22T21:50:42+02:00","activity_type":"Foo","payload":{}},{"action":"create","timestamp":"2013-08-15T18:19:52+02:00","activity_type":"Bar","payload":{}}]}'
36
+ http_version:
37
+ recorded_at: Thu, 15 Aug 2013 16:48:56 GMT
38
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"4072b6370a0e53d89e0321f855af2a21"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - 655f16c5e6000e7d73b933b81e648126
27
+ X-Runtime:
28
+ - '0.009323'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-09T10:51:15+02:00","activity_type":"Foo","payload":{}},{"action":"update","timestamp":"2013-06-09T10:51:26+02:00","activity_type":"Foo","payload":{}},{"action":"destroy","timestamp":"2013-06-09T10:51:30+02:00","activity_type":"Foo","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Sun, 09 Jun 2013 09:01:35 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"4072b6370a0e53d89e0321f855af2a21"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - 655f16c5e6000e7d73b933b81e648126
27
+ X-Runtime:
28
+ - '0.009323'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-09T10:51:15+02:00","activity_type":"Foo","payload":{}},{"action":"update","timestamp":"2013-06-09T10:51:26+02:00","activity_type":"Foo","payload":{}},{"action":"destroy","timestamp":"2013-06-09T10:51:30+02:00","activity_type":"Foo","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Sun, 09 Jun 2013 09:01:35 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://user:secret@inoxio-cim.dev/activities.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Content-Type:
16
+ - application/json; charset=utf-8
17
+ X-Meta-Request-Version:
18
+ - 0.2.2
19
+ X-Ua-Compatible:
20
+ - IE=Edge
21
+ Etag:
22
+ - ! '"4072b6370a0e53d89e0321f855af2a21"'
23
+ Cache-Control:
24
+ - max-age=0, private, must-revalidate
25
+ X-Request-Id:
26
+ - 655f16c5e6000e7d73b933b81e648126
27
+ X-Runtime:
28
+ - '0.009323'
29
+ Connection:
30
+ - close
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"activities":[{"action":"create","timestamp":"2013-06-09T10:51:15+02:00","activity_type":"Unknown","payload":{}}]}'
34
+ http_version:
35
+ recorded_at: Sun, 09 Jun 2013 09:01:35 GMT
36
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ class RemoteMyTestActivity < ActivityConsumer::RemoteActivity
4
+ end
5
+
6
+ module ActivityConsumer
7
+ describe RemoteActivity do
8
+
9
+ it "knows the last import timestamp" do
10
+ RemoteMyTestActivity.create(timestamp: Time.parse('2013-09-25T12:00:00+0200'), action: 'create', payload: {})
11
+ RemoteMyTestActivity.create(timestamp: Time.parse('2013-09-24T14:00:00+0200'), action: 'create', payload: {})
12
+
13
+ ActivityConsumer::RemoteActivity.latest_timestamp.should == Time.parse('2013-09-25T12:00:00+02:00').iso8601
14
+ end
15
+
16
+ it "has a short type" do
17
+ a = RemoteMyTestActivity.create(timestamp: Time.parse('2013-09-25T12:00:00+0200'), action: 'create', payload: {})
18
+ a.short_type.should == "my_test"
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module ActivityConsumer
4
+
5
+ describe Configuration do
6
+
7
+ it "remote activity importer uses configuration" do
8
+ ActivityConsumer.configure do |c|
9
+ c.activity_uri = 'http://example.com/my.xml'
10
+ end
11
+
12
+ ActivityConsumer::RemoteActivityRestClient.new.send(:request_url).should == 'http://example.com/my.xml'
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ # stub implementation of a RemoteActivity sub-class
4
+ class RemoteFooActivity < ActivityConsumer::RemoteActivity
5
+ end
6
+
7
+ module ActivityConsumer
8
+
9
+ describe RemoteActivityImporter do
10
+
11
+ before(:each) do
12
+ ActivityConsumer.configure do |c|
13
+ c.activity_uri = 'http://inoxio-cim.dev/activities.json'
14
+ c.import_types = ['Foo']
15
+ end
16
+ end
17
+
18
+ after(:each) do
19
+ VCR.eject_cassette
20
+ WebMock.reset!
21
+ end
22
+
23
+ describe "#import" do
24
+ let(:importer) {ActivityConsumer::RemoteActivityImporter.new(:delta)}
25
+
26
+ it "imports all activities" do
27
+ a1 = RemoteFooActivity.new(action: 'create', timestamp: Time.now)
28
+ a2 = RemoteFooActivity.new(action: 'update', timestamp: Time.now)
29
+ importer.stub(:activities).and_return([a1,a2])
30
+
31
+ a1.should_receive(:import!).once
32
+ a2.should_receive(:import!).once
33
+
34
+ importer.import
35
+ end
36
+
37
+ it "marks unsuccessful imports" do
38
+ a1 = RemoteFooActivity.new(action: 'create', timestamp: Time.now)
39
+ a2 = RemoteFooActivity.new(action: 'update', timestamp: Time.now)
40
+ importer.stub(:activities).and_return([a1,a2])
41
+
42
+ a1.should_receive(:import!).once
43
+ a2.should_receive(:import!).and_raise(RuntimeError.new("If this happens, call Batman!"))
44
+
45
+ importer.import
46
+
47
+ a1.reload
48
+ a1.was_successful.should == true
49
+ a2.reload
50
+ a2.was_successful.should == false
51
+ a2.error.should == "If this happens, call Batman!"
52
+ end
53
+
54
+ it "returns stats about imported activities" do
55
+ a1 = RemoteFooActivity.new(action: 'create', timestamp: Time.now)
56
+ a2 = RemoteFooActivity.new(action: 'update', timestamp: Time.now)
57
+ a3 = RemoteFooActivity.new(action: 'destroy', timestamp: Time.now)
58
+ a4 = RemoteFooActivity.new(action: 'create', timestamp: Time.now)
59
+ importer.stub(:activities).and_return([a1, a2, a3, a4])
60
+
61
+ a1.should_receive(:import!).once
62
+ a2.should_receive(:import!).once
63
+ a4.should_receive(:import!).and_raise(RuntimeError)
64
+ a3.should_receive(:import!).once
65
+
66
+ stats = importer.import
67
+
68
+ stats[:no_activities].should == 3
69
+ stats[:no_errors].should == 1
70
+
71
+ stats[:activities][:foo][:create].should == 1
72
+ stats[:activities][:foo][:update].should == 1
73
+ stats[:activities][:foo][:destroy].should == 1
74
+ end
75
+
76
+ it "the stats hash has no default" do
77
+ a1 = RemoteFooActivity.new(action: 'create', timestamp: Time.now)
78
+ importer.stub(:activities).and_return([a1])
79
+
80
+ a1.should_receive(:import!).once
81
+
82
+ stats = importer.import
83
+ stats[:no_activities].should == 1
84
+ stats[:xyz].should == nil
85
+ end
86
+
87
+ it "saves the latest etag" do
88
+ VCR.insert_cassette 'activities-etag-xyz789'
89
+ importer.import
90
+ RemoteActivity.last.etag.should == '"xyz789"'
91
+ end
92
+
93
+ end
94
+
95
+ describe "#activities" do
96
+
97
+ context "on delta" do
98
+ let(:importer) {ActivityConsumer::RemoteActivityImporter.new(:delta)}
99
+
100
+ it "gets the correct set of activities from rest client" do
101
+ ActivityConsumer::RemoteActivityRestClient.any_instance.should_receive(:fetch)
102
+ importer.send(:activities)
103
+ end
104
+ end
105
+
106
+ context "on delta" do
107
+ let(:importer) {ActivityConsumer::RemoteActivityImporter.new(:initial)}
108
+
109
+ it "gets the correct set of activities from rest client" do
110
+ ActivityConsumer::RemoteActivityRestClient.any_instance.should_receive(:fetch)
111
+ importer.send(:activities)
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+