remote_partial 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -18,7 +18,6 @@ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
18
18
  end
19
19
 
20
20
  class ActiveSupport::TestCase
21
- fixtures :all
22
21
 
23
22
  def enable_mock(url, body = '<body><h1>Something</h1><p>Else</p></body>')
24
23
  stub_request(:get, url).
@@ -4,18 +4,27 @@ module RemotePartial
4
4
  class BuilderTest < ActiveSupport::TestCase
5
5
 
6
6
  def setup
7
- @partial = Partial.find(1)
7
+ @partial = Partial.create(
8
+ name: 'simple',
9
+ url: 'http://www.warwickshire.gov.uk',
10
+ criteria: 'p:first-child',
11
+ repeat_period: 10.minutes
12
+ )
8
13
  @name = 'foo'
9
14
  @url = @partial.url
10
15
  enable_mock @url
11
16
  new_builder
12
17
  end
13
18
 
19
+ def teardown
20
+ File.delete(Partial.file) if File.exists?(Partial.file)
21
+ end
22
+
14
23
  def test_create_or_update_partial
15
24
  assert_difference 'RemotePartial::Partial.count' do
16
25
  @builder.create_or_update_partial
17
26
  end
18
- assert_equal @name, Partial.last.name
27
+ assert Partial.find @name
19
28
  end
20
29
 
21
30
  def test_create_or_update_partial_updates_if_partial_exists
@@ -25,7 +34,7 @@ module RemotePartial
25
34
  assert_no_difference 'RemotePartial::Partial.count' do
26
35
  @builder.create_or_update_partial
27
36
  end
28
- assert_equal @url, Partial.last.url
37
+ assert_equal @url, Partial.find(@name).url
29
38
  end
30
39
 
31
40
  def test_build
@@ -36,12 +45,12 @@ module RemotePartial
36
45
  name: @name
37
46
  )
38
47
  end
39
- assert_equal(@name, Partial.last.name)
48
+ assert_equal(@name, Partial.find(@name).name)
40
49
  end
41
50
  end
42
51
 
43
52
  def test_build_with_existing_stale_partial
44
- assert(@partial.stale?, "Partial needs to be stale at start of test")
53
+ assert(@partial.stale?, "Partial should be stale at start of test")
45
54
  assert_output_file_updated do
46
55
  assert_no_difference 'RemotePartial::Partial.count' do
