fixture_group 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bae4c5d91f627ff5c18ac6023ea2154516ec483
4
+ data.tar.gz: 940a5f32ca62f092a6311f528eb14bfeba011026
5
+ SHA512:
6
+ metadata.gz: aa989ccc0aeb447b49bc21accb153aac48f128c86736275ba0686846397fb09674516cab769b33c5268ec9991ce907ec93e82674b9629230cd66546f03bd2b22
7
+ data.tar.gz: 5852e9950e371fc700bfd1195c51d1fa2d242bffdf0179b841ceb8cbc4df0bb7dcbeff9fcb92d935fbc56bf3c05f59f2a271eb8cdacaf2353c68a2d86178ed5a
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ *.sqlite3
3
+ .bundle/
4
+ pkg/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ sudo: false
4
+
5
+ rvm:
6
+ - 2.0
7
+ - 2.1
8
+ - 2.2
9
+
10
+ gemfile:
11
+ - test/gemfiles/Gemfile-AR4.1
12
+ - test/gemfiles/Gemfile-AR4.2
13
+
14
+ script: rake test
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 0.1.1
2
+
3
+ * Fixed #2 Fixture accessor doesn't work
4
+
5
+ ## 0.1.0
6
+
7
+ The first release!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Katsuya HIDAKA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Fixture Group
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fixture_group.svg)](http://badge.fury.io/rb/fixture_group)
4
+ [![Build Status](https://travis-ci.org/hidakatsuya/fixture_group.svg?branch=master)](https://travis-ci.org/hidakatsuya/fixture_group)
5
+ [![Code Climate](https://codeclimate.com/github/hidakatsuya/fixture_group/badges/gpa.svg)](https://codeclimate.com/github/hidakatsuya/fixture_group)
6
+
7
+ An extension of the ActiveRecord Fixtures that make possible to create fixtures group.
8
+
9
+ ## Features
10
+
11
+ ```
12
+ Rails.root/
13
+ `- test/
14
+ `- fixtures/
15
+ |- case_a/
16
+ | |- users.yml
17
+ | `- items.yml
18
+ `- case_b/
19
+ |- subcase_b1/
20
+ | |- users.yml
21
+ | `- items.yml
22
+ `- subcase_b2/
23
+ |- users.yml
24
+ `- items.yml
25
+ ```
26
+
27
+ ```ruby
28
+ class FooControllerTest < ActiveSupport::TestCase
29
+ fixture_group 'case_a', :all
30
+ end
31
+
32
+ class BarScenarioTest < ActionDispatch::IntegrationTest
33
+ fixture_group 'case_b/subcase_b2', :all
34
+ end
35
+
36
+ class UserTest < ActiveSupport::TestCase
37
+ fixture_group 'case_b', :users
38
+ end
39
+ ```
40
+
41
+ ## Supported versions
42
+
43
+ * Ruby 2.0, 2.1, 2,2
44
+ * ActiveRecord 4.1, 4.2
45
+
46
+ ## Install
47
+
48
+ Put this line in your Gemfile:
49
+
50
+ gem 'fixture_group', group: :test
51
+
52
+ Then bundle:
53
+
54
+ % bundle
55
+
56
+ ## Usage
57
+
58
+ Please see `*_test.rb` in [test/integration](https://github.com/hidakatsuya/fixture_group/tree/master/test/integration).
59
+
60
+ ### DON'T DO THIS
61
+
62
+ ```ruby
63
+ class FooTest < ActiveSupport::TestCase
64
+ fixture_group 'case_a', :users
65
+ fixture_group 'case_b', :users
66
+ end
67
+ ```
68
+
69
+ In this code, `case_b/users.yml` will be loaded, but `case_a/users.yml` will be **ignored**.
70
+
71
+ ## Questions, Feedback
72
+
73
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hidakatsuya/fixture_group?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
74
+
75
+ or, feel free to message me on GitHub or Twitter (@hidakatsuya)
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
84
+
85
+ ## Copyright
86
+
87
+ &copy; Katsuya HIDAKA. See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ t.warning = true
15
+ end
16
+
17
+ task default: :test
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'fixture_group/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'fixture_group'
7
+ s.version = FixtureGroup::VERSION
8
+ s.authors = ['Katsuya HIDAKA']
9
+ s.email = ['hidakatsuya@gmail.com']
10
+ s.homepage = 'https://github.com/hidakatsuya/fixture_group'
11
+ s.summary = 'An extension of the ActiveRecord Fixtures ' \
12
+ 'that make possible to create fixtures group'
13
+ s.description = 'FixtureGroup is an extension of the ActiveRecord Fixtures ' \
14
+ 'that make possible to create fixtures group'
15
+ s.license = 'MIT'
16
+ s.platform = Gem::Platform::RUBY
17
+ s.required_ruby_version = '>= 2.0'
18
+
19
+ s.files = `git ls-files`.split($\)
20
+ s.test_files = s.files.grep %r{^test/}
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_dependency 'activerecord', '>= 4.1'
24
+ s.add_dependency 'activesupport', '>= 4.1'
25
+ s.add_development_dependency 'rake', '>= 10.0'
26
+ s.add_development_dependency 'sqlite3', '>= 1.3'
27
+ end
@@ -0,0 +1,64 @@
1
+ module FixtureGroup
2
+ module FixtureGroupMethod
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ # @param [String, Symbol] fixture_set_dirname
7
+ # @param [Array<String, Symbol>] fixture_set_names
8
+ # @example See `*_test.rb` in https://github.com/hidakatsuya/fixture_group/tree/master/test/integration
9
+ def fixture_group(fixture_set_dirname, *fixture_set_names)
10
+ fixture_set_path = Pathname(fixture_path).join(fixture_set_dirname.to_s)
11
+
12
+ if fixture_set_names.first == :all
13
+ fixture_set_names = Pathname.glob("#{fixture_set_path}/**/*.yml")
14
+ fixture_set_names.map! do |f|
15
+ f.relative_path_from(fixture_set_path).to_path[0..-5]
16
+ end
17
+ else
18
+ fixture_set_names = fixture_set_names.map(&:to_s)
19
+ end
20
+
21
+ paths, classes = [], {}
22
+
23
+ fixture_set_names.each do |fixture_name|
24
+ path = "#{fixture_set_dirname}/#{fixture_name}"
25
+
26
+ unless self.fixture_class_names.key?(path)
27
+ classes[path] = fixture_name.singularize.camelize.constantize
28
+ end
29
+ paths << path
30
+ end
31
+
32
+ set_fixture_class(classes)
33
+ fixtures(paths)
34
+ setup_fixture_group_accessors(paths, fixture_set_names)
35
+
36
+ register_fixture_group_dirname(fixture_set_dirname.to_s)
37
+ end
38
+
39
+ private
40
+
41
+ def setup_fixture_group_accessors(paths, fixture_set_names)
42
+ current_accessor_names = paths.map { |path| path.tr('/', '_').to_sym }
43
+ new_accessor_names = fixture_set_names.map(&:to_sym)
44
+
45
+ alias_accessor_names = Hash[current_accessor_names.zip(new_accessor_names)]
46
+ alias_accessor_names.each do |current_name, new_name|
47
+ alias_method new_name, current_name
48
+ end
49
+ end
50
+
51
+ def register_fixture_group_dirname(dirname)
52
+ return if FixtureGroup.fixture_group_dirnames.include?(dirname)
53
+ FixtureGroup.fixture_group_dirnames << dirname
54
+ end
55
+ end
56
+ end
57
+
58
+ # @private
59
+ def self.fixture_group_dirnames
60
+ @fixture_group_dirnames ||= []
61
+ end
62
+ end
63
+
64
+ ActiveRecord::TestFixtures.send :include, FixtureGroup::FixtureGroupMethod
@@ -0,0 +1,23 @@
1
+ module FixtureGroup
2
+ module FixtureSetPatch
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class << self
7
+ alias_method_chain :fixture_is_cached?, :ignoring_fixture_group
8
+ end
9
+ end
10
+
11
+ class_methods do
12
+ def fixture_is_cached_with_ignoring_fixture_group?(connection, table_name)
13
+ fixture_dirnames = FixtureGroup.fixture_group_dirnames
14
+
15
+ unless fixture_dirnames.find { |dir| table_name.to_s =~ /^#{dir}/ }
16
+ fixture_is_cached_without_ignoring_fixture_group?(connection, table_name)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ActiveRecord::FixtureSet.send :include, FixtureGroup::FixtureSetPatch
@@ -0,0 +1,3 @@
1
+ module FixtureGroup
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_record/fixtures'
3
+
4
+ require 'fixture_group/fixture_set_patch'
5
+ require 'fixture_group/fixture_group_method'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake', '>= 10.0'
4
+ gem 'sqlite3', '>= 1.3'
5
+ gem 'activerecord', '~> 4.1'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake', '>= 10.0'
4
+ gem 'sqlite3', '>= 1.3'
5
+ gem 'activerecord', '~> 4.2'
@@ -0,0 +1,14 @@
1
+ require_relative 'integration_helper'
2
+
3
+ class AllFixturesTest < ActiveSupport::TestCase
4
+ fixture_group 'for_case_a', :all
5
+
6
+ test 'load fixtures properly' do
7
+ assert_equal 1, Item.count
8
+ assert_equal 1, Category.count
9
+
10
+ assert_equal 'Item for CaseA', items(:case_a_item).name
11
+ assert_equal 'Category for CaseA', items(:case_a_item).category.name
12
+ assert_equal 'Category for CaseA', categories(:case_a_category).name
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'integration_helper'
2
+
3
+ class CompositeFixturesTest < ActiveSupport::TestCase
4
+ fixture_group 'common', :all
5
+ fixture_group 'for_case_a', :all
6
+
7
+ test 'load fixtures properly' do
8
+ assert_equal 1, User.count
9
+ assert_equal 1, Item.count
10
+ assert_equal 1, Category.count
11
+
12
+ assert_equal 'user_a', users(:user_a).login
13
+ assert_equal 'Item for CaseA', items(:case_a_item).name
14
+ assert_equal 'Category for CaseA', items(:case_a_item).category.name
15
+ end
16
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ user_a:
2
+ login: user_a
@@ -0,0 +1,2 @@
1
+ case_a_category:
2
+ name: Category for CaseA
@@ -0,0 +1,3 @@
1
+ case_a_item:
2
+ name: Item for CaseA
3
+ category: case_a_category
@@ -0,0 +1,2 @@
1
+ case_b_subcase_category:
2
+ name: Category for CaseB-Sub
@@ -0,0 +1,3 @@
1
+ case_b_subcase_item:
2
+ name: Item for CaseB-Sub
3
+ category: case_b_subcase_category
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'active_support/testing/autorun'
3
+
4
+ TEST_DB = TEST_ROOT.join('integration', 'db', 'test.sqlite3')
5
+
6
+ ActiveRecord::Base.establish_connection(
7
+ adapter: 'sqlite3',
8
+ database: TEST_DB.to_path
9
+ )
10
+
11
+ class User < ActiveRecord::Base; end
12
+
13
+ class Category < ActiveRecord::Base
14
+ has_many :items
15
+ end
16
+
17
+ class Item < ActiveRecord::Base
18
+ belongs_to :category
19
+ end
20
+
21
+ unless File.exist?(TEST_DB)
22
+ class CreateTestSchema < ActiveRecord::Migration
23
+ def change
24
+ create_table :users do |t|
25
+ t.string :login
26
+ end
27
+
28
+ create_table :categories do |t|
29
+ t.string :name
30
+ end
31
+
32
+ create_table :items do |t|
33
+ t.string :name
34
+ t.belongs_to :category
35
+ end
36
+ end
37
+ end
38
+ CreateTestSchema.migrate :up
39
+ end
40
+
41
+ class ActiveSupport::TestCase
42
+ include ActiveRecord::TestFixtures
43
+
44
+ self.fixture_path = TEST_ROOT.join('integration', 'fixtures')
45
+ self.test_order = :random
46
+ self.use_transactional_fixtures = true
47
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'integration_helper'
2
+
3
+ class NestedFixturesTest < ActiveSupport::TestCase
4
+ fixture_group 'for_case_b/subcase', :all
5
+
6
+ test 'load fixtures properly' do
7
+ assert_equal 1, Item.count
8
+ assert_equal 1, Category.count
9
+
10
+ assert_equal 'Item for CaseB-Sub', items(:case_b_subcase_item).name
11
+ assert_equal 'Category for CaseB-Sub', items(:case_b_subcase_item).category.name
12
+ assert_equal 'Category for CaseB-Sub', categories(:case_b_subcase_category).name
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'integration_helper'
2
+
3
+ class SelectFixturesTest < ActiveSupport::TestCase
4
+ fixture_group 'for_case_a', :categories, :items
5
+
6
+ test 'load fixtures properly' do
7
+ assert_equal 1, Item.count
8
+ assert_equal 1, Category.count
9
+
10
+ assert_equal 'Item for CaseA', items(:case_a_item).name
11
+ assert_equal 'Category for CaseA', items(:case_a_item).category.name
12
+ assert_equal 'Category for CaseA', categories(:case_a_category).name
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+ require 'fixture_group'
4
+
5
+ TEST_ROOT = Pathname(File.dirname(__FILE__))
6
+ $:.push TEST_ROOT.to_s
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixture_group
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Katsuya HIDAKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ description: FixtureGroup is an extension of the ActiveRecord Fixtures that make possible
70
+ to create fixtures group
71
+ email:
72
+ - hidakatsuya@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - MIT-LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - fixture_group.gemspec
85
+ - lib/fixture_group.rb
86
+ - lib/fixture_group/fixture_group_method.rb
87
+ - lib/fixture_group/fixture_set_patch.rb
88
+ - lib/fixture_group/version.rb
89
+ - test/gemfiles/Gemfile-AR4.1
90
+ - test/gemfiles/Gemfile-AR4.2
91
+ - test/integration/all_fixtures_test.rb
92
+ - test/integration/composite_fixtures_test.rb
93
+ - test/integration/db/.keep
94
+ - test/integration/fixtures/common/users.yml
95
+ - test/integration/fixtures/for_case_a/categories.yml
96
+ - test/integration/fixtures/for_case_a/items.yml
97
+ - test/integration/fixtures/for_case_b/subcase/categories.yml
98
+ - test/integration/fixtures/for_case_b/subcase/items.yml
99
+ - test/integration/integration_helper.rb
100
+ - test/integration/nested_fixtures_test.rb
101
+ - test/integration/select_fixtures_test.rb
102
+ - test/test_helper.rb
103
+ homepage: https://github.com/hidakatsuya/fixture_group
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '2.0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: An extension of the ActiveRecord Fixtures that make possible to create fixtures
127
+ group
128
+ test_files:
129
+ - test/gemfiles/Gemfile-AR4.1
130
+ - test/gemfiles/Gemfile-AR4.2
131
+ - test/integration/all_fixtures_test.rb
132
+ - test/integration/composite_fixtures_test.rb
133
+ - test/integration/db/.keep
134
+ - test/integration/fixtures/common/users.yml
135
+ - test/integration/fixtures/for_case_a/categories.yml
136
+ - test/integration/fixtures/for_case_a/items.yml
137
+ - test/integration/fixtures/for_case_b/subcase/categories.yml
138
+ - test/integration/fixtures/for_case_b/subcase/items.yml
139
+ - test/integration/integration_helper.rb
140
+ - test/integration/nested_fixtures_test.rb
141
+ - test/integration/select_fixtures_test.rb
142
+ - test/test_helper.rb
143
+ has_rdoc: