fixture_me 0.0.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: b938988f5a24da9822880fff81e66acf182e2e9d
4
+ data.tar.gz: 3a8ca5c16344831560dcdea3a0a3f5cc290fadbd
5
+ SHA512:
6
+ metadata.gz: 6fd4b29acf6448bddd1820af3c491857ce6176b459aaaca4be7c5679fc6a873afd5475a925bd8ff0818be7b8e849d01c172d075fac7799362463928f0044910e
7
+ data.tar.gz: f8f216a50b83c4e33f95c104e5a9c559f6000be9a83a9bf6139ed8c3a8021a8ffbef1861c05f9ff07c02332351326d7b92ee74b2c53bd391cbc0d51adb387eb5
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fixture_me.gemspec
4
+ gemspec
5
+ gem 'minitest'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 anthony
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # FixtureMe
2
+
3
+ Generate fixtures and fixture files for testing
4
+
5
+
6
+ If you want to generate fixtures from development database for a Ruby on Rails application here is a helper.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'fixture_me'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install fixture_me
23
+
24
+ ## Usage
25
+
26
+
27
+ ```ruby
28
+ rails console
29
+ ```
30
+
31
+ Oce your are inside Rails console
32
+
33
+ To generate fixtures for all models.
34
+
35
+ A new directory called fixtures would be created inside tmp directory (this is to make sure that this fixture generation would not override existing fixtures)
36
+
37
+ ```ruby
38
+ FixtureMe::AddFixtures.create_all_fixtures
39
+ ```
40
+
41
+
42
+
43
+ To generate fixtures one by one
44
+
45
+ a mymodel.yml file would be generated inside that file does not exist in the test/fixtures directory
46
+
47
+ 'add_fixture' method would add the new record after the existing fixtures.
48
+
49
+ ```ruby
50
+ require "fixture_me"
51
+ obj = Mymodel.find(42)
52
+ obj.add_fixture
53
+ ```
54
+
55
+
56
+ On a last note please try to give some tender love to fixtures. There is nothing wrong with them. No doubt Factories are good. But why would you need that when there are fixtures bundled right there with Rails and they work like a charm with Rails. I'll have a dig at Rspec as well. Why on earth would one use Rspec when there is minitest.
57
+
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/fixture_me/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fixture_me/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fixture_me"
8
+ spec.version = FixtureMe::VERSION
9
+ spec.authors = ["anthony de silva"]
10
+ spec.email = ["anthony@iamfree.com"]
11
+ spec.summary = %q{Generate fixtures and fixture files for testing}
12
+ spec.description = %q{If you want to generate fixtures from development database for a Ruby on Rails application here is a helper}
13
+ spec.homepage = "https://github.com/iamfree-com/fixture_me"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module FixtureMe
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fixture_me.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "fixture_me/version"
2
+
3
+ module FixtureMe
4
+
5
+ def add_fixture
6
+ hash = self.attributes
7
+ md5 = Digest::MD5.hexdigest(hash.to_s)
8
+ string = "#{md5}:\n"
9
+ hash.each do |key,value|
10
+ value.gsub!("\n","\n"+" "*4) if value.class == String
11
+ string += " "*2 + "#{key.to_s}: #{value}\n" unless value.nil?
12
+ end
13
+ string += "\n"
14
+ table_name = self.class.table_name
15
+ file_name = table_name + ".yml"
16
+ File.open("#{Rails.root}/test/fixtures/#{file_name}", 'a') do |out|
17
+ out.write(string)
18
+ end
19
+ end
20
+
21
+
22
+
23
+ class AddFixtures
24
+
25
+
26
+ def self.create_all_fixtures
27
+
28
+ fixtures_dir = "#{Rails.root}/tmp/fixtures/"
29
+ FileUtils.mkdir_p(fixtures_dir)
30
+
31
+ table_names = ActiveRecord::Base.connection.tables #.map{|a| a.capitalize.singularize}
32
+ model_names = Dir["#{Rails.root}/app/models/**/*.rb"].map {|f| File.basename(f, '.*').pluralize}
33
+ modelswithtables = table_names & model_names
34
+ modelswithtables.each do |table_name|
35
+ model = table_name.classify.constantize
36
+
37
+
38
+ if model.columns.any?{|c| c.name == 'created_at'}
39
+ sql = "SELECT * FROM #{table_name} ORDER BY created_at DESC"
40
+ else
41
+ sql = "SELECT * FROM #{table_name}"
42
+ end
43
+ File.open("#{fixtures_dir}#{table_name}.yml", "w") do |file|
44
+ objects = ActiveRecord::Base.connection.select_all(sql)
45
+ objects.each_with_index do |obj, i|
46
+ model.columns.each do |col|
47
+ if !col.null && obj[col.name].nil?
48
+ obj[col.name] = ''
49
+ end
50
+ end
51
+ file.write({"#{table_name}#{i}" => obj}.to_yaml.sub('---', ''))
52
+ file.write "\n"
53
+ end
54
+ end
55
+ puts "extracted #{table_name}"
56
+ end
57
+
58
+ end
59
+
60
+ #FixtureMe::AddFixtures.create_all_fixtures
61
+ end
62
+
63
+
64
+
65
+ end
66
+ ActiveRecord::Base.send(:include, FixtureMe)
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ class FitureMeTest < Minitest::Test
3
+
4
+
5
+ #def test_that_life_is_good
6
+ # assert_equal "hello", FixtureMe::Fixme.nice
7
+ #end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require "minitest/autorun"
3
+
4
+ libpath = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift File.join(libpath, "..", "lib")
6
+
7
+
8
+
9
+ require_relative "../lib/fixture_me"
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
2
+ class FitureMeTest < Minitest::Test
3
+
4
+
5
+ def test_that_life_is_good
6
+ assert_equal "hello world", "hello world"
7
+ end
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixture_me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - anthony de silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: If you want to generate fixtures from development database for a Ruby
42
+ on Rails application here is a helper
43
+ email:
44
+ - anthony@iamfree.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".DS_Store"
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - fixture_me.gemspec
56
+ - lib/.DS_Store
57
+ - lib/fixture_me.rb
58
+ - lib/fixture_me/version.rb
59
+ - test/fixture_me_test.rb
60
+ - test/test_helper.rb
61
+ - tests/fixture_me_test.rb
62
+ homepage: https://github.com/iamfree-com/fixture_me
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Generate fixtures and fixture files for testing
86
+ test_files:
87
+ - test/fixture_me_test.rb
88
+ - test/test_helper.rb