47
56
  Builder.build(
@@ -54,6 +63,7 @@ module RemotePartial
54
63
 
55
64
  def test_build_with_existing_partial
56
65
  @partial.update_stale_at
66
+ partial = Partial.find(@partial.name)
57
67
  assert_output_file_not_updated do
58
68
  assert_no_difference 'RemotePartial::Partial.count' do
59
69
  Builder.build(
@@ -79,7 +89,7 @@ module RemotePartial
79
89
  def test_stale_at_not_modified_if_unable_to_retrieve
80
90
  expected = @partial.stale_at
81
91
  test_build_with_http_error
82
- assert_equal(expected, @partial.reload.stale_at)
92
+ assert_equal(expected, Partial.find(@partial.name).stale_at)
83
93
  end
84
94
 
85
95
  def assert_expected_file_created(&test)
@@ -103,7 +113,7 @@ module RemotePartial
103
113
  end
104
114
 
105
115
  def expected_output_file_name
106
- @expected_output_file_name ||= @partial.output_file_name.gsub(@partial.name, @name)
116
+ @expected_output_file_name ||= @partial.output_file_name.gsub(@partial.name.to_s, @name)
107
117
  end
108
118
  end
109
119
  end
@@ -4,12 +4,21 @@ module RemotePartial
4
4
  class PartialTest < ActiveSupport::TestCase
5
5
 
6
6
  def setup
7
- @partial = Partial.find(1)
7
+ @partial = Partial.create(
8
+ name: :simple,
9
+ url: 'http://www.warwickshire.gov.uk',
10
+ criteria: 'p:first-child',
11
+ repeat_period: 10.minutes
12
+ )
8
13
  @first_p = '<p>One</p>'
9
14
  @body = "<body><h1>Foo</h1><div>#{@first_p}<p>Bar</p></div></body>"
10
15
  enable_mock(@partial.url, @body)
11
16
  end
12
17
 
18
+ def teardown
19
+ File.delete(Partial.file) if File.exists?(Partial.file)
20
+ end
21
+
13
22
  def test_output_file_name
14
23
  expected = "#{RemotePartial.partial_location}/_#{@partial.name}.html.erb"
15
24
  assert_equal expected, @partial.output_file_name
@@ -24,8 +33,20 @@ module RemotePartial
24
33
 
25
34
  def test_update_stale_at
26
35
  @partial.update_stale_at
27
- expected = @partial.updated_at + @partial.repeat_period
28
- assert_equal expected.to_s(:db), @partial.stale_at.to_s(:db)
36
+ @expected = @partial.updated_at + @partial.repeat_period
37
+ assert_equal @expected.to_s(:db), @partial.stale_at.to_s(:db)
38
+ end
39
+
40
+ def test_stale_at_gets_into_hash
41
+ test_update_stale_at
42
+ hash = @partial.to_hash
43
+ assert_equal @expected.to_s(:db), hash['stale_at'].to_s(:db)
44
+ end
45
+
46
+ def test_stale_at_gets_into_file
47
+ test_update_stale_at
48
+ partial = Partial.find(@partial.name)
49
+ assert_equal partial.stale_at, @partial.stale_at
29
50
  end
30
51
 
31
52
  def test_stale_at_not_updated_unless_stale
@@ -0,0 +1,136 @@
1
+ require 'test_helper'
2
+
3
+ module RemotePartial
4
+ class YamlStoreTest < ActiveSupport::TestCase
5
+
6
+ def teardown
7
+ File.delete(YamlStore.file) if File.exists?(YamlStore.file)
8
+ end
9
+
10
+ def test_root
11
+ assert_equal(fixture_path, YamlStore.root)
12
+ end
13
+
14
+ def test_file
15
+ expected = File.expand_path('remote_partial/yaml_stores.yml', fixture_path)
16
+ assert_equal(expected, YamlStore.file)
17
+ end
18
+
19
+ def test_dir
20
+ expected = File.expand_path('remote_partial', fixture_path)
21
+ assert_equal(expected, YamlStore.dir)
22
+ end
23
+
24
+ def test_write
25
+ assert !File.exists?(YamlStore.file), "File should not exist: #{YamlStore.file}"
26
+ @test = {'this' => {'foo' => 'bar'}}
27
+ YamlStore.write(@test)
28
+ assert File.exists?(YamlStore.file), "File should be found: #{YamlStore.file}"
29
+ end
30
+
31
+ def test_read
32
+ test_write
33
+ assert_equal @test, YamlStore.read
34
+ end
35
+
36
+ def test_read_when_no_file_exists
37
+ assert_equal({}, YamlStore.read)
38
+ end
39
+
40
+ def test_merge!
41
+ test_write
42
+ new_content = {'some' => {'thing' => 'else'}}
43
+ YamlStore.merge!({'some' => {'thing' => 'else'}})
44
+ assert_equal @test.merge(new_content), YamlStore.read
45
+ end
46
+
47
+ def test_new
48
+ name = 'Bob'
49
+ yaml_store = YamlStore.new(name: name)
50
+ assert_equal name, yaml_store.name
51
+ end
52
+
53
+ def test_save
54
+ hash = {name: 'Foo', colour:'Red'}
55
+ yaml_store = YamlStore.new(hash)
56
+ yaml_store.save
57
+ expected = {hash[:name] => {'colour' => hash[:colour]}.merge(yaml_store.time_stamps)}
58
+ assert_equal expected, YamlStore.read
59
+ end
60
+
61
+ def test_save_without_a_name
62
+ hash = {foo: 'bar'}
63
+ yaml_store = YamlStore.new(hash)
64
+ assert_raise RuntimeError do
65
+ yaml_store.save
66
+ end
67
+ end
68
+
69
+ def test_create
70
+ hash = {name: 'Foo', colour:'Red'}
71
+ yaml_store = YamlStore.create(hash)
72
+ expected = {hash[:name] => {'colour' => hash[:colour]}.merge(yaml_store.time_stamps)}
73
+ assert_equal expected, YamlStore.read
74
+ end
75
+
76
+ def test_find
77
+ @name = 'Foo'
78
+ @content = 'Bar'
79
+ YamlStore.create(name: @name, content: @content)
80
+ yaml_store = YamlStore.find(@name)
81
+ assert_equal @name, yaml_store.name
82
+ assert_equal @content, yaml_store.content
83
+ end
84
+
85
+ def test_find_when_none_exist
86
+ assert_nil YamlStore.find(:foo), "Should return nil if no match found"
87
+ end
88
+
89
+ def test_find_with_symbol
90
+ test_find
91
+ yaml_store = YamlStore.find(@name.to_sym)
92
+ assert_equal @name, yaml_store.name
93
+ assert_equal @content, yaml_store.content
94
+ end
95
+
96
+ def test_count
97
+ assert_equal 0, YamlStore.count
98
+ test_create
99
+ assert_equal 1, YamlStore.count
100
+ end
101
+
102
+ def test_created_at
103
+ yaml_store = YamlStore.create(name: 'foo')
104
+ assert yaml_store.created_at.kind_of?(Time), 'create_at should be a Time'
105
+ assert 1.minute.ago < yaml_store.created_at, 'created_at should be within the last minute'
106
+ end
107
+
108
+ def test_created_at_not_updated_if_exists
109
+ time = 1.day.ago
110
+ yaml_store = YamlStore.create(name: 'foo', created_at: time)
111
+ assert_equal(time, yaml_store.created_at)
112
+ end
113
+
114
+ def test_updated_at
115
+ yaml_store = YamlStore.create(name: 'foo')
116
+ assert yaml_store.updated_at.kind_of?(Time), 'updated_at should be a Time'
117
+ assert 1.minute.ago < yaml_store.updated_at, 'updated_at should be within the last minute'
118
+ end
119
+
120
+ def test_updated_at_if_updated_if_exists
121
+ time = 1.day.ago
122
+ yaml_store = YamlStore.create(name: 'foo', updated_at: time)
123
+ assert 1.minute.ago < yaml_store.updated_at, 'updated_at should be within the last minute'
124
+ end
125
+
126
+ def test_string_keys
127
+ sample = {:this => 'that', 'foo' => 'bar'}
128
+ expected = {'this' => 'that', 'foo' => 'bar'}
129
+ assert_equal(expected, YamlStore.string_keys(sample))
130
+ end
131
+
132
+ def fixture_path
133
+ File.expand_path('../../dummy/test/fixtures', File.dirname(__FILE__))
134
+ end
135
+ end
136
+ end
@@ -1,14 +1,33 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RemotePartialTest < ActiveSupport::TestCase
4
+
5
+ def teardown
6
+ File.delete(RemotePartial::Partial.file) if File.exists?(RemotePartial::Partial.file)
7
+ end
8
+
9
+ def test_define_with_string_keys
10
+ url = 'http://www.warwickshire.gov.uk'
11
+ name = 'wcc'
12
+ assert_difference 'RemotePartial::Partial.count' do
13
+ RemotePartial.define(
14
+ 'url' => url,
15
+ 'name' => name
16
+ )
17
+ end
18
+ assert_equal(url, RemotePartial::Partial.find(name).url)
19
+ end
20
+
4
21
  def test_define
22
+ url = 'http://www.warwickshire.gov.uk'
23
+ name = 'wcc'
5
24
  assert_difference 'RemotePartial::Partial.count' do
6
25
  RemotePartial.define(
7
- url: 'http://www.warwickshire.gov.uk',
8
- name: 'wcc'
26
+ url: url,
27
+ name: name
9
28
  )
10
29
  end
11
- assert_equal('wcc', RemotePartial::Partial.last.name)
30
+ assert_equal(url, RemotePartial::Partial.find(name).url)
12
31
  end
13
32
 
14
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_partial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-09 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: sqlite3
47
+ name: hashie
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :development
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
@@ -74,6 +74,7 @@ files:
74
74
  - app/models/remote_partial/exceptions.rb
75
75
  - app/models/remote_partial/partial.rb
76
76
  - app/models/remote_partial/builder.rb
77
+ - app/models/remote_partial/yaml_store.rb
77
78
  - config/routes.rb
78
79
  - db/migrate/20130702072157_create_remote_partial_partials.rb
79
80
  - lib/remote_partial/version.rb
@@ -83,7 +84,6 @@ files:
83
84
  - MIT-LICENSE
84
85
  - Rakefile
85
86
  - README.rdoc
86
- - test/integration/navigation_test.rb
87
87
  - test/dummy/app/helpers/samples_helper.rb
88
88
  - test/dummy/app/helpers/application_helper.rb
89
89
  - test/dummy/app/helpers/demos_helper.rb
@@ -108,9 +108,9 @@ files:
108
108
  - test/dummy/log/test.log
109
109
  - test/dummy/log/development.log
110
110
  - test/dummy/db/migrate/20130703141929_create_remote_partial_partials.remote_partial.rb
111
+ - test/dummy/db/remote_partial/partials.yml
111
112
  - test/dummy/db/test.sqlite3
112
113
  - test/dummy/db/development.sqlite3
113
- - test/dummy/db/schema.rb
114
114
  - test/dummy/config.ru
115
115
  - test/dummy/public/422.html
116
116
  - test/dummy/public/favicon.ico
@@ -145,7 +145,6 @@ files:
145
145
  - test/dummy/config/environments/development.rb
146
146
  - test/dummy/config/environments/production.rb
147
147
  - test/dummy/config/environments/test.rb
148
- - test/dummy/config/database.yml
149
148
  - test/dummy/config/initializers/inflections.rb
150
149
  - test/dummy/config/initializers/session_store.rb
151
150
  - test/dummy/config/initializers/wrap_parameters.rb
@@ -156,11 +155,11 @@ files:
156
155
  - test/dummy/config/application.rb
157
156
  - test/dummy/script/rails
158
157
  - test/remote_partial_test.rb
159
- - test/fixtures/remote_partial/partials.yml
160
158
  - test/test_helper.rb
161
159
  - test/unit/remote_partial/partial_test.rb
162
160
  - test/unit/remote_partial/builder_test.rb
163
161
  - test/unit/remote_partial/exception_test.rb
162
+ - test/unit/remote_partial/yaml_store_test.rb
164
163
  - test/unit/remote_partial/resource_manager_test.rb
165
164
  - test/unit/remote_partial_test.rb
166
165
  homepage: https://github.com/warwickshire/remote_partial
@@ -189,7 +188,6 @@ specification_version: 3
189
188
  summary: RemotePartial adds the facility to grab content from remote sites and add
190
189
  them as partials to the host app.
191
190
  test_files:
192
- - test/integration/navigation_test.rb
193
191
  - test/dummy/app/helpers/samples_helper.rb
194
192
  - test/dummy/app/helpers/application_helper.rb
195
193
  - test/dummy/app/helpers/demos_helper.rb
@@ -214,9 +212,9 @@ test_files:
214
212
  - test/dummy/log/test.log
215
213
  - test/dummy/log/development.log
216
214
  - test/dummy/db/migrate/20130703141929_create_remote_partial_partials.remote_partial.rb
215
+ - test/dummy/db/remote_partial/partials.yml
217
216
  - test/dummy/db/test.sqlite3
218
217
  - test/dummy/db/development.sqlite3
219
- - test/dummy/db/schema.rb
220
218
  - test/dummy/config.ru
221
219
  - test/dummy/public/422.html
222
220
  - test/dummy/public/favicon.ico
@@ -251,7 +249,6 @@ test_files:
251
249
  - test/dummy/config/environments/development.rb
252
250
  - test/dummy/config/environments/production.rb
253
251
  - test/dummy/config/environments/test.rb
254
- - test/dummy/config/database.yml
255
252
  - test/dummy/config/initializers/inflections.rb
256
253
  - test/dummy/config/initializers/session_store.rb
257
254
  - test/dummy/config/initializers/wrap_parameters.rb
@@ -262,10 +259,10 @@ test_files:
262
259
  - test/dummy/config/application.rb
263
260
  - test/dummy/script/rails
264
261
  - test/remote_partial_test.rb
265
- - test/fixtures/remote_partial/partials.yml
266
262
  - test/test_helper.rb
267
263
  - test/unit/remote_partial/partial_test.rb
268
264
  - test/unit/remote_partial/builder_test.rb
269
265
  - test/unit/remote_partial/exception_test.rb
266
+ - test/unit/remote_partial/yaml_store_test.rb
270
267
  - test/unit/remote_partial/resource_manager_test.rb
271
268
  - test/unit/remote_partial_test.rb
@@ -1,25 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- development:
7
- adapter: sqlite3
8
- database: db/development.sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- # Warning: The database defined as "test" will be erased and
13
- # re-generated from your development database when you run "rake".
14
- # Do not set this db to the same as development or production.
15
- test:
16
- adapter: sqlite3
17
- database: db/test.sqlite3
18
- pool: 5
19
- timeout: 5000
20
-
21
- production:
22
- adapter: sqlite3
23
- database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000