remote_partial 0.0.1
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/MIT-LICENSE +20 -0
- data/README.rdoc +63 -0
- data/Rakefile +40 -0
- data/app/helpers/remote_partial/application_helper.rb +4 -0
- data/app/helpers/remote_partial/host_app_helper.rb +11 -0
- data/app/models/remote_partial/builder.rb +30 -0
- data/app/models/remote_partial/exceptions.rb +24 -0
- data/app/models/remote_partial/partial.rb +57 -0
- data/app/models/remote_partial/resource_manager.rb +66 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20130702072157_create_remote_partial_partials.rb +12 -0
- data/lib/remote_partial/engine.rb +11 -0
- data/lib/remote_partial/version.rb +3 -0
- data/lib/remote_partial.rb +23 -0
- data/lib/tasks/remote_partial_tasks.rake +10 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/demos.js +2 -0
- data/test/dummy/app/assets/javascripts/samples.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/demos.css +4 -0
- data/test/dummy/app/assets/stylesheets/samples.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/demos_controller.rb +18 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/demos_helper.rb +2 -0
- data/test/dummy/app/helpers/samples_helper.rb +2 -0
- data/test/dummy/app/views/demos/_clock.html.erb +6 -0
- data/test/dummy/app/views/demos/_fixed.html.erb +3 -0
- data/test/dummy/app/views/demos/_ruby.html.erb +4 -0
- data/test/dummy/app/views/demos/index.html.erb +7 -0
- data/test/dummy/app/views/demos/show.html.erb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/remote_partials/_clock.html.erb +1 -0
- data/test/dummy/app/views/remote_partials/_fixed.html.erb +2 -0
- data/test/dummy/app/views/remote_partials/_ruby.html.erb +11 -0
- data/test/dummy/app/views/remote_partials/_wcc.html.erb +810 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/remote_partial.rb +16 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +8 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130703141929_create_remote_partial_partials.remote_partial.rb +13 -0
- data/test/dummy/db/schema.rb +26 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +4200 -0
- data/test/dummy/log/test.log +1397 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/demos_controller_test.rb +20 -0
- data/test/dummy/test/unit/helpers/demos_helper_test.rb +13 -0
- data/test/dummy/test/unit/helpers/samples_helper_test.rb +4 -0
- data/test/dummy/tmp/cache/assets/BE9/0F0/sprockets%2Fb918d6cc641337193b96751002451244 +0 -0
- data/test/dummy/tmp/cache/assets/C2E/4E0/sprockets%2F5b29288e435665a224409e7d76530c95 +0 -0
- data/test/dummy/tmp/cache/assets/CB3/DC0/sprockets%2F157201713d2fd4954447e0bf4d8e853e +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE3/080/sprockets%2F7d4d7689d6fa8236f0b4848c03ba1215 +0 -0
- data/test/dummy/tmp/cache/assets/CE5/D30/sprockets%2F8c9834a63b25a66203918a75ff56e2ac +0 -0
- data/test/dummy/tmp/cache/assets/D16/E10/sprockets%2Fd5d9c442561ec08a55d5d843a0d9792d +0 -0
- data/test/dummy/tmp/cache/assets/D20/020/sprockets%2F488c2c97fede45c86a62f1aa14554957 +0 -0
- data/test/dummy/tmp/cache/assets/D2E/690/sprockets%2F840591ad233bc7bda28b7f6a2b27c205 +0 -0
- data/test/dummy/tmp/cache/assets/D30/990/sprockets%2F995cc20d042afc03241f58f7d6ca1f02 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D52/430/sprockets%2F6ada07f0c9869f9f35b05fa0988dc717 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/DBB/BE0/sprockets%2Fc6eb578d23a69b5abb056e3abaa5c060 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E02/FA0/sprockets%2Fca8d5771d03e669be1d96acb6beb6cb6 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/fixtures/remote_partial/partials.yml +10 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/remote_partial_test.rb +7 -0
- data/test/test_helper.rb +80 -0
- data/test/unit/remote_partial/builder_test.rb +113 -0
- data/test/unit/remote_partial/exception_test.rb +21 -0
- data/test/unit/remote_partial/partial_test.rb +66 -0
- data/test/unit/remote_partial/resource_manager_test.rb +76 -0
- data/test/unit/remote_partial_test.rb +26 -0
- metadata +291 -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,20 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DemosControllerTest < ActionController::TestCase
|
|
4
|
+
def test_index
|
|
5
|
+
get :index
|
|
6
|
+
assert_response :success
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_show_fixed
|
|
11
|
+
get :show, id: 'fixed'
|
|
12
|
+
assert_response :success
|
|
13
|
+
assert_match content_of('fixed'), response.body
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def content_of(remote_partial_name)
|
|
17
|
+
File.read(Rails.root + "app/views/remote_partials/_#{remote_partial_name}.html.erb")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'remote_partial/host_app_helper'
|
|
3
|
+
|
|
4
|
+
class DemosHelperTest < ActionView::TestCase
|
|
5
|
+
include RemotePartial::HostAppHelper
|
|
6
|
+
|
|
7
|
+
def test_render_remote_partial_with_no_partial
|
|
8
|
+
assert_raise ActionView::MissingTemplate do
|
|
9
|
+
render_remote_partial 'non-existent-partial'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6728
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
|
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
5
|
+
require "rails/test_help"
|
|
6
|
+
require 'webmock/test_unit'
|
|
7
|
+
|
|
8
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
9
|
+
|
|
10
|
+
# Load support files
|
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
12
|
+
|
|
13
|
+
# Load fixtures from the engine
|
|
14
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
|
15
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class ActiveSupport::TestCase
|
|
19
|
+
fixtures :all
|
|
20
|
+
|
|
21
|
+
def enable_mock(url, body = '<body><h1>Something</h1><p>Else</p></body>')
|
|
22
|
+
WebMock.enable!
|
|
23
|
+
stub_request(:get, url).
|
|
24
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
|
25
|
+
to_return(:status => 200, :body => body, :headers => {})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def enable_mock_connection_failure(url, status = 400)
|
|
29
|
+
WebMock.enable!
|
|
30
|
+
stub_request(:get, url).
|
|
31
|
+
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
|
|
32
|
+
to_return(:status => status, :body => 'Whoops!', :headers => {})
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def enable_mock_connection_error(url)
|
|
36
|
+
WebMock.enable!
|
|
37
|
+
stub_request(:get, url).to_raise(SocketError.new("Some connection error"))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def disable_mock
|
|
41
|
+
WebMock.disable!
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def assert_equal_ignoring_cr(expected, testing, comment = nil)
|
|
45
|
+
cr = "\n"
|
|
46
|
+
assert_equal(expected, testing.gsub(cr, ""), comment)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def remove_file(file_name)
|
|
50
|
+
File.delete(file_name) if File.exists?(file_name)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def assert_file_exists(file_name)
|
|
54
|
+
assert(File.exists?(file_name), "File should exist: #{file_name}")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def assert_file_does_not_exist(file_name)
|
|
58
|
+
assert(!File.exists?(file_name), "File should not exist: #{file_name}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def assert_output_file_updated(content = nil, &test)
|
|
63
|
+
remove_output_file
|
|
64
|
+
test.call
|
|
65
|
+
assert_file_exists @partial.output_file_name
|
|
66
|
+
assert_equal_ignoring_cr(content, File.read(@partial.output_file_name)) if content
|
|
67
|
+
remove_output_file
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def assert_output_file_not_updated(&test)
|
|
71
|
+
remove_output_file
|
|
72
|
+
test.call
|
|
73
|
+
assert_file_does_not_exist @partial.output_file_name
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def remove_output_file
|
|
77
|
+
remove_file @partial.output_file_name
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module RemotePartial
|
|
4
|
+
class BuilderTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@partial = Partial.find(1)
|
|
8
|
+
@name = 'foo'
|
|
9
|
+
@url = @partial.url
|
|
10
|
+
enable_mock @url
|
|
11
|
+
new_builder
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def teardown
|
|
15
|
+
disable_mock
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_create_or_update_partial
|
|
19
|
+
assert_difference 'RemotePartial::Partial.count' do
|
|
20
|
+
@builder.create_or_update_partial
|
|
21
|
+
end
|
|
22
|
+
assert_equal @name, Partial.last.name
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_create_or_update_partial_updates_if_partial_exists
|
|
26
|
+
test_create_or_update_partial
|
|
27
|
+
@url = 'other'
|
|
28
|
+
new_builder
|
|
29
|
+
assert_no_difference 'RemotePartial::Partial.count' do
|
|
30
|
+
@builder.create_or_update_partial
|
|
31
|
+
end
|
|
32
|
+
assert_equal @url, Partial.last.url
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_build
|
|
36
|
+
assert_expected_file_created do
|
|
37
|
+
assert_difference 'RemotePartial::Partial.count' do
|
|
38
|
+
Builder.build(
|
|
39
|
+
url: @url,
|
|
40
|
+
name: @name
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
assert_equal(@name, Partial.last.name)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_build_with_existing_stale_partial
|
|
48
|
+
assert(@partial.stale?, "Partial needs to be stale at start of test")
|
|
49
|
+
assert_output_file_updated do
|
|
50
|
+
assert_no_difference 'RemotePartial::Partial.count' do
|
|
51
|
+
Builder.build(
|
|
52
|
+
url: @partial.url,
|
|
53
|
+
name: @partial.name
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_build_with_existing_partial
|
|
60
|
+
@partial.update_stale_at
|
|
61
|
+
assert_output_file_not_updated do
|
|
62
|
+
assert_no_difference 'RemotePartial::Partial.count' do
|
|
63
|
+
Builder.build(
|
|
64
|
+
url: @partial.url,
|
|
65
|
+
name: @partial.name
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_build_with_http_error
|
|
72
|
+
enable_mock_connection_failure @url
|
|
73
|
+
assert_output_file_not_updated do
|
|
74
|
+
assert_no_difference 'RemotePartial::Partial.count' do
|
|
75
|
+
Builder.build(
|
|
76
|
+
url: @partial.url,
|
|
77
|
+
name: @partial.name
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_stale_at_not_modified_if_unable_to_retrieve
|
|
84
|
+
expected = @partial.stale_at
|
|
85
|
+
test_build_with_http_error
|
|
86
|
+
assert_equal(expected, @partial.reload.stale_at)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def assert_expected_file_created(&test)
|
|
90
|
+
remove_file expected_output_file_name
|
|
91
|
+
test.call
|
|
92
|
+
assert_file_exists expected_output_file_name
|
|
93
|
+
remove_file expected_output_file_name
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def assert_expected_file_not_created(&test)
|
|
97
|
+
remove_file @partial.output_file_name
|
|
98
|
+
test.call
|
|
99
|
+
assert_file_does_not_exist @partial.output_file_name
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def new_builder
|
|
103
|
+
@builder = Builder.new(
|
|
104
|
+
name: @name,
|
|
105
|
+
url: @url
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def expected_output_file_name
|
|
110
|
+
@expected_output_file_name ||= @partial.output_file_name.gsub(@partial.name, @name)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module RemotePartial
|
|
4
|
+
class ExceptionTest < ActiveSupport::TestCase
|
|
5
|
+
def test_remote_partial_retrival_error
|
|
6
|
+
inner_message = 'Whoops'
|
|
7
|
+
catch_exception { raise RemotePartialRetrivalError.new(inner_message, Array)}
|
|
8
|
+
assert_match("Unable to retrieve remote partial", @exception.message)
|
|
9
|
+
assert_match(inner_message, @exception.message)
|
|
10
|
+
assert_match('Array', @exception.message)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def catch_exception(&process)
|
|
14
|
+
begin
|
|
15
|
+
process.call
|
|
16
|
+
rescue => e
|
|
17
|
+
@exception = e
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module RemotePartial
|
|
4
|
+
class PartialTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@partial = Partial.find(1)
|
|
8
|
+
@first_p = '<p>One</p>'
|
|
9
|
+
@body = "<body><h1>Foo</h1><div>#{@first_p}<p>Bar</p></div></body>"
|
|
10
|
+
enable_mock(@partial.url, @body)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
disable_mock
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_output_file_name
|
|
18
|
+
expected = "#{RemotePartial.partial_location}/_#{@partial.name}.html.erb"
|
|
19
|
+
assert_equal expected, @partial.output_file_name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_update_file
|
|
23
|
+
assert_output_file_updated(@first_p) do
|
|
24
|
+
@partial.update_file
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_update_stale_at
|
|
30
|
+
@partial.update_stale_at
|
|
31
|
+
expected = @partial.updated_at + @partial.repeat_period
|
|
32
|
+
assert_equal expected.to_s(:db), @partial.stale_at.to_s(:db)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_stale_at_not_updated_unless_stale
|
|
36
|
+
test_update_stale_at
|
|
37
|
+
before = @partial.stale_at
|
|
38
|
+
@partial.update_stale_at
|
|
39
|
+
assert_equal before, @partial.stale_at
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_stale_at_reset_if_stale
|
|
43
|
+
@partial.stale_at = 1.hour.ago
|
|
44
|
+
test_update_stale_at
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_update_stale_file
|
|
48
|
+
assert_output_file_updated(@first_p) do
|
|
49
|
+
@partial.update_stale_file
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_update_stale_file_when_not_stale
|
|
54
|
+
test_update_stale_at
|
|
55
|
+
assert_output_file_not_updated do
|
|
56
|
+
@partial.update_stale_file
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_update_file_not_affected_by_stale_state
|
|
61
|
+
test_update_stale_at
|
|
62
|
+
test_update_file
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
|
|
5
|
+
module RemotePartial
|
|
6
|
+
class ResourceManagerTest < ActiveSupport::TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@url = "http://www.worcestershire.gov.uk"
|
|
10
|
+
@body = "<body><p>One</p><h1>Foo</h1><p>Bar</p></body>"
|
|
11
|
+
enable_mock(@url, @body)
|
|
12
|
+
@path = 'temp/file.text'
|
|
13
|
+
File.delete(@path) if File.exists?(@path)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def teardown
|
|
17
|
+
disable_mock
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_stub
|
|
21
|
+
assert_equal_ignoring_cr(@body, content.search('body').to_s)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_get_page
|
|
25
|
+
assert_equal(content.to_s, ResourceManager.get_page(@url).to_s)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_get_raw
|
|
29
|
+
raw = Net::HTTP.get(URI(@url))
|
|
30
|
+
assert_equal raw, ResourceManager.get_raw(@url)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_html
|
|
34
|
+
resource_manager = ResourceManager.new(@url)
|
|
35
|
+
assert_equal content.to_s, resource_manager.html
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_html_with_limit
|
|
39
|
+
@resource_manager = ResourceManager.new(@url, 'body')
|
|
40
|
+
assert_equal_ignoring_cr @body, @resource_manager.html
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_html_with_limit_that_returns_multiple_matches
|
|
44
|
+
expected = '<p>One</p><p>Bar</p>'
|
|
45
|
+
resource_manager = ResourceManager.new(@url, 'p')
|
|
46
|
+
assert_equal_ignoring_cr expected, resource_manager.html
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_output_to
|
|
50
|
+
test_html_with_limit
|
|
51
|
+
@resource_manager.output_to(@path)
|
|
52
|
+
assert_equal_ignoring_cr(@body, File.read(@path))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_connection_failure
|
|
56
|
+
enable_mock_connection_failure @url
|
|
57
|
+
assert_raise RemotePartialRetrivalError do
|
|
58
|
+
ResourceManager.new(@url, 'body').html
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_connection_failure_due_to_invalid_url
|
|
63
|
+
enable_mock_connection_error @url
|
|
64
|
+
assert_raise RemotePartialRetrivalError do
|
|
65
|
+
ResourceManager.new(@url, 'body').html
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def content
|
|
70
|
+
Nokogiri::HTML(Net::HTTP.get(URI(@url)))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RemotePartialTest < ActiveSupport::TestCase
|
|
4
|
+
def test_define
|
|
5
|
+
assert_difference 'RemotePartial::Partial.count' do
|
|
6
|
+
RemotePartial.define(
|
|
7
|
+
url: 'http://www.warwickshire.gov.uk',
|
|
8
|
+
name: 'wcc'
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
assert_equal('wcc', RemotePartial::Partial.last.name)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_partial_location
|
|
15
|
+
expected = File.expand_path('../../dummy/app/views/remote_partials', __FILE__)
|
|
16
|
+
assert_equal expected, RemotePartial.partial_location
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_set_partial_location
|
|
20
|
+
location = '/tmp'
|
|
21
|
+
RemotePartial.partial_location = location
|
|
22
|
+
assert_equal location, RemotePartial.partial_location
|
|
23
|
+
RemotePartial.partial_location = nil
|
|
24
|
+
test_partial_location
|
|
25
|
+
end
|
|
26
|
+
end
|