sprig 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/README.md +27 -2
- data/lib/sprig.rb +17 -0
- data/lib/sprig/directive.rb +3 -3
- data/lib/sprig/seed/factory.rb +1 -1
- data/lib/sprig/version.rb +1 -1
- data/spec/adapters/active_record.rb +34 -0
- data/spec/adapters/mongoid.rb +19 -0
- data/spec/adapters/mongoid.yml +12 -0
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/models/{comment.rb → active_record/comment.rb} +0 -0
- data/spec/fixtures/models/{post.rb → active_record/post.rb} +0 -0
- data/spec/fixtures/models/{tag.rb → active_record/tag.rb} +0 -0
- data/spec/fixtures/models/{user.rb → active_record/user.rb} +0 -0
- data/spec/fixtures/models/mongoid/comment.rb +9 -0
- data/spec/fixtures/models/mongoid/post.rb +18 -0
- data/spec/fixtures/models/mongoid/tag.rb +7 -0
- data/spec/fixtures/models/mongoid/user.rb +9 -0
- data/spec/lib/generators/sprig/install_generator_spec.rb +2 -2
- data/spec/lib/sprig/directive_spec.rb +2 -2
- data/spec/lib/sprig_spec.rb +51 -0
- data/spec/spec_helper.rb +14 -26
- data/spec/sprig_spec.rb +38 -2
- metadata +36 -16
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e9deb6a8c1f64f83ed2fbeb9c4c7a7de28a90be5
         | 
| 4 | 
            +
              data.tar.gz: 38ab2e9a1eee0cd9a43f5578cd5a049859ae6a21
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b0dcb9273bb4bffb8cef23386f31e23bdfbbb5484a194a1809565514137b95ca6076927526d99d6f83779c280197c1c2d228dd9f94660869cbcaed8996870535
         | 
| 7 | 
            +
              data.tar.gz: afbc6277ada442ce7bd424b33abd4b7d38f8e02c7112c0e1281f5fdeac8c3ed0a45533746e04168664c5110875c87eece488d43a7b61835c3732d21d57ccc0be
         | 
    
        data/README.md
    CHANGED
    
    | @@ -32,7 +32,6 @@ Seed files are unique to the environment in which your Rails application is runn | |
| 32 32 |  | 
| 33 33 | 
             
            Todo: [Support for shared seed files]
         | 
| 34 34 |  | 
| 35 | 
            -
             | 
| 36 35 | 
             
            ##Seed files
         | 
| 37 36 |  | 
| 38 37 | 
             
            Hang your seed definitions on a `records` key for *yaml* and *json* files.
         | 
| @@ -74,6 +73,8 @@ records: | |
| 74 73 |  | 
| 75 74 | 
             
            Each seed record needs a `sprig_id` defined that must be *unique across all seed files per class*.  It can be an integer, string, whatever you prefer; as long as it is unique, Sprig can sort your seeds for insertion and detect any cyclic relationships.
         | 
| 76 75 |  | 
| 76 | 
            +
            ### Relationships
         | 
| 77 | 
            +
             | 
| 77 78 | 
             
            Create relationships between seed records with the `sprig_record` helper:
         | 
| 78 79 |  | 
| 79 80 | 
             
            ```yaml
         | 
| @@ -85,6 +86,28 @@ records: | |
| 85 86 | 
             
                body: "Yaml Comment body"
         | 
| 86 87 | 
             
            ```
         | 
| 87 88 |  | 
| 89 | 
            +
            #### Has and Belongs to Many
         | 
| 90 | 
            +
            For `has_and_belongs_to_many` (HABTM) relationships, you may define relation ids in array format. So if `Post` `has_and_belongs_to_many :tags`, you could write:
         | 
| 91 | 
            +
            ```yaml
         | 
| 92 | 
            +
            #posts.yml
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            records:
         | 
| 95 | 
            +
              - sprig_id: 1
         | 
| 96 | 
            +
                title: 'All About Brains'
         | 
| 97 | 
            +
                content: 'Lorem ipsum...'
         | 
| 98 | 
            +
                tag_ids:
         | 
| 99 | 
            +
                  - '<%= sprig_record(Tag, 1).id %>'
         | 
| 100 | 
            +
                  - '<%= sprig_record(Tag, 2).id %>'
         | 
| 101 | 
            +
            ```
         | 
