dm-svn 0.2.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/.gitignore +23 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/dm-svn.gemspec +85 -0
- data/lib/dm-svn.rb +13 -0
- data/lib/dm-svn/config.rb +38 -0
- data/lib/dm-svn/model.rb +12 -0
- data/lib/dm-svn/svn.rb +144 -0
- data/lib/dm-svn/svn/categorized.rb +113 -0
- data/lib/dm-svn/svn/changeset.rb +119 -0
- data/lib/dm-svn/svn/node.rb +128 -0
- data/lib/dm-svn/svn/sync.rb +85 -0
- data/spec/dm-svn/config_spec.rb +51 -0
- data/spec/dm-svn/database.yml +16 -0
- data/spec/dm-svn/fixtures/articles_comments.rb +95 -0
- data/spec/dm-svn/mock_models.rb +53 -0
- data/spec/dm-svn/model_spec.rb +5 -0
- data/spec/dm-svn/spec_helper.rb +50 -0
- data/spec/dm-svn/svn/categorized_spec.rb +138 -0
- data/spec/dm-svn/svn/changeset_spec.rb +42 -0
- data/spec/dm-svn/svn/node_spec.rb +125 -0
- data/spec/dm-svn/svn/sync_spec.rb +111 -0
- data/spec/dm-svn/svn_spec.rb +213 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +23 -0
- metadata +132 -0
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dm-svn/mock_models'
|
3
|
+
|
4
|
+
describe DmSvn::Svn do
|
5
|
+
before(:all) do
|
6
|
+
DmSvn::Model.auto_migrate!
|
7
|
+
MockArticle.auto_migrate!
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@article = MockArticle.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should add svn_* properties" do
|
15
|
+
fields = %w{name created_at updated_at created_rev updated_rev created_by updated_by}
|
16
|
+
fields.each do | field |
|
17
|
+
MockArticleNoSvn.properties["svn_#{field}"].should be_nil
|
18
|
+
MockArticle.properties["svn_#{field}"].should be_kind_of(DataMapper::Property)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should assign @config to an instance of DmSvn::Config" do
|
23
|
+
c = MockArticle.config
|
24
|
+
c.should be_kind_of(DmSvn::Config)
|
25
|
+
c.should be(MockArticle.config)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should add an :body_property options to including class" do
|
29
|
+
MockArticle.config.body_property.should == "contents"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should alias svn_name as name" do
|
33
|
+
m = MockArticle.new
|
34
|
+
m.svn_name = 'path/to/name'
|
35
|
+
m.name.should == 'path/to/name'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should alias svn_name as path" do
|
39
|
+
m = MockArticle.new
|
40
|
+
m.svn_name = 'path/to/name'
|
41
|
+
m.path.should == 'path/to/name'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#path=' do
|
45
|
+
it "should set svn_name" do
|
46
|
+
@article.should_receive(:attribute_set).with(:svn_name, 'short/path')
|
47
|
+
@article.path = 'short/path'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#update_from_svn' do
|
52
|
+
before(:each) do
|
53
|
+
@node = mock(DmSvn::Svn::Node)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should update path, body and other properties' do
|
57
|
+
@node.should_receive(:body).twice.and_return('body')
|
58
|
+
@node.should_receive(:short_path).and_return('short/path')
|
59
|
+
@node.should_receive(:properties).and_return(
|
60
|
+
{'title' => 'Title', 'svn_updated_by' => 'jmorgan'}
|
61
|
+
)
|
62
|
+
|
63
|
+
@article.should_receive(:attribute_set).with(:svn_name, 'short/path')
|
64
|
+
@article.should_receive(:attribute_set).with('contents', 'body')
|
65
|
+
@article.should_receive(:title=).with('Title')
|
66
|
+
@article.should_receive(:svn_updated_by=).with('jmorgan')
|
67
|
+
|
68
|
+
@article.should_receive(:save)
|
69
|
+
@article.update_from_svn(@node)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#move_to" do
|
75
|
+
it 'should update the path and save' do
|
76
|
+
@article.should_receive(:path=).with('new/path')
|
77
|
+
@article.should_receive(:save)
|
78
|
+
@article.move_to('new/path')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe ".svn_repository" do
|
83
|
+
before(:each) do
|
84
|
+
@svn_model = mock(DmSvn::Model)
|
85
|
+
@svn_model.stub!(:config=)
|
86
|
+
MockArticle.instance_variable_set("@svn_repository", nil)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return an already set repository" do
|
90
|
+
DmSvn::Model.should_not_receive(:first)
|
91
|
+
DmSvn::Model.should_not_receive(:create)
|
92
|
+
MockArticle.instance_variable_set("@svn_repository", @svn_model)
|
93
|
+
MockArticle.svn_repository.should be(@svn_model)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should find an existing DmSvn::Model" do
|
97
|
+
DmSvn::Model.should_receive(:first).with(:name => 'MockArticle').
|
98
|
+
and_return(@svn_model)
|
99
|
+
DmSvn::Model.should_not_receive(:create)
|
100
|
+
MockArticle.svn_repository.should be(@svn_model)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should create an new DmSvn::Model if needed" do
|
104
|
+
DmSvn::Model.should_receive(:first).with(:name => 'MockArticle').
|
105
|
+
and_return(nil)
|
106
|
+
DmSvn::Model.should_receive(:create).with(:name => 'MockArticle', :revision => 0).
|
107
|
+
and_return(@svn_model)
|
108
|
+
MockArticle.svn_repository.should be(@svn_model)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should really create a new DmSvn::Model" do
|
112
|
+
DmSvn::Model.all.each {|m| m.destroy }
|
113
|
+
DmSvn::Model.count.should == 0
|
114
|
+
MockArticle.svn_repository
|
115
|
+
DmSvn::Model.count.should == 1
|
116
|
+
MockArticle.instance_variable_set("@svn_repository", nil)
|
117
|
+
MockArticle.svn_repository
|
118
|
+
DmSvn::Model.count.should == 1
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should assign @config to the DmSvn::Model" do
|
122
|
+
DmSvn::Model.should_receive(:first).with(:name => 'MockArticle').
|
123
|
+
and_return(@svn_model)
|
124
|
+
@svn_model.should_receive(:config=).with(MockArticle.config)
|
125
|
+
MockArticle.svn_repository
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should run sync" do
|
129
|
+
DmSvn::Model.should_receive(:first).with(:name => 'MockArticle').
|
130
|
+
and_return(@svn_model)
|
131
|
+
sync = mock(DmSvn::Svn::Sync)
|
132
|
+
DmSvn::Svn::Sync.should_receive(:new).with(@svn_model).and_return(sync)
|
133
|
+
sync.should_receive(:run)
|
134
|
+
MockArticle.sync
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
describe ".get" do
|
140
|
+
it "should get instance by path" do
|
141
|
+
MockArticle.should_receive(:get_by_path).
|
142
|
+
with('path/to/name').
|
143
|
+
and_return(nil)
|
144
|
+
|
145
|
+
MockArticle.get('path/to/name')
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should get instance by id" do
|
149
|
+
MockArticle.should_not_receive(:get_by_path)
|
150
|
+
MockArticle.should_receive(:first).and_return(nil)
|
151
|
+
MockArticle.get(1)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe ".get_or_create" do
|
156
|
+
it "should get an existing instance by path" do
|
157
|
+
MockArticle.should_receive(:get_by_path).
|
158
|
+
with('path/to/name').
|
159
|
+
and_return(1)
|
160
|
+
|
161
|
+
MockArticle.get_or_create('path/to/name').should == 1
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should create a new instance, setting path" do
|
165
|
+
MockArticle.should_receive(:get_by_path).
|
166
|
+
with('path/to/name').
|
167
|
+
and_return(nil)
|
168
|
+
|
169
|
+
m = MockArticle.new
|
170
|
+
MockArticle.should_receive(:create).and_return(m)
|
171
|
+
|
172
|
+
MockArticle.get_or_create('path/to/name')
|
173
|
+
m.path.should == 'path/to/name'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe ".get_by_path" do
|
178
|
+
it "should get an instance by path" do
|
179
|
+
MockArticle.should_receive(:first).
|
180
|
+
with(:svn_name => 'path/to/name').
|
181
|
+
and_return(nil)
|
182
|
+
|
183
|
+
MockArticle.get_by_path('path/to/name')
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "hooks" do
|
188
|
+
it "should update svn_created_* properties before create" do
|
189
|
+
a = MockArticle.new
|
190
|
+
|
191
|
+
a.svn_updated_at = Time.parse("2008-08-10 05:00:00")
|
192
|
+
a.svn_updated_rev = 10
|
193
|
+
a.svn_updated_by = "jmorgan"
|
194
|
+
a.save
|
195
|
+
|
196
|
+
at = a.svn_updated_at
|
197
|
+
|
198
|
+
a.svn_created_at.should == at
|
199
|
+
a.svn_created_rev.should == 10.to_s
|
200
|
+
a.svn_created_by.should == "jmorgan"
|
201
|
+
|
202
|
+
a.svn_updated_at = Time.parse("2008-08-12 05:00:00")
|
203
|
+
a.svn_updated_rev = 12
|
204
|
+
a.svn_updated_by = "someone_else"
|
205
|
+
a.save
|
206
|
+
|
207
|
+
# should not have changed.
|
208
|
+
a.svn_created_at.should == at
|
209
|
+
a.svn_created_rev.should == 10.to_s
|
210
|
+
a.svn_created_by.should == "jmorgan"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
data/spec/spec.opts
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'dm-svn'
|
3
|
+
|
4
|
+
gem 'jm81-svn-fixture'
|
5
|
+
require 'svn-fixture'
|
6
|
+
|
7
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
# for temporarily disabling one set of specs.
|
14
|
+
def dont_describe(*args)
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# Load a fixture and return the repos uri.
|
19
|
+
def load_svn_fixture(name)
|
20
|
+
script = File.expand_path(File.join(File.dirname(__FILE__), "dm-svn", "fixtures", "#{name}.rb" ))
|
21
|
+
load script
|
22
|
+
return SvnFixture.repo(name).uri + "/articles"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-svn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Morgan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-11 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.10.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dm-aggregates
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: dm-validations
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.10.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: jm81-svn-fixture
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.1
|
54
|
+
version:
|
55
|
+
description: |-
|
56
|
+
dm-svn allows you to store data in a Subversion
|
57
|
+
repository, then sync that data to a DataMapper model (for example, to a
|
58
|
+
relational database. Essentially, it allows you app quicker access to the
|
59
|
+
Subversion data.
|
60
|
+
email: jmorgan@morgancreative.net
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
extra_rdoc_files: []
|
66
|
+
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- dm-svn.gemspec
|
72
|
+
- lib/dm-svn.rb
|
73
|
+
- lib/dm-svn/config.rb
|
74
|
+
- lib/dm-svn/model.rb
|
75
|
+
- lib/dm-svn/svn.rb
|
76
|
+
- lib/dm-svn/svn/categorized.rb
|
77
|
+
- lib/dm-svn/svn/changeset.rb
|
78
|
+
- lib/dm-svn/svn/node.rb
|
79
|
+
- lib/dm-svn/svn/sync.rb
|
80
|
+
- spec/dm-svn/config_spec.rb
|
81
|
+
- spec/dm-svn/database.yml
|
82
|
+
- spec/dm-svn/fixtures/articles_comments.rb
|
83
|
+
- spec/dm-svn/mock_models.rb
|
84
|
+
- spec/dm-svn/model_spec.rb
|
85
|
+
- spec/dm-svn/spec_helper.rb
|
86
|
+
- spec/dm-svn/svn/categorized_spec.rb
|
87
|
+
- spec/dm-svn/svn/changeset_spec.rb
|
88
|
+
- spec/dm-svn/svn/node_spec.rb
|
89
|
+
- spec/dm-svn/svn/sync_spec.rb
|
90
|
+
- spec/dm-svn/svn_spec.rb
|
91
|
+
- spec/spec.opts
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://github.com/jm81/dm-svn
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- --charset=UTF-8
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.5
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Sync content from a Subversion repository to a DataMapper model
|
121
|
+
test_files:
|
122
|
+
- spec/dm-svn/config_spec.rb
|
123
|
+
- spec/dm-svn/fixtures/articles_comments.rb
|
124
|
+
- spec/dm-svn/mock_models.rb
|
125
|
+
- spec/dm-svn/model_spec.rb
|
126
|
+
- spec/dm-svn/spec_helper.rb
|
127
|
+
- spec/dm-svn/svn/categorized_spec.rb
|
128
|
+
- spec/dm-svn/svn/changeset_spec.rb
|
129
|
+
- spec/dm-svn/svn/node_spec.rb
|
130
|
+
- spec/dm-svn/svn/sync_spec.rb
|
131
|
+
- spec/dm-svn/svn_spec.rb
|
132
|
+
- spec/spec_helper.rb
|