trackman 0.6.9 → 0.6.10

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.
@@ -8,7 +8,6 @@ module Trackman
8
8
  def initialize attributes = {}
9
9
  @assets = []
10
10
 
11
-
12
11
  self.path = attributes[:path]
13
12
  self.virtual_path = attributes[:virtual_path]
14
13
  end
@@ -16,14 +15,17 @@ module Trackman
16
15
  attr_accessor :virtual_path
17
16
  attr_reader :path, :assets
18
17
 
19
- def to_remote
20
- RemoteAsset.create(:path => @path, :virtual_path => self.virtual_path)
18
+ def to_remote(id = nil)
19
+ RemoteAsset.create(:path => @path, :virtual_path => self.virtual_path, :id => id)
21
20
  end
22
21
 
23
22
  def ==(other)
24
23
  return false if other.nil?
25
24
  other_path = other.path.is_a?(Pathname) ? other.path : Pathname.new(other.path)
26
- other_path.to_s == path.to_s || path.cleanpath == other_path.cleanpath
25
+ path_equal = other_path.to_s == path.to_s || path.cleanpath == other_path.cleanpath
26
+ vp_equal = virtual_path.to_s == other.virtual_path.to_s
27
+
28
+ path_equal && vp_equal
27
29
  end
28
30
 
29
31
  def <=>(another)
@@ -50,7 +52,7 @@ module Trackman
50
52
  end
51
53
 
52
54
  def to_s
53
- "<#{self.class}:\npath=#{path}\nfile_hash=#{file_hash}>"
55
+ "\n<#{self.class}>:\npath='#{path}'\nfile_hash='#{file_hash}'\nvirtual_path='#{virtual_path}'"
54
56
  end
55
57
 
56
58
  def self.all
@@ -27,9 +27,8 @@ module Trackman
27
27
  if other.is_a? RemoteAsset
28
28
  result = other.id == id && other.file_hash == file_hash
29
29
  end
30
- return result
31
30
  end
32
- false
31
+ result
33
32
  end
34
33
 
35
34
  private
@@ -6,7 +6,7 @@ module Trackman
6
6
 
