repo_manager 0.7.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/.gemfiles +115 -0
- data/.gitattributes +1 -0
- data/.gitignore +7 -0
- data/.rspec +3 -0
- data/.yardopts +11 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +99 -0
- data/Guardfile +63 -0
- data/HISTORY.markdown +12 -0
- data/LICENSE +20 -0
- data/README.markdown +192 -0
- data/Rakefile +94 -0
- data/TODO.markdown +15 -0
- data/VERSION +1 -0
- data/bin/repo +151 -0
- data/cucumber.yml +28 -0
- data/examples/pc_saved_game_backup/.gitignore +2 -0
- data/examples/pc_saved_game_backup/INSTALL.markdown +420 -0
- data/examples/pc_saved_game_backup/README.markdown +108 -0
- data/examples/pc_saved_game_backup/remote/.gitignore +2 -0
- data/examples/pc_saved_game_backup/repo_manager/Gemfile +12 -0
- data/examples/pc_saved_game_backup/repo_manager/Gemfile.lock +66 -0
- data/examples/pc_saved_game_backup/repo_manager/assets/.gitignore +2 -0
- data/examples/pc_saved_game_backup/repo_manager/features/support/aruba.rb +15 -0
- data/examples/pc_saved_game_backup/repo_manager/features/support/env.rb +11 -0
- data/examples/pc_saved_game_backup/repo_manager/features/support/steps.rb +3 -0
- data/examples/pc_saved_game_backup/repo_manager/features/tasks/update.feature +144 -0
- data/examples/pc_saved_game_backup/repo_manager/global/default/asset.conf +2 -0
- data/examples/pc_saved_game_backup/repo_manager/repo.conf +64 -0
- data/examples/pc_saved_game_backup/repo_manager/tasks/.gitignore +0 -0
- data/examples/pc_saved_game_backup/repo_manager/tasks/remote.rb +57 -0
- data/examples/pc_saved_game_backup/repo_manager/tasks/update.rb +65 -0
- data/examples/pc_saved_game_backup/saved_games/hearts/save1 +1 -0
- data/examples/pc_saved_game_backup/saved_games/hearts/save2 +1 -0
- data/examples/pc_saved_game_backup/saved_games/mines/my_profile.ini +1 -0
- data/examples/pc_saved_game_backup/saved_games/mines/saves/save1 +1 -0
- data/examples/pc_saved_game_backup/saved_games/mines/saves/save2 +1 -0
- data/features/actions/git.feature +296 -0
- data/features/actions/help.feature +53 -0
- data/features/actions/list.feature +624 -0
- data/features/actions/path.feature +195 -0
- data/features/actions/status.feature +261 -0
- data/features/actions/task.feature +127 -0
- data/features/assets/configuration.feature +204 -0
- data/features/assets/rendering.feature +42 -0
- data/features/assets/user_attributes.feature +98 -0
- data/features/bin.feature +42 -0
- data/features/logger.feature +218 -0
- data/features/settings.feature +240 -0
- data/features/support/aruba.rb +15 -0
- data/features/support/env.rb +11 -0
- data/features/support/steps.rb +3 -0
- data/features/tasks/add/asset.feature +178 -0
- data/features/tasks/generate/init.feature +56 -0
- data/lib/repo_manager.rb +36 -0
- data/lib/repo_manager/actions.rb +8 -0
- data/lib/repo_manager/actions/action_helper.rb +39 -0
- data/lib/repo_manager/actions/app_action.rb +30 -0
- data/lib/repo_manager/actions/base_action.rb +296 -0
- data/lib/repo_manager/actions/git_action.rb +113 -0
- data/lib/repo_manager/actions/help_action.rb +52 -0
- data/lib/repo_manager/actions/list_action.rb +123 -0
- data/lib/repo_manager/actions/path_action.rb +22 -0
- data/lib/repo_manager/actions/status_action.rb +192 -0
- data/lib/repo_manager/actions/task_action.rb +71 -0
- data/lib/repo_manager/app.rb +116 -0
- data/lib/repo_manager/assets.rb +3 -0
- data/lib/repo_manager/assets/app_asset.rb +15 -0
- data/lib/repo_manager/assets/asset_accessors.rb +67 -0
- data/lib/repo_manager/assets/asset_configuration.rb +137 -0
- data/lib/repo_manager/assets/asset_manager.rb +72 -0
- data/lib/repo_manager/assets/base_asset.rb +199 -0
- data/lib/repo_manager/assets/repo_asset.rb +30 -0
- data/lib/repo_manager/core.rb +2 -0
- data/lib/repo_manager/core/array.rb +21 -0
- data/lib/repo_manager/core/hash.rb +83 -0
- data/lib/repo_manager/errors.rb +10 -0
- data/lib/repo_manager/extensions/hash.rb +86 -0
- data/lib/repo_manager/git.rb +2 -0
- data/lib/repo_manager/git/lib.rb +69 -0
- data/lib/repo_manager/git/status.rb +196 -0
- data/lib/repo_manager/logger.rb +39 -0
- data/lib/repo_manager/settings.rb +98 -0
- data/lib/repo_manager/tasks.rb +3 -0
- data/lib/repo_manager/tasks/add/asset.rb +213 -0
- data/lib/repo_manager/tasks/generate/init.rb +42 -0
- data/lib/repo_manager/tasks/generate/templates/config/repo.conf.tt +61 -0
- data/lib/repo_manager/tasks/generate/templates/init/assets/.gitignore +0 -0
- data/lib/repo_manager/tasks/generate/templates/init/global/default/asset.conf +2 -0
- data/lib/repo_manager/tasks/generate/templates/init/tasks/.gitignore +0 -0
- data/lib/repo_manager/tasks/task_manager.rb +166 -0
- data/lib/repo_manager/tasks/thor_helper.rb +29 -0
- data/lib/repo_manager/test/asset_steps.rb +19 -0
- data/lib/repo_manager/test/base_steps.rb +152 -0
- data/lib/repo_manager/test/repo_api.rb +41 -0
- data/lib/repo_manager/test/repo_steps.rb +83 -0
- data/lib/repo_manager/test/test_api.rb +88 -0
- data/lib/repo_manager/views.rb +2 -0
- data/lib/repo_manager/views/app_view.rb +15 -0
- data/lib/repo_manager/views/base_view.rb +137 -0
- data/lib/repo_manager/views/templates/css/basic.css +26 -0
- data/lib/repo_manager/views/templates/default.erb +40 -0
- data/lib/repo_manager/views/templates/default.slim +37 -0
- data/lib/repo_manager/views/view_helper.rb +55 -0
- data/repo_manager.gemspec +75 -0
- data/spec/basic_app/actions/action_helper_spec.rb +54 -0
- data/spec/basic_app/assets/base_asset_spec.rb +210 -0
- data/spec/basic_app/core_spec.rb +78 -0
- data/spec/basic_app/settings_spec.rb +64 -0
- data/spec/basic_app/views/view_helper_spec.rb +28 -0
- data/spec/basic_gem/aruba_helper_spec.rb +33 -0
- data/spec/basic_gem/basic_gem_spec.rb +84 -0
- data/spec/basic_gem/gemspec_spec.rb +68 -0
- data/spec/repo_manager/git_spec.rb +31 -0
- data/spec/spec_helper.rb +25 -0
- metadata +472 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module RepoManager
|
|
2
|
+
|
|
3
|
+
module ViewHelper
|
|
4
|
+
|
|
5
|
+
# path_to returns absolute installed path to various folders packaged with
|
|
6
|
+
# the RepoManager gem
|
|
7
|
+
#
|
|
8
|
+
# @example manually require and include before use
|
|
9
|
+
#
|
|
10
|
+
# require 'repo_manager/views/view_helper'
|
|
11
|
+
# include RepoManager::ViewHelper
|
|
12
|
+
#
|
|
13
|
+
# @example default to repo_manager root
|
|
14
|
+
#
|
|
15
|
+
# path_to("views/templates/bla.rb")
|
|
16
|
+
#
|
|
17
|
+
# @example repo_manager root
|
|
18
|
+
#
|
|
19
|
+
# path_to(:repo_manager, "views/templates/bla.rb")
|
|
20
|
+
#
|
|
21
|
+
# @example :bootstrap
|
|
22
|
+
#
|
|
23
|
+
# path_to(:bootstrap, "bootstrap/css/bootstrap.css")
|
|
24
|
+
#
|
|
25
|
+
# @overload path_to(*args)
|
|
26
|
+
# @param [Symbol] base_path which gem folder should be root
|
|
27
|
+
# @param [String] file_asset path to file asset parented in the given folder
|
|
28
|
+
#
|
|
29
|
+
# @return [String] absolute path to asset
|
|
30
|
+
def path_to(*args)
|
|
31
|
+
|
|
32
|
+
case
|
|
33
|
+
when args.length == 1
|
|
34
|
+
base_path = :repo_manager
|
|
35
|
+
asset = args
|
|
36
|
+
when args.length == 2
|
|
37
|
+
base_path, asset = *args
|
|
38
|
+
when args.length > 2
|
|
39
|
+
raise ArgumentError, "Too many arguments"
|
|
40
|
+
else
|
|
41
|
+
raise ArgumentError, "Specify at least the file asset"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
case base_path
|
|
45
|
+
when :repo_manager
|
|
46
|
+
root = File.expand_path('../../../../', __FILE__)
|
|
47
|
+
else
|
|
48
|
+
raise "unknown base_path"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
File.join(root, asset)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
#
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
|
|
6
|
+
# avoid shelling out to run git every time the gemspec is evaluated
|
|
7
|
+
#
|
|
8
|
+
# @see spec/gemspec_spec.rb
|
|
9
|
+
#
|
|
10
|
+
gemfiles_cache = File.join(File.dirname(__FILE__), '.gemfiles')
|
|
11
|
+
if File.exists?(gemfiles_cache)
|
|
12
|
+
gemfiles = File.open(gemfiles_cache, "r") {|f| f.read}
|
|
13
|
+
# normalize EOL
|
|
14
|
+
gemfiles.gsub!(/\r\n/, "\n")
|
|
15
|
+
else
|
|
16
|
+
# .gemfiles missing, run 'rake gemfiles' to create it
|
|
17
|
+
# falling back to 'git ls-files'"
|
|
18
|
+
gemfiles = `git ls-files`
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
s.name = "repo_manager"
|
|
22
|
+
s.version = File.open(File.join(File.dirname(__FILE__), 'VERSION'), "r") { |f| f.read }
|
|
23
|
+
s.platform = Gem::Platform::RUBY
|
|
24
|
+
s.authors = ["Robert Wahler"]
|
|
25
|
+
s.email = ["robert@gearheadforhire.com"]
|
|
26
|
+
s.homepage = "http://rubygems.org/gems/repo_manager"
|
|
27
|
+
s.summary = "CLI for batch management of multiple Git repositories"
|
|
28
|
+
s.description = "CLI for batch management of multiple Git repositories. Repositories don't need to be related."
|
|
29
|
+
|
|
30
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
31
|
+
s.rubyforge_project = "repo_manager"
|
|
32
|
+
|
|
33
|
+
s.add_dependency 'term-ansicolor', '>= 1.0.4'
|
|
34
|
+
s.add_dependency 'logging', '>= 1.6.2'
|
|
35
|
+
s.add_dependency 'slim', '>= 1.0.4'
|
|
36
|
+
s.add_dependency 'mustache', '>= 0.99.4'
|
|
37
|
+
s.add_dependency "chronic", ">= 0.6.5"
|
|
38
|
+
s.add_dependency "thor", "~> 0.15.0"
|
|
39
|
+
|
|
40
|
+
s.add_dependency 'git', '= 1.2.5'
|
|
41
|
+
|
|
42
|
+
s.add_development_dependency "bundler", ">= 1.0.14"
|
|
43
|
+
s.add_development_dependency "rspec", ">= 2.6.0"
|
|
44
|
+
s.add_development_dependency "cucumber", "~> 1.0"
|
|
45
|
+
s.add_development_dependency "aruba", "= 0.4.5"
|
|
46
|
+
s.add_development_dependency "rake", ">= 0.8.7"
|
|
47
|
+
|
|
48
|
+
# doc generation
|
|
49
|
+
s.add_development_dependency "yard", ">= 0.7.4"
|
|
50
|
+
s.add_development_dependency "yard-cucumber", ">= 2.1.7"
|
|
51
|
+
s.add_development_dependency "redcarpet", ">= 1.17.2"
|
|
52
|
+
|
|
53
|
+
# guard, watches files and runs specs and features
|
|
54
|
+
#
|
|
55
|
+
# Guard is locked at 1.0.3 due to high CPU usage after returning from screen
|
|
56
|
+
# lock on Ubuntu 11.04. Wait for the 1+ version of Guard to mature and listen
|
|
57
|
+
# gem fixes are applied
|
|
58
|
+
#
|
|
59
|
+
# https://github.com/guard/listen/issues/44
|
|
60
|
+
#
|
|
61
|
+
s.add_development_dependency "guard", "= 1.0.3"
|
|
62
|
+
s.add_development_dependency "guard-rspec", "~> 0.7"
|
|
63
|
+
s.add_development_dependency "guard-cucumber", "~> 0.8"
|
|
64
|
+
|
|
65
|
+
s.files = gemfiles.split("\n")
|
|
66
|
+
s.executables = gemfiles.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
|
67
|
+
s.require_paths = ["lib"]
|
|
68
|
+
|
|
69
|
+
s.rdoc_options = [
|
|
70
|
+
'--title', 'RepoManager Documentation',
|
|
71
|
+
'--main', 'README.markdown',
|
|
72
|
+
'--line-numbers',
|
|
73
|
+
'--inline-source'
|
|
74
|
+
]
|
|
75
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'repo_manager/actions/action_helper'
|
|
4
|
+
|
|
5
|
+
class Thing
|
|
6
|
+
include ::RepoManager::ActionHelper
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe RepoManager::ActionHelper do
|
|
10
|
+
|
|
11
|
+
describe 'relative_path', :posix => true do
|
|
12
|
+
|
|
13
|
+
it "should return relative path given an absolute path" do
|
|
14
|
+
thing = Thing.new
|
|
15
|
+
FileUtils.stub!('pwd').and_return '/home/robert/workspace/my_app'
|
|
16
|
+
thing.relative_path('/home/robert/workspace/my_app/photos').should == './photos'
|
|
17
|
+
thing.relative_path('/home/robert/photos').should == '../../photos'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should return relative path given a relative path" do
|
|
21
|
+
thing = Thing.new
|
|
22
|
+
FileUtils.stub!('pwd').and_return '/home/someuser/my_app'
|
|
23
|
+
thing.relative_path('cats/dogs').should == './cats/dogs'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'relative_path', :windows => true do
|
|
29
|
+
|
|
30
|
+
context "on the same drive" do
|
|
31
|
+
it "should return relative path given an absolute path" do
|
|
32
|
+
thing = Thing.new
|
|
33
|
+
FileUtils.stub!('pwd').and_return 'c:/home/robert/workspace/my_app'
|
|
34
|
+
thing.relative_path('c:/home/robert/workspace/my_app/photos').should == './photos'
|
|
35
|
+
thing.relative_path('c:/home/robert/photos').should == '../../photos'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "on a different drive" do
|
|
40
|
+
it "should return relative path given an absolute path" do
|
|
41
|
+
thing = Thing.new
|
|
42
|
+
FileUtils.stub!('pwd').and_return 'c:/home/robert/workspace/my_app'
|
|
43
|
+
thing.relative_path('d:/some/path/photos').should == 'd:/some/path/photos'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should return relative path given a relative path" do
|
|
48
|
+
thing = Thing.new
|
|
49
|
+
FileUtils.stub!('pwd').and_return 'c:/home/someuser/my_app'
|
|
50
|
+
thing.relative_path('cats/dogs').should == './cats/dogs'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe RepoManager::BaseAsset do
|
|
4
|
+
|
|
5
|
+
describe 'self.path_to_name' do
|
|
6
|
+
|
|
7
|
+
it "should replace one or more whitespace chars with a single underscore" do
|
|
8
|
+
RepoManager::BaseAsset.path_to_name("/path/to a/hello world ").should == "hello_world"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should strip special chars # @ % * ' ! + . -" do
|
|
12
|
+
RepoManager::BaseAsset.path_to_name("/path/to a/.he@@llo' !w+orl-d'").should == "hello_world"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should replace '&' with '_and_'" do
|
|
16
|
+
RepoManager::BaseAsset.path_to_name("/path/to a/&hello &world&").should == "and_hello_and_world_and"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should lowercase the name" do
|
|
20
|
+
RepoManager::BaseAsset.path_to_name("d:/path/to a/Hello worlD").should == "hello_world"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "being created" do
|
|
26
|
+
|
|
27
|
+
describe "name" do
|
|
28
|
+
|
|
29
|
+
it "should be nil if unless name passed to initialize " do
|
|
30
|
+
asset = RepoManager::BaseAsset.new
|
|
31
|
+
asset.name.should be_nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should be the same as asset_name param " do
|
|
35
|
+
asset = RepoManager::BaseAsset.new("my_asset_name")
|
|
36
|
+
asset.name.should == "my_asset_name"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe 'common attributes' do
|
|
43
|
+
|
|
44
|
+
before :each do
|
|
45
|
+
@asset = RepoManager::BaseAsset.new
|
|
46
|
+
@asset.name = "test_asset"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe 'description' do
|
|
50
|
+
|
|
51
|
+
it "should be nil unless set" do
|
|
52
|
+
@asset.attributes[:description].should be_nil
|
|
53
|
+
@asset.description.should be_nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should render mustache templates" do
|
|
57
|
+
@asset.description = "This is a {{name}}"
|
|
58
|
+
@asset.attributes[:description].should == "This is a {{name}}"
|
|
59
|
+
@asset.description.should == "This is a test_asset"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe 'notes' do
|
|
65
|
+
|
|
66
|
+
it "should be nil unless set" do
|
|
67
|
+
@asset.attributes[:notes].should be_nil
|
|
68
|
+
@asset.notes.should be_nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should render mustache templates" do
|
|
72
|
+
@asset.notes = "This is a {{name}}"
|
|
73
|
+
@asset.attributes[:notes].should == "This is a {{name}}"
|
|
74
|
+
@asset.notes.should == "This is a test_asset"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe 'path' do
|
|
80
|
+
|
|
81
|
+
it "defaults to asset name when the path attribute is blank" do
|
|
82
|
+
@asset.name = "asset_name"
|
|
83
|
+
@asset.attributes[:path].should be_nil
|
|
84
|
+
@asset.path.should match(/^.*\/asset_name$/)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should be nil unless path or name is set" do
|
|
88
|
+
@asset.name = nil
|
|
89
|
+
@asset.attributes[:path].should be_nil
|
|
90
|
+
@asset.path.should be_nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should expand '~'" do
|
|
94
|
+
@asset.path = "~/test/here"
|
|
95
|
+
@asset.attributes[:path].should == "~/test/here"
|
|
96
|
+
@asset.path.should_not == "~/test/here"
|
|
97
|
+
@asset.path.should match(/.*\/test\/here$/)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should expand relative paths" do
|
|
101
|
+
@asset.path = "test/here"
|
|
102
|
+
@asset.attributes[:path].should == "test/here"
|
|
103
|
+
@asset.path.should match(/^#{File.expand_path(FileUtils.pwd)}\/test\/here$/)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "should render mustache templates" do
|
|
107
|
+
@asset.path = "test/{{name}}/here"
|
|
108
|
+
@asset.attributes[:path].should == "test/{{name}}/here"
|
|
109
|
+
@asset.path.should match(/^#{File.expand_path(FileUtils.pwd)}\/test\/test_asset\/here$/)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe 'tags' do
|
|
115
|
+
|
|
116
|
+
it "should be an empty array unless set" do
|
|
117
|
+
@asset.attributes[:tags].should be_nil
|
|
118
|
+
@asset.tags.should be_empty
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe 'user defined attributes' do
|
|
126
|
+
|
|
127
|
+
context "when not explicitly defined" do
|
|
128
|
+
|
|
129
|
+
it "should raise 'NoMethodError' when accessing" do
|
|
130
|
+
asset = RepoManager::BaseAsset.new("test_asset")
|
|
131
|
+
defined?(asset.undefined_attribute).should be_false
|
|
132
|
+
lambda {asset.undefined_attribute.should be_nil}.should raise_error NoMethodError
|
|
133
|
+
lambda {asset.undefined_attribute = 1}.should raise_error NoMethodError
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should not set that attributes hash" do
|
|
137
|
+
asset = RepoManager::BaseAsset.new "test_asset"
|
|
138
|
+
defined?(asset.undefined_attribute).should be_false
|
|
139
|
+
lambda {asset.undefined_attribute = 1}.should raise_error NoMethodError
|
|
140
|
+
asset.attributes[:undefined_attribute].should be_nil
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context "when a value exists in the main attributes hash" do
|
|
144
|
+
it "should not raise 'NoMethodError' when accessing" do
|
|
145
|
+
asset = RepoManager::BaseAsset.new("test_asset", {:undefined_attribute => "foo bar"})
|
|
146
|
+
defined?(asset.undefined_attribute).should be_false
|
|
147
|
+
lambda {asset.undefined_attribute.should be_nil}.should_not raise_error NoMethodError
|
|
148
|
+
lambda {asset.undefined_attribute = 1}.should raise_error NoMethodError
|
|
149
|
+
asset.undefined_attribute.should == "foo bar"
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context "when explicitly creating" do
|
|
156
|
+
|
|
157
|
+
class MyAsset < RepoManager::BaseAsset
|
|
158
|
+
def my_attribute
|
|
159
|
+
@my_attribute
|
|
160
|
+
end
|
|
161
|
+
def my_attribute=(value)
|
|
162
|
+
@my_attribute = value.to_i * 2
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should not overwrite existing attributes" do
|
|
167
|
+
attributes = {:user_attributes => [:my_attribute]}
|
|
168
|
+
|
|
169
|
+
asset = RepoManager::BaseAsset.new("test_asset", attributes)
|
|
170
|
+
asset.my_attribute = 2
|
|
171
|
+
asset.my_attribute.should == "2"
|
|
172
|
+
|
|
173
|
+
my_asset = MyAsset.new("test_asset", attributes)
|
|
174
|
+
my_asset.my_attribute = 2
|
|
175
|
+
my_asset.my_attribute.should == 4
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
context "when explicitly defined" do
|
|
181
|
+
|
|
182
|
+
it "should create read accessors" do
|
|
183
|
+
attributes = {:user_attributes => [:undefined_attribute]}
|
|
184
|
+
asset = RepoManager::BaseAsset.new("test_asset", attributes)
|
|
185
|
+
|
|
186
|
+
defined?(asset.undefined_attribute).should be_true
|
|
187
|
+
lambda {asset.undefined_attribute.should be_nil}.should_not raise_error NoMethodError
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "should create write accessors" do
|
|
191
|
+
attributes = {:user_attributes => [:undefined_attribute]}
|
|
192
|
+
asset = RepoManager::BaseAsset.new("test_asset", attributes)
|
|
193
|
+
|
|
194
|
+
lambda {asset.undefined_attribute = "1"}.should_not raise_error NoMethodError
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should set the attributes hash" do
|
|
198
|
+
attributes = {:user_attributes => [:undefined_attribute]}
|
|
199
|
+
asset = RepoManager::BaseAsset.new("test_asset", attributes)
|
|
200
|
+
|
|
201
|
+
asset.undefined_attribute = "1"
|
|
202
|
+
asset.attributes[:undefined_attribute].should == "1"
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
end
|
|
210
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Core" do
|
|
4
|
+
|
|
5
|
+
before :each do
|
|
6
|
+
@hash_symbols = {
|
|
7
|
+
:zebras => true,
|
|
8
|
+
:options => {
|
|
9
|
+
:verbose => false,
|
|
10
|
+
},
|
|
11
|
+
:repos => {
|
|
12
|
+
:repo1 => {:path => "something"}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@hash_strings = {
|
|
17
|
+
'zebras' => true,
|
|
18
|
+
'options' => {
|
|
19
|
+
'verbose' => false,
|
|
20
|
+
},
|
|
21
|
+
'repos' => {
|
|
22
|
+
'repo1' => {'path' => "something"}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe Hash do
|
|
28
|
+
|
|
29
|
+
describe 'recursively_symbolize_keys!' do
|
|
30
|
+
it "should recursively convert a hash with string keys to a hash with symbol keys" do
|
|
31
|
+
@hash_symbols.should == @hash_strings.recursively_symbolize_keys!
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should handle hashes that are already symbolized" do
|
|
35
|
+
hash_copy = @hash_symbols.dup
|
|
36
|
+
hash_copy.should == @hash_symbols.recursively_symbolize_keys!
|
|
37
|
+
@hash_symbols[:repos][:repo1].should == {:path => "something"}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe 'to_conf' do
|
|
42
|
+
|
|
43
|
+
# Ruby 1.8
|
|
44
|
+
if RUBY_VERSION =~ /^1.8/
|
|
45
|
+
|
|
46
|
+
it "should convert a hash of symbolized keys to sorted YAML" do
|
|
47
|
+
@hash_symbols.to_conf.should == "--- \n:options: \n :verbose: false\n:repos: \n :repo1: \n :path: something\n:zebras: true\n"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should convert a hash of stringified keys to sorted YAML" do
|
|
51
|
+
@hash_strings.to_conf.should == "--- \noptions: \n verbose: false\nrepos: \n repo1: \n path: something\nzebras: true\n"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Ruby 1.9+
|
|
55
|
+
else
|
|
56
|
+
|
|
57
|
+
it "should convert a hash of symbolized keys to insertion order YAML" do
|
|
58
|
+
@hash_symbols.to_conf.should == "---\n:zebras: true\n:options:\n :verbose: false\n:repos:\n :repo1:\n :path: something\n"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should convert a hash of stringified keys to insertion order YAML" do
|
|
62
|
+
@hash_strings.to_conf.should == "---\nzebras: true\noptions:\n verbose: false\nrepos:\n repo1:\n path: something\n"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should force string encoding to UTF-8" do
|
|
66
|
+
h = {:num => 2000, :str1 => "hello".force_encoding("UTF-8"), :str2 => "world".force_encoding("ASCII-8BIT")}
|
|
67
|
+
h.to_conf.match(/\!binary \|/).should_not be_true
|
|
68
|
+
h.to_conf.should == "---\n:num: 2000\n:str1: hello\n:str2: world\n"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|