| 102 | 
            +
            ```yaml
         | 
| 103 | 
            +
            #tags.yml
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            records:
         | 
| 106 | 
            +
              - sprig_id: 1
         | 
| 107 | 
            +
                name: 'Biology'
         | 
| 108 | 
            +
              - sprig_id: 2
         | 
| 109 | 
            +
                name: 'Neuroscience'
         | 
| 110 | 
            +
            ```
         | 
| 88 111 | 
             
            **Note: For namespaced or STI classes, you'll need to include the namespace with the class name in the seed file name. For example `Users::HeadManager` would need to be `users_head_managers.yml`**
         | 
| 89 112 |  | 
| 90 113 | 
             
            ### Special Options
         | 
| @@ -124,6 +147,8 @@ records: | |
| 124 147 | 
             
            If all your data is in `.wat` files, fear not. You can tell Sprig where to look for your data, and point it toward a custom parser class for turning your data into records. The example below tells Sprig to read `User` seed data from a Google Spreadsheet, and parse it accordingly.
         | 
| 125 148 |  | 
| 126 149 | 
             
            ```ruby
         | 
| 150 | 
            +
            require 'open-uri'
         | 
| 151 | 
            +
             | 
| 127 152 | 
             
            fanciness = {
         | 
| 128 153 | 
             
              :class  => User,
         | 
| 129 154 | 
             
              :source => open('https://spreadsheets.google.com/feeds/list/somerandomtoken/1/public/values?alt=json'),
         | 
| @@ -150,7 +175,7 @@ end | |
| 150 175 | 
             
            ## Populate Seed Files from Database
         | 
| 151 176 |  | 
| 152 177 | 
             
            Want to create Sprig seed files from the records in your database? Well,
         | 
| 153 | 
            -
            [Sprig::Reap]( | 
| 178 | 
            +
            [Sprig::Reap](https://rubygems.org/gems/sprig-reap) can create them for you! Check out the gem's
         | 
| 154 179 | 
             
            [README](https://github.com/vigetlabs/sprig-reap#sprigreap) for installation instructions and
         | 
| 155 180 | 
             
            details on usage.
         | 
| 156 181 |  | 
    
        data/lib/sprig.rb
    CHANGED
    
    | @@ -19,6 +19,23 @@ module Sprig | |
| 19 19 | 
             
              autoload :Seed,                 'sprig/seed'
         | 
| 20 20 |  | 
| 21 21 | 
             
              class << self
         | 
| 22 | 
            +
                attr_writer :adapter
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def adapter
         | 
| 25 | 
            +
                  @adapter ||= :active_record
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def adapter_model_class
         | 
| 29 | 
            +
                  @adapter_model_class ||= case adapter
         | 
| 30 | 
            +
                  when :active_record
         | 
| 31 | 
            +
                    ActiveRecord::Base
         | 
| 32 | 
            +
                  when :mongoid
         | 
| 33 | 
            +
                    Mongoid::Document
         | 
| 34 | 
            +
                  else
         | 
| 35 | 
            +
                    raise "Unknown model class for adapter #{adapter}"
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 22 39 | 
             
                def configuration
         | 
| 23 40 | 
             
                  @@configuration ||= Sprig::Configuration.new
         | 
| 24 41 | 
             
                end
         | 
    
        data/lib/sprig/directive.rb
    CHANGED
    
    | @@ -7,7 +7,7 @@ module Sprig | |
| 7 7 | 
             
                    case
         | 
| 8 8 | 
             
                    when args.is_a?(Hash)
         | 
| 9 9 | 
             
                      args
         | 
| 10 | 
            -
                    when args.is_a?(Class) && args <  | 
| 10 | 
            +
                    when args.is_a?(Class) && args < Sprig.adapter_model_class
         | 
| 11 11 | 
             
                      { :class => args }
         | 
| 12 12 | 
             
                    else
         | 
| 13 13 | 
             
                      raise ArgumentError, argument_error_message
         | 
| @@ -30,8 +30,8 @@ module Sprig | |
| 30 30 | 
             
                private
         | 
| 31 31 |  | 
| 32 32 | 
             
                def argument_error_message
         | 
| 33 | 
            -
                  'Sprig::Directive must be instantiated with  | 
| 34 | 
            -
                   | 
| 33 | 
            +
                  'Sprig::Directive must be instantiated with a(n) '\
         | 
| 34 | 
            +
                  "#{Sprig.adapter_model_class} class or a Hash with :class defined"
         | 
| 35 35 | 
             
                end
         | 
| 36 36 | 
             
              end
         | 
| 37 37 | 
             
            end
         | 
    
        data/lib/sprig/seed/factory.rb
    CHANGED
    
    | @@ -30,7 +30,7 @@ module Sprig | |
| 30 30 | 
             
                  def klass=(klass)
         | 
| 31 31 | 
             
                    raise ArgumentError, 'Must provide a Class as first argument' unless klass.is_a? Class
         | 
| 32 32 |  | 
| 33 | 
            -
                    klass.reset_column_information
         | 
| 33 | 
            +
                    klass.reset_column_information if defined?(ActiveRecord) && klass < ActiveRecord::Base
         | 
| 34 34 | 
             
                    @klass = klass
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
    
        data/lib/sprig/version.rb
    CHANGED
    
    
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require "database_cleaner"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.configure do |c|
         | 
| 4 | 
            +
              c.before(:suite) do
         | 
| 5 | 
            +
                DatabaseCleaner[:active_record].strategy = :transaction
         | 
| 6 | 
            +
                DatabaseCleaner[:active_record].clean_with(:truncation)
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              c.before(:each) do
         | 
| 10 | 
            +
                DatabaseCleaner[:active_record].start
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              c.after(:each) do
         | 
| 14 | 
            +
                DatabaseCleaner[:active_record].clean
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # Database
         | 
| 19 | 
            +
            ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "spec/db/activerecord.db")
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            User.connection.execute "DROP TABLE IF EXISTS users;"
         | 
| 22 | 
            +
            User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255));"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            Post.connection.execute "DROP TABLE IF EXISTS posts;"
         | 
| 25 | 
            +
            Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR(255), content VARCHAR(255), photo VARCHAR(255), published BOOLEAN , user_id INTEGER);"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            Comment.connection.execute "DROP TABLE IF EXISTS comments;"
         | 
| 28 | 
            +
            Comment.connection.execute "CREATE TABLE comments (id INTEGER PRIMARY KEY , post_id INTEGER, body VARCHAR(255));"
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            Tag.connection.execute "DROP TABLE IF EXISTS tags;"
         | 
| 31 | 
            +
            Tag.connection.execute "CREATE TABLE tags (id INTEGER PRIMARY KEY , name VARCHAR(255));"
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Tag.connection.execute "DROP TABLE IF EXISTS posts_tags;"
         | 
| 34 | 
            +
            Tag.connection.execute "CREATE TABLE posts_tags (id INTEGER PRIMARY KEY , post_id INTEGER, tag_id INTEGER);"
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require "database_cleaner"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec.configure do |c|
         | 
| 4 | 
            +
              c.before(:suite) do
         | 
| 5 | 
            +
                DatabaseCleaner[:mongoid].strategy = :truncation
         | 
| 6 | 
            +
                DatabaseCleaner[:mongoid].clean_with(:truncation)
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              c.before(:each) do
         | 
| 10 | 
            +
                DatabaseCleaner[:mongoid].start
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              c.after(:each) do
         | 
| 14 | 
            +
                DatabaseCleaner[:mongoid].clean
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # Datastore
         | 
| 19 | 
            +
            Mongoid.load!(File.join File.dirname(__FILE__), 'mongoid.yml')
         | 
    
        data/spec/db/activerecord.db
    CHANGED
    
    | Binary file | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            class Post
         | 
| 2 | 
            +
              include Mongoid::Document
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              if Mongoid::VERSION.split('.').first == "3"
         | 
| 5 | 
            +
                field :user_id,   :type => Moped::BSON::ObjectId
         | 
| 6 | 
            +
              else
         | 
| 7 | 
            +
                field :user_id,   :type => BSON::ObjectId
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
              field :title,     :type => String
         | 
| 10 | 
            +
              field :content,   :type => String
         | 
| 11 | 
            +
              field :published, :type => Boolean
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              has_and_belongs_to_many :tags
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def photo=(file)
         | 
| 16 | 
            +
                write_attribute(:photo, File.basename(file.path))
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 | 
             
            require 'generators/sprig/install_generator'
         | 
| 3 3 |  | 
| 4 | 
            -
            describe Sprig::Generators::InstallGenerator do
         | 
| 4 | 
            +
            describe Sprig::Generators::InstallGenerator, type: :generator do
         | 
| 5 5 | 
             
              destination File.expand_path("../../tmp", __FILE__)
         | 
| 6 6 |  | 
| 7 7 | 
             
              before do
         | 
| @@ -29,7 +29,7 @@ end | |
| 29 29 | 
             
            # Generator arguments are set on a class basis. We need to open
         | 
| 30 30 | 
             
            # a new describe block to make these examples work.
         | 
| 31 31 |  | 
| 32 | 
            -
            describe Sprig::Generators::InstallGenerator do
         | 
| 32 | 
            +
            describe Sprig::Generators::InstallGenerator, type: :generator do
         | 
| 33 33 | 
             
              context "with arguments" do
         | 
| 34 34 | 
             
                destination File.expand_path("../../tmp", __FILE__)
         | 
| 35 35 | 
             
                arguments %w(development test integration)
         | 
| @@ -34,8 +34,8 @@ describe Sprig::Directive do | |
| 34 34 | 
             
                      subject.klass
         | 
| 35 35 | 
             
                    }.to raise_error(
         | 
| 36 36 | 
             
                      ArgumentError,
         | 
| 37 | 
            -
                      'Sprig::Directive must be instantiated with  | 
| 38 | 
            -
                       | 
| 37 | 
            +
                      'Sprig::Directive must be instantiated with a(n) '\
         | 
| 38 | 
            +
                      "#{Sprig.adapter_model_class} class or a Hash with :class defined"
         | 
| 39 39 | 
             
                    )
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 | 
             
                end
         | 
    
        data/spec/lib/sprig_spec.rb
    CHANGED
    
    | @@ -7,6 +7,57 @@ describe Sprig do | |
| 7 7 | 
             
                Sprig::Configuration.stub(:new).and_return(configuration)
         | 
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| 10 | 
            +
              describe '.adapter' do
         | 
| 11 | 
            +
                it { expect(described_class).to respond_to(:adapter).with(0).arguments }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                it { expect(described_class.adapter).not_to be nil }
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              describe '.adapter=' do
         | 
| 17 | 
            +
                let(:value) { :mongo_mapper }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                around(:each) do |example|
         | 
| 20 | 
            +
                  previous_value = described_class.adapter
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  example.run
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  described_class.adapter = previous_value
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it { expect(described_class).to respond_to(:adapter=).with(1).argument }
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                it 'changes the value' do
         | 
| 30 | 
            +
                  expect { described_class.adapter = value }.to change(described_class, :adapter).to(value)
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              describe '.adapter_model_class' do
         | 
| 35 | 
            +
                let(:expected_class) do
         | 
| 36 | 
            +
                  case Sprig.adapter
         | 
| 37 | 
            +
                  when :active_record
         | 
| 38 | 
            +
                    ActiveRecord::Base
         | 
| 39 | 
            +
                  when :mongoid
         | 
| 40 | 
            +
                    Mongoid::Document
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                before(:each) { described_class.instance_variable_set(:@adapter_model_class, nil) }
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                it { expect(described_class).to respond_to(:adapter_model_class).with(0).arguments }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                it { expect(described_class.adapter_model_class).to be expected_class }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                describe 'with an unrecognized adapter' do
         | 
| 51 | 
            +
                  let(:value) { :mongo_mapper }
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  it 'raises an error' do
         | 
| 54 | 
            +
                    allow(described_class).to receive(:adapter).and_return(value)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    expect { described_class.adapter_model_class }.to raise_error(/unknown model class/i)
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 10 61 | 
             
              describe ".configuration" do
         | 
| 11 62 | 
             
                context "when there is not yet a Configuration instance" do
         | 
| 12 63 | 
             
                  it "returns a new Configuration instance" do
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -7,8 +7,6 @@ SimpleCov.formatter = Coveralls::SimpleCov::Formatter | |
| 7 7 | 
             
            SimpleCov.start "rails"
         | 
| 8 8 |  | 
| 9 9 | 
             
            require "rails"
         | 
| 10 | 
            -
            require "active_record"
         | 
| 11 | 
            -
            require "database_cleaner"
         | 
| 12 10 | 
             
            require "webmock"
         | 
| 13 11 | 
             
            require "vcr"
         | 
| 14 12 | 
             
            require "pry"
         | 
| @@ -17,25 +15,13 @@ require "generator_spec" | |
| 17 15 | 
             
            require "sprig"
         | 
| 18 16 | 
             
            include Sprig::Helpers
         | 
| 19 17 |  | 
| 20 | 
            -
            Dir[File.dirname(__FILE__) + '/fixtures/models/*.rb'].each {|file| require file }
         | 
| 21 18 | 
             
            Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|file| require file}
         | 
| 22 19 |  | 
| 23 20 | 
             
            RSpec.configure do |c|
         | 
| 24 21 | 
             
              c.include ColoredText
         | 
| 25 22 | 
             
              c.include LoggerMock
         | 
| 26 23 |  | 
| 27 | 
            -
              c.before(:suite) do
         | 
| 28 | 
            -
                DatabaseCleaner.strategy = :transaction
         | 
| 29 | 
            -
                DatabaseCleaner.clean_with(:truncation)
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              c.before(:each) do
         | 
| 33 | 
            -
                DatabaseCleaner.start
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 24 | 
             
              c.after(:each) do
         | 
| 37 | 
            -
                DatabaseCleaner.clean
         | 
| 38 | 
            -
             | 
| 39 25 | 
             
                Sprig.reset_configuration
         | 
| 40 26 | 
             
              end
         | 
| 41 27 | 
             
            end
         | 
| @@ -46,23 +32,25 @@ VCR.configure do |c| | |
| 46 32 | 
             
              c.hook_into :webmock
         | 
| 47 33 | 
             
            end
         | 
| 48 34 |  | 
| 49 | 
            -
            #  | 
| 50 | 
            -
             | 
| 35 | 
            +
            # ActiveRecord (via SQlite3)
         | 
| 36 | 
            +
            begin
         | 
| 37 | 
            +
              require 'active_record'
         | 
| 38 | 
            +
              require 'sqlite3'
         | 
| 51 39 |  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 40 | 
            +
              Sprig.adapter = :active_record
         | 
| 41 | 
            +
            rescue LoadError; end
         | 
| 54 42 |  | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 43 | 
            +
            # Mongoid
         | 
| 44 | 
            +
            begin
         | 
| 45 | 
            +
              require 'mongoid'
         | 
| 57 46 |  | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 47 | 
            +
              Sprig.adapter = :mongoid
         | 
| 48 | 
            +
            rescue LoadError; end
         | 
| 60 49 |  | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 50 | 
            +
            # Require model files.
         | 
| 51 | 
            +
            Dir[File.dirname(__FILE__) + "/fixtures/models/#{Sprig.adapter}/*.rb"].each {|file| require file}
         | 
| 63 52 |  | 
| 64 | 
            -
             | 
| 65 | 
            -
            Tag.connection.execute "CREATE TABLE posts_tags (id INTEGER PRIMARY KEY , post_id INTEGER, tag_id INTEGER);"
         | 
| 53 | 
            +
            require "adapters/#{Sprig.adapter}.rb"
         | 
| 66 54 |  | 
| 67 55 | 
             
            # Helpers
         | 
| 68 56 | 
             
            #
         | 
    
        data/spec/sprig_spec.rb
    CHANGED
    
    | @@ -2,6 +2,14 @@ require 'spec_helper' | |
| 2 2 | 
             
            require 'open-uri'
         | 
| 3 3 |  | 
| 4 4 | 
             
            describe "Seeding an application" do
         | 
| 5 | 
            +
              let(:missing_record_error) do
         | 
| 6 | 
            +
                if defined?(ActiveRecord) && Post < ActiveRecord::Base
         | 
| 7 | 
            +
                  ActiveRecord::RecordNotFound
         | 
| 8 | 
            +
                elsif defined?(Mongoid) && Post < Mongoid::Document
         | 
| 9 | 
            +
                  Mongoid::Errors::DocumentNotFound
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 5 13 | 
             
              before do
         | 
| 6 14 | 
             
                stub_rails_root
         | 
| 7 15 | 
             
              end
         | 
| @@ -272,7 +280,7 @@ describe "Seeding an application" do | |
| 272 280 | 
             
              end
         | 
| 273 281 |  | 
| 274 282 | 
             
              context "with a malformed directive" do
         | 
| 275 | 
            -
                let(:expected_error_message) {  | 
| 283 | 
            +
                let(:expected_error_message) { "Sprig::Directive must be instantiated with a(n) #{Sprig.adapter_model_class} class or a Hash with :class defined" }
         | 
| 276 284 |  | 
| 277 285 | 
             
                context "including a class that is not a subclass of AR" do
         | 
| 278 286 | 
             
                  it "raises an argument error" do
         | 
| @@ -327,7 +335,7 @@ describe "Seeding an application" do | |
| 327 335 |  | 
| 328 336 | 
             
                      expect {
         | 
| 329 337 | 
             
                        existing_match.reload
         | 
| 330 | 
            -
                      }.to raise_error( | 
| 338 | 
            +
                      }.to raise_error(missing_record_error)
         | 
| 331 339 |  | 
| 332 340 | 
             
                      expect {
         | 
| 333 341 | 
             
                        existing_nonmatch.reload
         | 
| @@ -408,5 +416,33 @@ describe "Seeding an application" do | |
| 408 416 | 
             
                    end
         | 
| 409 417 | 
             
                  end
         | 
| 410 418 | 
             
                end
         | 
| 419 | 
            +
             | 
| 420 | 
            +
                context "defined within the directive" do
         | 
| 421 | 
            +
                  let!(:existing) do
         | 
| 422 | 
            +
                    Post.create(
         | 
| 423 | 
            +
                      :title    => "Yaml title",
         | 
| 424 | 
            +
                      :content  => "Existing content")
         | 
| 425 | 
            +
                  end
         | 
| 426 | 
            +
             | 
| 427 | 
            +
                  around do |example|
         | 
| 428 | 
            +
                    load_seeds('posts.yml', &example)
         | 
| 429 | 
            +
                  end
         | 
| 430 | 
            +
             | 
| 431 | 
            +
                  it "respects the directive option" do
         | 
| 432 | 
            +
                    sprig [
         | 
| 433 | 
            +
                      {
         | 
| 434 | 
            +
                        :class   => Post,
         | 
| 435 | 
            +
                        :source  => open("spec/fixtures/seeds/test/posts.yml"),
         | 
| 436 | 
            +
                        :delete_existing_by => :title
         | 
| 437 | 
            +
                      }
         | 
| 438 | 
            +
                    ]
         | 
| 439 | 
            +
             | 
| 440 | 
            +
                    Post.count.should == 1
         | 
| 441 | 
            +
             | 
| 442 | 
            +
                    expect {
         | 
| 443 | 
            +
                      existing.reload
         | 
| 444 | 
            +
                    }.to raise_error(missing_record_error)
         | 
| 445 | 
            +
                  end
         | 
| 446 | 
            +
                end
         | 
| 411 447 | 
             
              end
         | 
| 412 448 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sprig
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Lawson Kurtz
         | 
| @@ -9,36 +9,42 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2015-03-20 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            -
              name:  | 
| 15 | 
            +
              name: appraisal
         | 
| 16 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                requirements:
         | 
| 18 18 | 
             
                - - ~>
         | 
| 19 19 | 
             
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            -
                    version: ' | 
| 20 | 
            +
                    version: '1.0'
         | 
| 21 | 
            +
                - - '>='
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 23 | 
            +
                    version: 1.0.3
         | 
| 21 24 | 
             
              type: :development
         | 
| 22 25 | 
             
              prerelease: false
         | 
| 23 26 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 27 | 
             
                requirements:
         | 
| 25 28 | 
             
                - - ~>
         | 
| 26 29 | 
             
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            -
                    version: ' | 
| 30 | 
            +
                    version: '1.0'
         | 
| 31 | 
            +
                - - '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 1.0.3
         | 
| 28 34 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 29 | 
            -
              name:  | 
| 35 | 
            +
              name: rails
         | 
| 30 36 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 31 37 | 
             
                requirements:
         | 
| 32 38 | 
             
                - - ~>
         | 
| 33 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            -
                    version:  | 
| 40 | 
            +
                    version: '3.1'
         | 
| 35 41 | 
             
              type: :development
         | 
| 36 42 | 
             
              prerelease: false
         | 
| 37 43 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 44 | 
             
                requirements:
         | 
| 39 45 | 
             
                - - ~>
         | 
| 40 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            -
                    version:  | 
| 47 | 
            +
                    version: '3.1'
         | 
| 42 48 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 43 49 | 
             
              name: rspec
         | 
| 44 50 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -193,16 +199,23 @@ files: | |
| 193 199 | 
             
            - lib/sprig/sprig_record_store.rb
         | 
| 194 200 | 
             
            - lib/sprig/tsortable_hash.rb
         | 
| 195 201 | 
             
            - lib/sprig/version.rb
         | 
| 202 | 
            +
            - spec/adapters/active_record.rb
         | 
| 203 | 
            +
            - spec/adapters/mongoid.rb
         | 
| 204 | 
            +
            - spec/adapters/mongoid.yml
         | 
| 196 205 | 
             
            - spec/db/activerecord.db
         | 
| 197 206 | 
             
            - spec/feature/configurations_spec.rb
         | 
| 198 207 | 
             
            - spec/fixtures/cassettes/google_spreadsheet_json_posts.yml
         | 
| 199 208 | 
             
            - spec/fixtures/config/environments/development.rb
         | 
| 200 209 | 
             
            - spec/fixtures/config/environments/production.rb
         | 
| 201 210 | 
             
            - spec/fixtures/config/environments/test.rb
         | 
| 202 | 
            -
            - spec/fixtures/models/comment.rb
         | 
| 203 | 
            -
            - spec/fixtures/models/post.rb
         | 
| 204 | 
            -
            - spec/fixtures/models/tag.rb
         | 
| 205 | 
            -
            - spec/fixtures/models/user.rb
         | 
| 211 | 
            +
            - spec/fixtures/models/active_record/comment.rb
         | 
| 212 | 
            +
            - spec/fixtures/models/active_record/post.rb
         | 
| 213 | 
            +
            - spec/fixtures/models/active_record/tag.rb
         | 
| 214 | 
            +
            - spec/fixtures/models/active_record/user.rb
         | 
| 215 | 
            +
            - spec/fixtures/models/mongoid/comment.rb
         | 
| 216 | 
            +
            - spec/fixtures/models/mongoid/post.rb
         | 
| 217 | 
            +
            - spec/fixtures/models/mongoid/tag.rb
         | 
| 218 | 
            +
            - spec/fixtures/models/mongoid/user.rb
         | 
| 206 219 | 
             
            - spec/fixtures/seeds/staging/posts.yml
         | 
| 207 220 | 
             
            - spec/fixtures/seeds/test/comments.yml
         | 
| 208 221 | 
             
            - spec/fixtures/seeds/test/files/cat.png
         | 
| @@ -263,16 +276,23 @@ signing_key: | |
| 263 276 | 
             
            specification_version: 4
         | 
| 264 277 | 
             
            summary: Relational, environment-specific seeding for Rails apps.
         | 
| 265 278 | 
             
            test_files:
         | 
| 279 | 
            +
            - spec/adapters/active_record.rb
         | 
| 280 | 
            +
            - spec/adapters/mongoid.rb
         | 
| 281 | 
            +
            - spec/adapters/mongoid.yml
         | 
| 266 282 | 
             
            - spec/db/activerecord.db
         | 
| 267 283 | 
             
            - spec/feature/configurations_spec.rb
         | 
| 268 284 | 
             
            - spec/fixtures/cassettes/google_spreadsheet_json_posts.yml
         | 
| 269 285 | 
             
            - spec/fixtures/config/environments/development.rb
         | 
| 270 286 | 
             
            - spec/fixtures/config/environments/production.rb
         | 
| 271 287 | 
             
            - spec/fixtures/config/environments/test.rb
         | 
| 272 | 
            -
            - spec/fixtures/models/comment.rb
         | 
| 273 | 
            -
            - spec/fixtures/models/post.rb
         | 
| 274 | 
            -
            - spec/fixtures/models/tag.rb
         | 
| 275 | 
            -
            - spec/fixtures/models/user.rb
         | 
| 288 | 
            +
            - spec/fixtures/models/active_record/comment.rb
         | 
| 289 | 
            +
            - spec/fixtures/models/active_record/post.rb
         | 
| 290 | 
            +
            - spec/fixtures/models/active_record/tag.rb
         | 
| 291 | 
            +
            - spec/fixtures/models/active_record/user.rb
         | 
| 292 | 
            +
            - spec/fixtures/models/mongoid/comment.rb
         | 
| 293 | 
            +
            - spec/fixtures/models/mongoid/post.rb
         | 
| 294 | 
            +
            - spec/fixtures/models/mongoid/tag.rb
         | 
| 295 | 
            +
            - spec/fixtures/models/mongoid/user.rb
         | 
| 276 296 | 
             
            - spec/fixtures/seeds/staging/posts.yml
         | 
| 277 297 | 
             
            - spec/fixtures/seeds/test/comments.yml
         | 
| 278 298 | 
             
            - spec/fixtures/seeds/test/files/cat.png
         |