7
7
  {
8
8
  :create => to_create,
9
- :update => remote.select{|a| local.any?{ |s| a.path == s.path && (a.file_hash != s.file_hash || a.virtual_path != s.virtual_path) }},
9
+ :update => define_update(local, remote),
10
10
  :delete => define_deleted(local, remote) do |a|
11
11
  to_create.any?{ |c| c.path.basename == a.path.basename }
12
12
  end
@@ -23,6 +23,24 @@ module Trackman
23
23
 
24
24
  to_delete.reject{|a| a.path.to_s =~ /.html$/ }.to_a
25
25
  end
26
+
27
+ def define_update local, remote
28
+ to_update = local.select do |l|
29
+ remote.any? do |r|
30
+ path_eql = a.path == s.path
31
+ hash_eql = a.file_hash == s.file_hash
32
+ vp_eql = a.virtual_path == s.virtual_path
33
+
34
+ path_eql && (!hash_eql || !vp_eql)
35
+ end
36
+ end
37
+
38
+ to_update.map do |a|
39
+ sibling = remote.select{|x| x.path == a.path }.first
40
+ a.to_remote(sibling.id)
41
+ end
42
+ end
43
+
26
44
  end
27
45
  end
28
46
  end
@@ -1,3 +1,3 @@
1
1
  module Trackman
2
- VERSION = "0.6.9"
2
+ VERSION = "0.6.10"
3
3
  end
@@ -16,8 +16,8 @@ describe Trackman::Assets::Asset do
16
16
  end
17
17
 
18
18
  expected = [
19
- TestAsset.create(:path => 'spec/test_data/all/1.css'),
20
- TestAsset.create(:path => 'spec/test_data/all/2.gif'),
19
+ TestAsset.create(:path => 'spec/test_data/all/1.css', :virtual_path => '1.css'),
20
+ TestAsset.create(:path => 'spec/test_data/all/2.gif', :virtual_path => '2.gif'),
21
21
  TestAsset.maintenance_page
22
22
  ]
23
23
 
@@ -45,9 +45,9 @@ describe Trackman::Assets::Asset do
45
45
  end
46
46
 
47
47
  expected = [
48
- TestAsset.create(:path => 'spec/test_data/all/1.css'),
49
- TestAsset.create(:path => 'spec/test_data/all/2.gif'),
50
- TestAsset.create(:path => 'spec/test_data/all/3.js'),
48
+ TestAsset.create(:path => 'spec/test_data/all/1.css', :virtual_path => '1.css'),
49
+ TestAsset.create(:path => 'spec/test_data/all/2.gif', :virtual_path => '2.gif'),
50
+ TestAsset.create(:path => 'spec/test_data/all/3.js', :virtual_path => '3.js'),
51
51
  TestAsset.maintenance_page,
52
52
  TestAsset.error_page
53
53
  ]
@@ -74,8 +74,8 @@ describe Trackman::Assets::Asset do
74
74
  end
75
75
 
76
76
  expected = [
77
- TestAsset.create(:path => 'spec/test_data/all/1.css'),
78
- TestAsset.create(:path => 'spec/test_data/all/2.gif'),
77
+ TestAsset.create(:path => 'spec/test_data/all/1.css', :virtual_path => '1.css'),
78
+ TestAsset.create(:path => 'spec/test_data/all/2.gif', :virtual_path => '2.gif'),
79
79
  TestAsset.maintenance_page,
80
80
  TestAsset.error_page
81
81
  ]
@@ -108,7 +108,7 @@ describe Trackman::Assets::Asset do
108
108
  end
109
109
  end
110
110
 
111
- expected = [TestAsset.create(:path => 'spec/test_data/external_paths/1.css'), TestAsset.maintenance_page]
111
+ expected = [TestAsset.create(:path => 'spec/test_data/external_paths/1.css', :virtual_path => '1.css'), TestAsset.maintenance_page]
112
112
 
113
113
  TestAsset.all.should eq(expected)
114
114
  end
@@ -129,7 +129,7 @@ describe Trackman::Assets::Asset do
129
129
  end
130
130
  end
131
131
 
132
- expected = [TestAsset.create(:path => 'spec/test_data/external_paths/1.css'), TestAsset.maintenance_page]
132
+ expected = [TestAsset.create(:path => 'spec/test_data/external_paths/1.css', :virtual_path => '1.css'), TestAsset.maintenance_page]
133
133
  TestAsset.all.should eq(expected)
134
134
  end
135
135
  end
data/spec/asset_spec.rb CHANGED
@@ -26,6 +26,13 @@ describe Trackman::Assets::Asset do
26
26
 
27
27
  asset1.should == asset2
28
28
  end
29
+
30
+ it "is not equal if the virtual path is different" do
31
+ asset1 = RemoteAsset.create(:path => 'same/path', :virtual_path => '/different/virtual/path')
32
+ asset2 = RemoteAsset.create(:path => 'same/path', :virtual_path => 'different/virtual/path')
33
+
34
+ asset1.should_not == asset2
35
+ end
29
36
 
30
37
  describe "#data" do
31
38
  it "returns content of the file specified by path" do
@@ -22,9 +22,10 @@ describe Trackman::Assets::CompositeAsset do
22
22
  before :each do
23
23
  @composite = TestComposite.new
24
24
  end
25
+
25
26
  it "has children" do
26
27
  asset = Asset.create(:path => 'spec/test_data/css/with-asset.css')
27
- asset.assets.should == [Asset.create(:path => 'spec/test_data/css/imported.css')]
28
+ asset.assets.should == [Asset.create(:path => 'spec/test_data/css/imported.css', :virtual_path => 'imported.css')]
28
29
  end
29
30
 
30
31
  it "removes the translated assets that are nil" do
@@ -4,14 +4,14 @@ describe CssAsset do
4
4
  it "returns its assets when it has import in it" do
5
5
  asset = Asset.create(:path => 'spec/test_data/css/with-asset.css')
6
6
 
7
- asset.assets.should == [Asset.create(:path => 'spec/test_data/css/imported.css')]
7
+ asset.assets.should == [Asset.create(:path => 'spec/test_data/css/imported.css', :virtual_path => 'imported.css')]
8
8
  end
9
9
 
10
10
  it "returns multiple assets when it has multiple imports" do
11
11
  actual = Asset.create(:path => 'spec/test_data/css/with-multiple-assets.css')
12
12
  expected = [
13
- Asset.create(:path => 'spec/test_data/css/imported.css'),
14
- Asset.create(:path => 'spec/test_data/css/imported2.css')
13
+ Asset.create(:path => 'spec/test_data/css/imported.css', :virtual_path => 'imported.css'),
14
+ Asset.create(:path => 'spec/test_data/css/imported2.css', :virtual_path => 'imported2.css')
15
15
  ]
16
16
 
17
17
  actual.assets.should == expected
@@ -19,7 +19,7 @@ describe CssAsset do
19
19
 
20
20
  it "returns an image if it is within the css" do
21
21
  actual = Asset.create(:path => 'spec/test_data/css/image/with-image.css')
22
- expected = [ Asset.create(:path => 'spec/test_data/css/image/riding-you.jpg')]
22
+ expected = [ Asset.create(:path => 'spec/test_data/css/image/riding-you.jpg', :virtual_path => 'riding-you.jpg')]
23
23
 
24
24
  actual.assets.should == expected
25
25
  end
@@ -27,9 +27,9 @@ describe CssAsset do
27
27
  it "returns all recursive css imports and images under the css file" do
28
28
  expected =
29
29
  [
30
- Asset.create(:path => 'spec/test_data/css/recursive/imported-lvl2.css'),
31
- Asset.create(:path => 'spec/test_data/css/recursive/imported-lvl3.css'),
32
- Asset.create(:path => 'spec/test_data/css/recursive/riding-you.jpg')
30
+ Asset.create(:path => 'spec/test_data/css/recursive/imported-lvl2.css', :virtual_path => 'imported-lvl2.css'),
31
+ Asset.create(:path => 'spec/test_data/css/recursive/imported-lvl3.css', :virtual_path => 'imported-lvl3.css'),
32
+ Asset.create(:path => 'spec/test_data/css/recursive/riding-you.jpg', :virtual_path => 'riding-you.jpg')
33
33
  ]
34
34
  asset = Asset.create(:path => 'spec/test_data/css/recursive/imported-recursive.css')
35
35
  actual = asset.assets
@@ -5,10 +5,10 @@ describe Trackman::Assets::HtmlAsset do
5
5
  asset = Asset.create(:path => 'spec/test_data/sample.html')
6
6
 
7
7
  expected = [
8
- 'spec/test_data/test1.jpeg',
9
- 'spec/test_data/test2.png',
10
- 'spec/test_data/test3.gif'
11
- ].map{|x| Asset.create(:path => x) }
8
+ Asset.create(:path => 'spec/test_data/test1.jpeg', :virtual_path => 'test1.jpeg'),
9
+ Asset.create(:path => 'spec/test_data/test2.png', :virtual_path => 'test2.png'),
10
+ Asset.create(:path => 'spec/test_data/test3.gif', :virtual_path => 'test3.gif')
11
+ ]
12
12
 
