Skip to content

Commit

Permalink
Adds support for symlinks as seedfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
duksis committed Oct 12, 2015
1 parent 695a1a3 commit ebdcc46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/sprig/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def initialize(table_name)
end

def file
File.new(seed_directory.join(filename))
File.new(filepath)
end

private
Expand All @@ -78,6 +78,15 @@ def filename
available_files.detect {|name| name =~ /^#{table_name}\./ } || file_not_found
end

def filepath
path = seed_directory.join(filename)
if File.symlink?(path)
File.readlink(path)
else
path
end
end

def available_files
Dir.entries(seed_directory)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/sprig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@
end
end

context "with a symlinked file" do
let(:env) { Rails.env }

around do |example|
`ln -s ./spec/fixtures/seeds/#{env}/posts.yml ./spec/fixtures/db/seeds/#{env}`
example.call
`rm ./spec/fixtures/db/seeds/#{env}/posts.yml`
end

it "seeds the db" do
sprig [Post]

Post.count.should == 1
Post.pluck(:title).should =~ ['Yaml title']
end
end

context "with a google spreadsheet" do
it "seeds the db", :vcr => { :cassette_name => 'google_spreadsheet_json_posts' } do
sprig [
Expand Down

0 comments on commit ebdcc46

Please sign in to comment.