timecapsule 1.1.2 → 1.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.
- checksums.yaml +4 -4
 - data/Rakefile +4 -8
 - data/lib/timecapsule/tasks.rb +17 -0
 - data/lib/timecapsule/version.rb +1 -1
 - metadata +4 -7
 - data/test/helper.rb +0 -92
 - data/test/test_timecapsule.rb +0 -68
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 84c8cbbae9ae96154d8c9b14866a82a72f28a18c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6dd541ee2d72e5a6c03f1bceae915deab5fe77d6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2bf8faa5e51b9ffd9f2f353c85f5009b0e8773b4873b3190bfceeb9540520799aa3c6f1e075f5a1bbd15f3c905124be19859396b0f19ea375fbd384a5e428972
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 9f427e8326c747ee93265189c13457ec6e4c37dbd7f40b86e80af18d1a30b3567d7226c1caf933d031de3882da02c394eef526c9b93965a406e7c9ac32d1481d
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'bundler'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'rake'
         
     | 
| 
       5 
     | 
    
         
            -
            require ' 
     | 
| 
      
 5 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'rdoc/task'
         
     | 
| 
       7 
7 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       8 
8 
     | 
    
         
             
            require 'thread'
         
     | 
| 
         @@ -15,15 +15,11 @@ rescue Bundler::BundlerError => e 
     | 
|
| 
       15 
15 
     | 
    
         
             
              exit e.status_code
         
     | 
| 
       16 
16 
     | 
    
         
             
            end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:spec)
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
            task default: :spec
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              test.libs << 'lib' << 'test'
         
     | 
| 
       24 
     | 
    
         
            -
              test.pattern = 'test/**/test_*.rb'
         
     | 
| 
       25 
     | 
    
         
            -
              test.verbose = true
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
            Bundler::GemHelper.install_tasks
         
     | 
| 
       27 
23 
     | 
    
         | 
| 
       28 
24 
     | 
    
         
             
            Rake::RDocTask.new do |rdoc|
         
     | 
| 
       29 
25 
     | 
    
         
             
              version = File.exist?('VERSION') ? File.read('VERSION') : ''
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            namespace :timecapsule do
         
     | 
| 
      
 2 
     | 
    
         
            +
              model_list = Dir['app/models/*.rb'].map{ |file| File.basename(file, '.*') }
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              model_list.each do |klass|
         
     | 
| 
      
 5 
     | 
    
         
            +
                desc "Generates CSV dump of all #{klass} records"
         
     | 
| 
      
 6 
     | 
    
         
            +
                task klass.pluralize.to_sym => :environment do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  run_timecapsule_for(klass)
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def run_timecapsule_for(klass)
         
     | 
| 
      
 12 
     | 
    
         
            +
                Rails.application.eager_load!
         
     | 
| 
      
 13 
     | 
    
         
            +
                if ActiveRecord::Base.descendants.map(&:name).include? klass.classify
         
     | 
| 
      
 14 
     | 
    
         
            +
                  Timecapsule.export_model(klass.classify.constantize)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/timecapsule/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: timecapsule
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Renée Hendricksen
         
     | 
| 
         @@ -10,7 +10,7 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2015-12-08 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: activerecord
         
     | 
| 
         @@ -64,9 +64,8 @@ files: 
     | 
|
| 
       64 
64 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       65 
65 
     | 
    
         
             
            - lib/timecapsule.rb
         
     | 
| 
       66 
66 
     | 
    
         
             
            - lib/timecapsule/railtie.rb
         
     | 
| 
      
 67 
     | 
    
         
            +
            - lib/timecapsule/tasks.rb
         
     | 
| 
       67 
68 
     | 
    
         
             
            - lib/timecapsule/version.rb
         
     | 
| 
       68 
     | 
    
         
            -
            - test/helper.rb
         
     | 
| 
       69 
     | 
    
         
            -
            - test/test_timecapsule.rb
         
     | 
| 
       70 
69 
     | 
    
         
             
            homepage: https://github.com/nirds/timecapsule
         
     | 
| 
       71 
70 
     | 
    
         
             
            licenses:
         
     | 
| 
       72 
71 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -91,6 +90,4 @@ rubygems_version: 2.4.6 
     | 
|
| 
       91 
90 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       92 
91 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       93 
92 
     | 
    
         
             
            summary: gem for importing and exporting ActiveRecord data.
         
     | 
| 
       94 
     | 
    
         
            -
            test_files:
         
     | 
| 
       95 
     | 
    
         
            -
            - test/helper.rb
         
     | 
| 
       96 
     | 
    
         
            -
            - test/test_timecapsule.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
            test_files: []
         
     | 
    
        data/test/helper.rb
    DELETED
    
    | 
         @@ -1,92 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'rubygems'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'thread'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'active_record'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'active_support'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'rails'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            require 'bundler'
         
     | 
| 
       8 
     | 
    
         
            -
            begin
         
     | 
