svn-fixture 0.2.0 → 0.3.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -8,7 +8,7 @@ require "svn/fs"
8
8
  require "svn/repos"
9
9
 
10
10
  module SvnFixture
11
- VERSION = '0.2.0'
11
+ VERSION = '0.3.0'
12
12
 
13
13
  CONFIG_DEFAULTS = {
14
14
  :base_path => File.join(Dir.tmpdir, 'svn-fixture')
@@ -71,5 +71,5 @@ end
71
71
 
72
72
  require 'svn-fixture/repository'
73
73
  require 'svn-fixture/revision'
74
- require 'svn-fixture/directory'
75
74
  require 'svn-fixture/file'
75
+ require 'svn-fixture/directory'
@@ -30,7 +30,7 @@ module SvnFixture
30
30
  # ctx.checkout('file:///repository/uri', '/fs/path/of/wc')
31
31
  # d = SvnFixture::Directory.new(ctx, '/fs/path/of/wc/to/dir')
32
32
  # d.prop('propname', 'Value')
33
- class Directory
33
+ class Directory < File
34
34
 
35
35
  # +new+ is normally called through Directory#dir (a block to a Revision is
36
36
  # applied to the root Directory).
@@ -43,6 +43,7 @@ module SvnFixture
43
43
  @ctx = ctx
44
44
  @path = path
45
45
  @path += "/" unless path[-1] == 47
46
+ @clean_path = @path[0..-2] # Path without a trailing slash.
46
47
  end
47
48
 
48
49
  # Create or access a subdirectory. Takes the name of the subdirectory (not a
@@ -96,7 +97,7 @@ module SvnFixture
96
97
  # value<String>:: The value of the property.
97
98
  # recurse<True, False>:: Apply this property to descendants?
98
99
  def prop(name, value, recurse = false)
99
- @ctx.propset(name, SvnFixture.svn_prop(value), @path[0..-2], recurse)
100
+ @ctx.propset(name, SvnFixture.svn_prop(value), @clean_path, recurse)
100
101
  end
101
102
  end
102
103
  end
@@ -40,6 +40,7 @@ module SvnFixture
40
40
  # - +path+: The path (on the file system) of the File in the working copy
41
41
  def initialize(ctx, path)
42
42
  @ctx, @path = ctx, path
43
+ @clean_path = path # Path without a trailing slash. Used by methods shared with Directory
43
44
  end
44
45
 
45
46
  # Set a property for the file
@@ -50,6 +51,47 @@ module SvnFixture
50
51
  @ctx.propset(name, SvnFixture.svn_prop(value), @path)
51
52
  end
52
53
 
54
+ # Remove a property from the directory
55
+ #
56
+ # ==== Parameters
57
+ # name<String>:: The property name
58
+ def propdel(name)
59
+ @ctx.propdel(name, @clean_path)
60
+ end
61
+
62
+ # Set all properties from a hash, deleting any existing that are not
63
+ # included in the hash. "svn:entry" properties are ignored, as these are
64
+ # handled internally by Subversion.
65
+ #
66
+ # ==== Parameters
67
+ # hsh<Hash>:: Properties to set (name => value)
68
+ def props(hsh)
69
+ # Getting the proplist for a node that hasn't been committed doesn't
70
+ # seem to work. This isn't a problem (there's no existing props to delete)
71
+ # so just skip those.
72
+ skip_deletes = false
73
+ @ctx.status(@clean_path) do |path, status|
74
+ skip_deletes = true if @clean_path == path && status.entry.add?
75
+ end
76
+
77
+ # Delete any that aren't in hash
78
+ unless skip_deletes
79
+ url = @ctx.url_from_path(@clean_path)
80
+ existing = @ctx.proplist(@clean_path).find { |pl| pl.name == url }
81
+
82
+ if existing
83
+ existing.props.each_pair do |k, v|
84
+ propdel(k) unless (hsh[k] || k =~ /\Asvn:entry/)
85
+ end
86
+ end
87
+ end
88
+
89
+ # Set props (except svn:entry)
90
+ hsh.each do |k, v|
91
+ prop(k, v) unless k =~ /\Asvn:entry/
92
+ end
93
+ end
94
+
53
95
  # Set the content of a file
54
96
  def body(val)
55
97
  ::File.open(@path, 'w') { |f| f.write(val) }
@@ -4,3 +4,5 @@ require 'svn-fixture'
4
4
  Spec::Runner.configure do |config|
5
5
 
6
6
  end
7
+
8
+ require 'svn-fixture/props_shared.rb'
@@ -9,8 +9,11 @@ describe SvnFixture::Directory do
9
9
  @repos = SvnFixture::repo('dir_test') do
10
10
  revision(1, 'create directory and file') do
11
11
  dir('test-dir') do
12
+ prop 'three', 'dir'
12
13
  dir('subdir')
13
- file('file.txt')
14
+ file('file.txt') do
15
+ prop 'one', 'two'
16
+ end
14
17
  end
15
18
  end
16
19
  end
@@ -23,13 +26,15 @@ describe SvnFixture::Directory do
23
26
  before(:each) do
24
27
  @path = File.join(@wc_path, 'test-dir')
25
28
  @full_repos_path = "file://#{File.join(@repos_path, 'test-dir')}"
26
- @dir = @klass.new(@ctx, @path)
29
+ @dir = @node = @klass.new(@ctx, @path)
27
30
  end
28
31
 
29
32
  after(:all) do
30
33
  SvnFixture::Repository.destroy_all
31
34
  end
32
35
 
36
+ it_should_behave_like "nodes with properties"
37
+
33
38
  describe '#initialize' do
34
39
  it 'should set ctx and path' do
35
40
  dir = @klass.new(@ctx, '/tmp/path/')
@@ -172,18 +177,6 @@ describe SvnFixture::Directory do
172
177
  end
173
178
 
174
179
  describe '#prop' do
175
- it 'should set a property' do
176
- @dir.prop('prop:name', 'Prop Value')
177
- rev = @ctx.ci(@wc_path).revision
178
- @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
179
- 'Prop Value'
180
-
181
- @dir.prop('prop:name', 'New Value')
182
- rev = @ctx.ci(@wc_path).revision
183
- @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
184
- 'New Value'
185
- end
186
-
187
180
  it 'should not set a property recursively by default' do
188
181
  @dir.prop('prop:name', 'Prop Value')
189
182
  rev = @ctx.ci(@wc_path).revision
@@ -203,12 +196,5 @@ describe SvnFixture::Directory do
203
196
  @ctx.propget('prop:name', @path + "/file.txt", rev)[@full_repos_path + "/file.txt"].should ==
204
197
  'Prop Value'
205
198
  end
206
-
207
- it 'should format a Time correctly' do
208
- @dir.prop('prop:timeval', Time.parse('2009-06-18 14:00 UTC'))
209
- rev = @ctx.ci(@wc_path).revision
210
- @ctx.propget('prop:timeval', @path, rev)[@full_repos_path].should ==
211
- '2009-06-18T14:00:00.000000Z'
212
- end
213
199
  end
214
200
  end
@@ -20,13 +20,15 @@ describe SvnFixture::File do
20
20
  before(:each) do
21
21
  @path = File.join(@wc_path, 'test.txt')
22
22
  @full_repos_path = "file://#{File.join(@repos_path, 'test.txt')}"
23
- @file = @klass.new(@ctx, @path)
23
+ @file = @node = @klass.new(@ctx, @path)
24
24
  end
25
25
 
26
26
  after(:all) do
27
27
  SvnFixture::Repository.destroy_all
28
28
  end
29
29
 
30
+ it_should_behave_like "nodes with properties"
31
+
30
32
  describe '#initialize' do
31
33
  it 'should set ctx and path' do
32
34
  file = @klass.new(@ctx, '/tmp/path')
@@ -35,27 +37,6 @@ describe SvnFixture::File do
35
37
  end
36
38
  end
37
39
 
38
- describe '#prop' do
39
- it 'should set a property' do
40
- @file.prop('prop:name', 'Prop Value')
41
- rev = @ctx.ci(@wc_path).revision
42
- @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
43
- 'Prop Value'
44
-
45
- @file.prop('prop:name', 'New Value')
46
- rev = @ctx.ci(@wc_path).revision
47
- @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
48
- 'New Value'
49
- end
50
-
51
- it 'should format a Time correctly' do
52
- @file.prop('prop:timeval', Time.parse('2009-06-18 14:00 UTC'))
53
- rev = @ctx.ci(@wc_path).revision
54
- @ctx.propget('prop:timeval', @path, rev)[@full_repos_path].should ==
55
- '2009-06-18T14:00:00.000000Z'
56
- end
57
- end
58
-
59
40
  describe '#body' do
60
41
  it "should update the File's contents" do
61
42
  @file.body('Test Content')
@@ -0,0 +1,57 @@
1
+ shared_examples_for "nodes with properties" do
2
+ describe '#prop' do
3
+ it 'should set a property' do
4
+ @node.prop('prop:name', 'Prop Value')
5
+ rev = @ctx.ci(@wc_path).revision
6
+ @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
7
+ 'Prop Value'
8
+
9
+ @node.prop('prop:name', 'New Value')
10
+ rev = @ctx.ci(@wc_path).revision
11
+ @ctx.propget('prop:name', @path, rev)[@full_repos_path].should ==
12
+ 'New Value'
13
+ end
14
+
15
+ it 'should format a Time correctly' do
16
+ @node.prop('prop:timeval', Time.parse('2009-06-18 14:00 UTC'))
17
+ rev = @ctx.ci(@wc_path).revision
18
+ @ctx.propget('prop:timeval', @path, rev)[@full_repos_path].should ==
19
+ '2009-06-18T14:00:00.000000Z'
20
+ end
21
+ end
22
+
23
+ describe '#props' do
24
+ it 'should set properties (deleting those not included)' do
25
+ @node.props('prop:name' => 'One', 'prop:two' => 'Two')
26
+ rev = @ctx.ci(@wc_path).revision
27
+ @ctx.propget('prop:name', @path, rev)[@full_repos_path].should == 'One'
28
+ @ctx.propget('prop:two', @path, rev)[@full_repos_path].should == 'Two'
29
+
30
+ @node.props('prop:two' => 'Two', 'prop:three' => 'Three')
31
+ rev = @ctx.ci(@wc_path).revision
32
+ @ctx.propget('prop:two', @path, rev)[@full_repos_path].should == 'Two'
33
+ @ctx.propget('prop:three', @path, rev)[@full_repos_path].should == 'Three'
34
+ @ctx.propget('prop:name', @path, rev)[@full_repos_path].should be_nil
35
+ end
36
+
37
+ it 'should ignore svn:entry properties' do
38
+ @node.should_receive(:prop).with('prop:name', 'One')
39
+ @node.props('prop:name' => 'One')
40
+ @node.should_not_receive(:prop).with('svn:entry:time', 'One')
41
+ @node.props('svn:entry:time' => 'One')
42
+ end
43
+ end
44
+
45
+ describe '#propdel' do
46
+ it 'should delete a property' do
47
+ @node.prop('prop:del', 'Prop Value')
48
+ rev = @ctx.ci(@wc_path).revision
49
+ @ctx.propget('prop:del', @path, rev)[@full_repos_path].should ==
50
+ 'Prop Value'
51
+
52
+ @node.propdel('prop:del')
53
+ rev = @ctx.ci(@wc_path).revision
54
+ @ctx.propget('prop:del', @path, rev)[@full_repos_path].should be_nil
55
+ end
56
+ end
57
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{svn-fixture}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jared Morgan"]
12
- s.date = %q{2009-10-18}
12
+ s.date = %q{2009-10-31}
13
13
  s.description = %q{svn-fixture simplifies creating (or updating) a Subversion repository. It is
14
14
  designed to be used in tests that require a Subversion repo, but can also be
15
15
  used to initialize a repository according to some template. svn-fixture depends
@@ -38,6 +38,7 @@ on the Subversion Ruby bindings.
38
38
  "spec/svn-fixture/file_spec.rb",
39
39
  "spec/svn-fixture/fixtures/hello_world.rb",
40
40
  "spec/svn-fixture/integration_spec.rb",
41
+ "spec/svn-fixture/props_shared.rb",
41
42
  "spec/svn-fixture/repository_spec.rb",
42
43
  "spec/svn-fixture/revision_spec.rb",
43
44
  "spec/svn-fixture_spec.rb",
@@ -55,6 +56,7 @@ on the Subversion Ruby bindings.
55
56
  "spec/svn-fixture/file_spec.rb",
56
57
  "spec/svn-fixture/fixtures/hello_world.rb",
57
58
  "spec/svn-fixture/integration_spec.rb",
59
+ "spec/svn-fixture/props_shared.rb",
58
60
  "spec/svn-fixture/repository_spec.rb",
59
61
  "spec/svn-fixture/revision_spec.rb",
60
62
  "spec/svn-fixture_spec.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svn-fixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Morgan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-18 00:00:00 -05:00
12
+ date: 2009-10-31 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -45,6 +45,7 @@ files:
45
45
  - spec/svn-fixture/file_spec.rb
46
46
  - spec/svn-fixture/fixtures/hello_world.rb
47
47
  - spec/svn-fixture/integration_spec.rb
48
+ - spec/svn-fixture/props_shared.rb
48
49
  - spec/svn-fixture/repository_spec.rb
49
50
  - spec/svn-fixture/revision_spec.rb
50
51
  - spec/svn-fixture_spec.rb
@@ -84,6 +85,7 @@ test_files:
84
85
  - spec/svn-fixture/file_spec.rb
85
86
  - spec/svn-fixture/fixtures/hello_world.rb
86
87
  - spec/svn-fixture/integration_spec.rb
88
+ - spec/svn-fixture/props_shared.rb
87
89
  - spec/svn-fixture/repository_spec.rb
88
90
  - spec/svn-fixture/revision_spec.rb
89
91
  - spec/svn-fixture_spec.rb