Skip to content

Commit

Permalink
Allows asset copy when source and destination are the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Mar 5, 2013
1 parent 3bbba58 commit d2bfd14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/gutenberg/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def initialize(path, check_path = nil)
def copy(to)
subpath = File.basename @path.chomp(File.basename(@path))
FileUtils.mkdir_p "#{to}/#{subpath}"
FileUtils.cp @path, "#{to}/#{subpath}"
begin
FileUtils.cp @path, "#{to}/#{subpath}"
rescue ArgumentError => e
# For when the source and destination are the same
end
end
end
end
22 changes: 22 additions & 0 deletions spec/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,27 @@

Gutenberg::Asset.new("images/foo.png").copy "bar"
end

it "allows source and destination to be the same" do
File.stubs(:exists?).returns(true)
YAML.stubs(:load_file).returns({})

FileUtils.stubs(:mkdir_p)
FileUtils.stubs(:cp).raises(ArgumentError)

Gutenberg::Asset.new("images/foo.png").copy "images"
end

it "raises an exception when the destination is not found" do
File.stubs(:exists?).returns(true)
YAML.stubs(:load_file).returns({})

FileUtils.stubs(:mkdir_p)
FileUtils.stubs(:cp).raises(Errno::ENOENT)

proc {
Gutenberg::Asset.new("images/foo.png").copy("images")
}.must_raise Errno::ENOENT
end
end
end

0 comments on commit d2bfd14

Please sign in to comment.