| 
       9 
     | 
    
         
            -
              Bundler.setup(:default, :development)
         
     | 
| 
       10 
     | 
    
         
            -
            rescue Bundler::BundlerError => e
         
     | 
| 
       11 
     | 
    
         
            -
              $stderr.puts e.message
         
     | 
| 
       12 
     | 
    
         
            -
              $stderr.puts 'Run `bundle install` to install missing gems'
         
     | 
| 
       13 
     | 
    
         
            -
              exit e.status_code
         
     | 
| 
       14 
     | 
    
         
            -
            end
         
     | 
| 
       15 
     | 
    
         
            -
            require 'test/unit'
         
     | 
| 
       16 
     | 
    
         
            -
            require 'shoulda'
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         
     | 
| 
       19 
     | 
    
         
            -
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            module Rails
         
     | 
| 
       22 
     | 
    
         
            -
              def self.root
         
     | 
| 
       23 
     | 
    
         
            -
                Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
            end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
            # ActiveRecord::Base.logger = ::Logger.new(StringIO.new)
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
            ENV['RAILS_ENV'] = 'test'
         
     | 
| 
       30 
     | 
    
         
            -
            ENV['RAILS_ROOT'] = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            require 'timecapsule'
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            class Timecapsule
         
     | 
| 
       35 
     | 
    
         
            -
              default_config = { import_directory: 'db/seed_data/',
         
     | 
| 
       36 
     | 
    
         
            -
                                 export_directory: 'db/seed_data/' }
         
     | 
| 
       37 
     | 
    
         
            -
              IMPORT_DIR ||= default_config[:import_directory]
         
     | 
| 
       38 
     | 
    
         
            -
              EXPORT_DIR ||= default_config[:export_directory]
         
     | 
| 
       39 
     | 
    
         
            -
              def self.check_for_and_make_directory(path)
         
     | 
| 
       40 
     | 
    
         
            -
                return true if File.exist?(path)
         
     | 
| 
       41 
     | 
    
         
            -
                path = Pathname.new(path)
         
     | 
| 
       42 
     | 
    
         
            -
                parent = path.parent
         
     | 
| 
       43 
     | 
    
         
            -
                Timecapsule.check_for_and_make_directory(parent) unless path.parent.parent.root?
         
     | 
| 
       44 
     | 
    
         
            -
                Dir.mkdir(path) unless File.exist?(path)
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
            end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
            ActiveRecord::Schema.define(version: 1) do
         
     | 
| 
       51 
     | 
    
         
            -
              create_table :users do |t|
         
     | 
| 
       52 
     | 
    
         
            -
                t.string :first_name
         
     | 
| 
       53 
     | 
    
         
            -
                t.string :last_name
         
     | 
| 
       54 
     | 
    
         
            -
                t.string :username
         
     | 
| 
       55 
     | 
    
         
            -
                t.string :password
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
              create_table :posts do |t|
         
     | 
| 
       59 
     | 
    
         
            -
                t.string :title
         
     | 
| 
       60 
     | 
    
         
            -
                t.string :body
         
     | 
| 
       61 
     | 
    
         
            -
                t.integer :user_id
         
     | 
| 
       62 
     | 
    
         
            -
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              create_table :names do |t|
         
     | 
| 
       65 
     | 
    
         
            -
                t.string :name
         
     | 
| 
       66 
     | 
    
         
            -
                t.string :other_name
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
     | 
    
         
            -
            end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            module ActiveRecord
         
     | 
| 
       71 
     | 
    
         
            -
              class Base
         
     | 
| 
       72 
     | 
    
         
            -
                def self.reset_pk_sequence
         
     | 
| 
       73 
     | 
    
         
            -
                  new_max = maximum(primary_key) || 0
         
     | 
| 
       74 
     | 
    
         
            -
                  update_seq_sql = "update sqlite_sequence set seq = #{new_max} where name = '#{table_name}';"
         
     | 
| 
       75 
     | 
    
         
            -
                  ActiveRecord::Base.connection.execute(update_seq_sql)
         
     | 
| 
       76 
     | 
    
         
            -
                end
         
     | 
| 
       77 
     | 
    
         
            -
              end
         
     | 
| 
       78 
     | 
    
         
            -
            end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
            class User < ActiveRecord::Base
         
     | 
| 
       81 
     | 
    
         
            -
              has_many :posts
         
     | 
| 
       82 
     | 
    
         
            -
            end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
            class Post < ActiveRecord::Base
         
     | 
| 
       85 
     | 
    
         
            -
              belongs_to :user
         
     | 
| 
       86 
     | 
    
         
            -
            end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
            class Name < ActiveRecord::Base
         
     | 
| 
       89 
     | 
    
         
            -
            end
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
            class Test::Unit::TestCase
         
     | 
| 
       92 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_timecapsule.rb
    DELETED
    
    | 
         @@ -1,68 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestTimecapsule < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
              def cleanup!
         
     | 
| 
       5 
     | 
    
         
            -
                cleanup_db!
         
     | 