13
13
  actual = asset.assets.select{|a| !(['.css', '.js'].include?(a.path.extname)) }
14
14
 
@@ -19,8 +19,8 @@ describe Trackman::Assets::HtmlAsset do
19
19
  it "should contains every js within the html as assets" do
20
20
  asset = Asset.create(:path => 'spec/test_data/sample.html')
21
21
 
22
- expected = ['a', 'b', 'c'].map{|x| Asset.create(:path =>"spec/test_data/#{x}.js") }
23
-
22
+ expected = ['a', 'b', 'c'].map{|x| Asset.create(:path =>"spec/test_data/#{x}.js", :virtual_path => "#{x}.js") }
23
+
24
24
  actual = asset.assets.select{|a| a.path.extname == '.js'}
25
25
 
26
26
  actual.should eq(expected)
@@ -29,7 +29,7 @@ describe Trackman::Assets::HtmlAsset do
29
29
  it "should contains every css within the html as assets" do
30
30
  asset = Asset.create(:path => 'spec/test_data/sample.html')
31
31
 
32
- expected = ['y', 'z'].map{|x| Asset.create(:path => "spec/test_data/#{x}.css") }
32
+ expected = ['y', 'z'].map{|x| Asset.create(:path => "spec/test_data/#{x}.css", :virtual_path => "#{x}.css") }
33
33
 
