inheritable_fixtures 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5cf907d5ad4f16706ce69b5387408bda6502b68
4
+ data.tar.gz: 866cd601138e6a7b7600a33cbdec62fabde391f7
5
+ SHA512:
6
+ metadata.gz: 6dcb8a183bc6229184e90fc2c9de532021dc3d8ee4606452f52c3fa7511b4ae18446795a3001537f703e994df91e4753a364ac508940362f01fcd11cb612d134
7
+ data.tar.gz: b6dc384607561a236fc7f54e612088669c68df89bce4c8fbdb23e91f9bab4f0b7e1ce29c2273a8ad46d24726a6740641720839052abb91b0be6541d87a5c9556
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.2
5
+ script:
6
+ - RAILS_ENV=test bundle exec rake --trace db:create db:migrate test
7
+ gemfile:
8
+ - gemfiles/rails40.gemfile
9
+ - gemfiles/rails41.gemfile
10
+ - gemfiles/rails42.gemfile
data/Appraisals ADDED
@@ -0,0 +1,10 @@
1
+ appraise "rails40" do
2
+ gem "rails", '4.0.13'
3
+ end
4
+ appraise "rails41" do
5
+ gem "rails", '4.1.12'
6
+ end
7
+ appraise "rails42" do
8
+ gem "rails", '4.2.1'
9
+ end
10
+
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'appraisal', '~> 2.0'
6
+ gem 'bundler'
7
+ gem 'minitest'
8
+ gem 'sqlite3'
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # InheritableFixtures
2
+
3
+ [![GitHub version](https://badge.fury.io/gh/appfolio%2Finheritable_fixtures.svg)](http://badge.fury.io/gh/appfolio%2Finheritable_fixtures)
4
+ [![Build Status](https://travis-ci.org/appfolio/inheritable_fixtures.svg?branch=master)](https://travis-ci.org/appfolio/inheritable_fixtures)
5
+
6
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/inheritable_fixtures`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+
8
+ TODO: Delete this and the text above, and describe your gem
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'inheritable_fixtures'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install inheritable_fixtures
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/inheritable_fixtures/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rake/testtask'
5
+ require 'bundler/gem_tasks'
6
+
7
+ APP_RAKEFILE = File.expand_path("../test/test_app/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << "test"
12
+ t.pattern = 'test/**/*_test.rb'
13
+ end
14
+
15
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "inheritable_fixtures"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.0"
6
+ gem "bundler"
7
+ gem "minitest"
8
+ gem "sqlite3"
9
+ gem "rails", "4.0.13"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.0"
6
+ gem "bundler"
7
+ gem "minitest"
8
+ gem "sqlite3"
9
+ gem "rails", "4.1.12"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.0"
6
+ gem "bundler"
7
+ gem "minitest"
8
+ gem "sqlite3"
9
+ gem "rails", "4.2.1"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'inheritable_fixtures/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "inheritable_fixtures"
8
+ spec.version = InheritableFixtures::VERSION
9
+ spec.authors = ["Paul Kmiec"]
10
+ spec.email = ["paul.kmiec@appfolio.com"]
11
+
12
+ spec.required_ruby_version = '>= 2.0.0'
13
+
14
+ spec.summary = %q{Allows fixtures from engines to be inherited by applications}
15
+ spec.description = %q{Allows fixtures from engines to be inherited by applications}
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rails", "~> 4.0"
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails'
2
+ require 'inheritable_fixtures/version'
3
+
4
+ module InheritableFixtures
5
+ # Your code goes here...
6
+ end
7
+
8
+ require 'inheritable_fixtures/rails_extensions/engine'
9
+ require 'inheritable_fixtures/rails_extensions/engine_configuration'
10
+ require 'inheritable_fixtures/rails_extensions/test_fixtures'
11
+ require 'inheritable_fixtures/rails_extensions/test_process'
12
+ require 'inheritable_fixtures/engine'
13
+
14
+ require 'rails/engine'
15
+ require 'rails/engine/configuration'
16
+ require 'active_record/fixtures'
17
+ require 'action_dispatch/testing/test_process'
18
+
19
+ module ActiveRecord
20
+ module TestFixtures
21
+ class << self
22
+ prepend ::InheritableFixtures::RailsExtensions::TestFixtures
23
+ end
24
+ end
25
+ end
26
+
27
+ module ActionDispatch
28
+ module TestProcess
29
+ prepend ::InheritableFixtures::RailsExtensions::TestProcess
30
+ end
31
+ end
32
+
33
+ Rails::Engine::Configuration.prepend(::InheritableFixtures::RailsExtensions::EngineConfiguration)
34
+ Rails::Engine.include(::InheritableFixtures::RailsExtensions::Engine)
35
+
@@ -0,0 +1,9 @@
1
+ module InheritableFixtures
2
+ class Engine < Rails::Engine
3
+ config.fixtures_paths = []
4
+
5
+ rake_tasks do
6
+ load File.expand_path("../rails_extensions/db_fixtures.rake", __FILE__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ Rake::Task['db:fixtures:load'].clear_actions
2
+
3
+ namespace :db do
4
+ namespace :fixtures do
5
+ # This is heavily based on the original implementation in rails. It handles FIXTURES, FIXTURES_PATH,
6
+ # and FIXTURES_DIR arguments just like the original but it searches for fixtures in all fixtures
7
+ # paths.
8
+ task :load do
9
+ require 'active_record/fixtures'
10
+
11
+ fixtures_paths = if ENV['FIXTURES_PATH']
12
+ [ Rails.root.join(ENV['FIXTURES_PATH'] || %w{test fixtures}).to_s ]
13
+ else
14
+ [ ActiveRecord::Tasks::DatabaseTasks.fixtures_path ] + Rails.application.config.fixtures_paths
15
+ end
16
+
17
+ fixtures_to_load = ENV['FIXTURES'] ? ENV['FIXTURES'].split(',') : nil
18
+
19
+ fixtures_paths.each do |base_dir|
20
+ fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
21
+ Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }.each do |fixture_file|
22
+ if fixtures_to_load
23
+ if fixtures_to_load.include?(fixture_file)
24
+ fixtures_to_load.delete(fixture_file)
25
+ else
26
+ next
27
+ end
28
+ end
29
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_file)
30
+ end
31
+ end
32
+
33
+ if fixtures_to_load
34
+ if !fixtures_to_load.empty?
35
+ raise "Fixtures #{fixtures_to_load.inspect} not found in any fixtures path #{fixtures_paths.inspect}"
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module InheritableFixtures
2
+ module RailsExtensions
3
+ module Engine
4
+ def self.included(target)
5
+ target.class_eval do
6
+ initializer :append_fixtures_paths, group: :all do |app|
7
+ app.config.fixtures_paths.unshift(*paths["lib/test/fixtures"].existent_directories)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,15 @@
1
+ module InheritableFixtures
2
+ module RailsExtensions
3
+ module EngineConfiguration
4
+ def paths
5
+ @paths ||= begin
6
+ paths = super
7
+ paths.add("lib/test/fixtures")
8
+ paths
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,52 @@
1
+ module InheritableFixtures
2
+ module RailsExtensions
3
+ module TestFixtures
4
+
5
+ def included(target)
6
+ super
7
+ target.send(:include, InstanceMethods)
8
+ target.send(:extend, ClassMethods)
9
+ target.class_eval do
10
+ class_attribute :fixture_table_names_per_path, :instance_writer => false
11
+ self.fixture_table_names_per_path = {}
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+ def fixtures(*fixture_set_names)
17
+ original_fixture_path = self.fixture_path
18
+
19
+ paths = ([ self.fixture_path ] + Rails.application.config.fixtures_paths)
20
+ paths.each do |path|
21
+ self.fixture_path = path
22
+ self.fixture_table_names = []
23
+ super
24
+ self.fixture_table_names_per_path[path] = self.fixture_table_names
25
+ end
26
+
27
+ ensure
28
+ self.fixture_path = original_fixture_path
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+ private
34
+
35
+ def load_fixtures(*args)
36
+ if defined?(ActiveRecord::FixtureSet) # rails 4.x
37
+ fixtures_class = ActiveRecord::FixtureSet
38
+ end
39
+ raise "do not know how to monkey patch fixtures .. what version of rails are you using?" unless fixtures_class
40
+
41
+ fixtures = []
42
+ fixture_table_names_per_path.each do |fixture_path, fixture_table_names|
43
+ fixture_args = [ fixture_path, fixture_table_names, fixture_class_names] + args
44
+ fixtures += fixtures_class.create_fixtures(*fixture_args)
45
+ end
46
+ Hash[fixtures.map { |f| [f.name, f] }]
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,21 @@
1
+ module InheritableFixtures
2
+ module RailsExtensions
3
+ module TestProcess
4
+ def fixture_file_upload(path, mime_type = nil, binary = false)
5
+ fixtures_paths = Rails.application.config.fixtures_paths
6
+ if self.class.respond_to?(:fixture_path) && self.class.fixture_path
7
+ fixtures_paths.unshift(fixture_path)
8
+ end
9
+
10
+ fixtures_paths.each do |fixtures_path|
11
+ fixtures_path = File.join(fixtures_path, path)
12
+ if File.exist?(fixtures_path)
13
+ return Rack::Test::UploadedFile.new(fixtures_path, mime_type, binary)
14
+ end
15
+ end
16
+
17
+ raise "#{path} not found in #{fixtures_paths}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module InheritableFixtures
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inheritable_fixtures
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Kmiec
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ description: Allows fixtures from engines to be inherited by applications
28
+ email:
29
+ - paul.kmiec@appfolio.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".ruby-version"
36
+ - ".travis.yml"
37
+ - Appraisals
38
+ - Gemfile
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - gemfiles/rails40.gemfile
44
+ - gemfiles/rails41.gemfile
45
+ - gemfiles/rails42.gemfile
46
+ - inheritable_fixtures.gemspec
47
+ - lib/inheritable_fixtures.rb
48
+ - lib/inheritable_fixtures/engine.rb
49
+ - lib/inheritable_fixtures/rails_extensions/db_fixtures.rake
50
+ - lib/inheritable_fixtures/rails_extensions/engine.rb
51
+ - lib/inheritable_fixtures/rails_extensions/engine_configuration.rb
52
+ - lib/inheritable_fixtures/rails_extensions/test_fixtures.rb
53
+ - lib/inheritable_fixtures/rails_extensions/test_process.rb
54
+ - lib/inheritable_fixtures/version.rb
55
+ homepage:
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.0.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.7
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Allows fixtures from engines to be inherited by applications
79
+ test_files: []