| 
       6 
     | 
    
         
            -
                system "rm -rf #{Pathname.new(Timecapsule::EXPORT_DIR).parent}"
         
     | 
| 
       7 
     | 
    
         
            -
                system "rm -rf #{Timecapsule::EXPORT_DIR}"
         
     | 
| 
       8 
     | 
    
         
            -
                system "rm -rf #{Rails.root.join('config')}"
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              def cleanup_db!
         
     | 
| 
       12 
     | 
    
         
            -
                User.destroy_all
         
     | 
| 
       13 
     | 
    
         
            -
                Post.destroy_all
         
     | 
| 
       14 
     | 
    
         
            -
                Name.destroy_all
         
     | 
| 
       15 
     | 
    
         
            -
                User.reset_pk_sequence
         
     | 
| 
       16 
     | 
    
         
            -
                Post.reset_pk_sequence
         
     | 
| 
       17 
     | 
    
         
            -
                Name.reset_pk_sequence
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              should 'export a model' do
         
     | 
| 
       21 
     | 
    
         
            -
                Timecapsule.export_model(User)
         
     | 
| 
       22 
     | 
    
         
            -
                assert_equal true, File.exist?("#{Timecapsule::EXPORT_DIR}#{User.to_s.pluralize.underscore}.csv")
         
     | 
| 
       23 
     | 
    
         
            -
                cleanup!
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              should 'import a model' do
         
     | 
| 
       27 
     | 
    
         
            -
                User.create!(first_name: 'test', last_name: 'tester')
         
     | 
| 
       28 
     | 
    
         
            -
                assert_equal 1, User.count
         
     | 
| 
       29 
     | 
    
         
            -
                Timecapsule.export_model(User)
         
     | 
| 
       30 
     | 
    
         
            -
                cleanup_db!
         
     | 
| 
       31 
     | 
    
         
            -
                assert_equal 0, User.count
         
     | 
| 
       32 
     | 
    
         
            -
                Timecapsule.import_model(User)
         
     | 
| 
       33 
     | 
    
         
            -
                assert_equal 1, User.count
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal 'test', User.first.first_name
         
     | 
| 
       35 
     | 
    
         
            -
                cleanup!
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
              should 'import all the models' do
         
     | 
| 
       39 
     | 
    
         
            -
                u = User.create!(first_name: 'test', last_name: 'tester')
         
     | 
| 
       40 
     | 
    
         
            -
                Post.create!(title: 'Test Post', body: 'I like to test my gems!', user: u)
         
     | 
| 
       41 
     | 
    
         
            -
                assert_equal User.first, Post.first.user
         
     | 
| 
       42 
     | 
    
         
            -
                assert_equal 1, User.count
         
     | 
| 
       43 
     | 
    
         
            -
                assert_equal 1, Post.count
         
     | 
| 
       44 
     | 
    
         
            -
                Timecapsule.export_model(User, 1)
         
     | 
| 
       45 
     | 
    
         
            -
                Timecapsule.export_model(Post, 2)
         
     | 
| 
       46 
     | 
    
         
            -
                cleanup_db!
         
     | 
| 
       47 
     | 
    
         
            -
                assert_equal 0, User.count
         
     | 
| 
       48 
     | 
    
         
            -
                assert_equal 0, Post.count
         
     | 
| 
       49 
     | 
    
         
            -
                Timecapsule.import
         
     | 
| 
       50 
     | 
    
         
            -
                assert_equal 1, User.count
         
     | 
| 
       51 
     | 
    
         
            -
                assert_equal 1, Post.count
         
     | 
| 
       52 
     | 
    
         
            -
                assert_equal 'test', User.first.first_name
         
     | 
| 
       53 
     | 
    
         
            -
                assert_equal 'Test Post', Post.first.title
         
     | 
| 
       54 
     | 
    
         
            -
                assert_equal User.first, Post.first.user
         
     | 
| 
       55 
     | 
    
         
            -
                cleanup!
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
              should 'export part of a model' do
         
     | 
| 
       59 
     | 
    
         
            -
                u = User.create!(first_name: 'test', last_name: 'tester')
         
     | 
| 
       60 
     | 
    
         
            -
                Timecapsule.export_model(User, nil, { first_name: :name, last_name: :other_name }, 'name')
         
     | 
| 
       61 
     | 
    
         
            -
                cleanup_db!
         
     | 
| 
       62 
     | 
    
         
            -
                assert_equal true, File.exist?("#{Timecapsule::EXPORT_DIR}#{'name'.to_s.pluralize.underscore}.csv")
         
     | 
| 
       63 
     | 
    
         
            -
                Timecapsule.import
         
     | 
| 
       64 
     | 
    
         
            -
                assert_equal 1, Name.count
         
     | 
| 
       65 
     | 
    
         
            -
                assert_equal 'test', Name.first.name
         
     | 
| 
       66 
     | 
    
         
            -
                cleanup!
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
       68 
     | 
    
         
            -
            end
         
     |