34
34
  actual = asset.assets.select{|a| a.path.extname == '.css'}
35
35
 
@@ -38,9 +38,9 @@ describe Trackman::Assets::HtmlAsset do
38
38
 
39
39
  it "returns all recursive css imports and images under the html file that contains css" do
40
40
  expected = [
41
- CssAsset.new(:path => 'spec/test_data/css/recursive/imported-lvl2.css'),
42
- CssAsset.new(:path => 'spec/test_data/css/recursive/imported-lvl3.css'),
43
- Asset.new(:path => 'spec/test_data/css/recursive/riding-you.jpg')
41
+ CssAsset.new(:path => 'spec/test_data/css/recursive/imported-lvl2.css', :virtual_path => "imported-lvl2.css"),
42
+ CssAsset.new(:path => 'spec/test_data/css/recursive/imported-lvl3.css', :virtual_path => "imported-lvl3.css"),
43
+ Asset.new(:path => 'spec/test_data/css/recursive/riding-you.jpg', :virtual_path => "riding-you.jpg")
44
44
  ]
45
45
  asset = Asset.create(:path => 'spec/test_data/css/recursive/html-with-css.html')
46
46
 
@@ -3,7 +3,7 @@ require 'helpers/app_creator'
3
3
  require 'helpers/fakable_pathman_tester'
4
4
  require 'helpers/act_like_rails2311'
5
5
 
6
- describe 'full path' do
6
+ describe 'sync' do
7
7
  before :all do
8
8
  FakablePathManTester.switch_on 'spec/fixtures/rails2311/fully-loaded/'
9
9
  ActLikeRails2311.switch_on
@@ -25,6 +25,7 @@ describe 'full path' do
25
25
  remote = RemoteAsset.all
26
26
 
27
27
  remote.count.should == 8
28
+
28
29
  local.each{|l| remote.should include(l) }
29
30
  end
30
31
  end
@@ -14,7 +14,7 @@ describe Trackman::Assets::RemoteAsset do
14
14
  end
15
15
 
16
16
  it "creates assets on the server" do
17
- expected = RemoteAsset.create(:path => 'spec/test_data/test2.png')
17
+ expected = RemoteAsset.create(:path => 'spec/test_data/test2.png', :virtual_path => 'spec/test_data/test2.png')
18
18
  expected.insert
19
19
 
20
20
  actual = RemoteAsset.find expected.id
@@ -48,7 +48,7 @@ describe Trackman::Assets::RemoteAsset do
48
48
  end
49
49
 
50
50
  it "updates assets on the server" do
51
- expected = RemoteAsset.create(:path => 'spec/test_data/y.css')
51
+ expected = RemoteAsset.create(:path => 'spec/test_data/y.css', :virtual_path => 'spec/test_data/y.css')
52
52
 
53
53
  expected.insert
54
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: