fixture_me 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9810644f0c121be6dabdbe00e68646a685bc211
4
- data.tar.gz: edaf8ae132ee5c0184a3058e3aebea5d1538a931
3
+ metadata.gz: ae3357fdb16f08d2c8271f5bc9397e9fd733f367
4
+ data.tar.gz: b69abc8809ea67635c35d473de07e779a1615b60
5
5
  SHA512:
6
- metadata.gz: 710dd27e7733e1aa35076e9870f1e8ae968a834ba48030ebe203df62592726ecda5eeb8a85d1c86f5bad2c261f801e34fc6a65ab737f2c5720c367cf22815a75
7
- data.tar.gz: 5503d39655aabfd0a3e282f15f8d5bc69c5b3e511e3f51db7bf52daab1b3fddd4639fded7be55cd3770b0867a8ccd91386a898c1bbf4d52152feddb3228116b5
6
+ metadata.gz: 4810f37a701bf0980a458abbec646d0e5244fbb0c963460bbc4c308f0964c7f3b02b4826d1088131641a1445c5ca1b5c4a8d1a469f19c5a8fd87bf7c1f573704
7
+ data.tar.gz: 71639b87acba2845f88efc6bf569be0708e8412cabdf5406c5ac2250bedd3cfd1e1f3e46b238e31531cc3271324106e465e6d62a114f1fe15dd092d7967aff2a
data/.gitignore CHANGED
@@ -12,3 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ **/.DS_Store
16
+ *.gem
17
+ *.rbc
data/README.md CHANGED
@@ -47,7 +47,7 @@ to exclude created_at and updated_at columns
47
47
  fixme.create_all_fixtures_no_timestamps
48
48
  ```
49
49
 
50
-
50
+
51
51
  To generate fixtures one by one
52
52
 
53
53
  a mymodel.yml file would be generated inside that file does not exist in the test/fixtures directory
@@ -60,13 +60,24 @@ obj = Mymodel.find(42)
60
60
  obj.add_fixture
61
61
  ```
62
62
 
63
+ To exclude timestamps and ID
64
+
65
+ ```ruby
66
+ require "fixture_me"
67
+ obj = Mymodel.find(42)
68
+ obj.add_fixture_no_id_timestamps
69
+ ```
70
+
71
+
72
+
73
+
63
74
 
64
75
  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.
65
76
 
66
77
 
67
78
  ## Contributing
68
79
 
69
- 1. Fork it ( https://github.com/[my-github-username]/fixture_me/fork )
80
+ 1. Fork it ( https://github.com/iamfree-com/fixture_me/fork )
70
81
  2. Create your feature branch (`git checkout -b my-new-feature`)
71
82
  3. Commit your changes (`git commit -am 'Add some feature'`)
72
83
  4. Push to the branch (`git push origin my-new-feature`)
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "activerecord"
24
+ spec.add_development_dependency "sqlite3"
23
25
  end
@@ -13,7 +13,7 @@ module FixtureMe
13
13
  string += "\n"
14
14
  table_name = self.class.table_name
15
15
  file_name = table_name + ".yml"
16
- File.open("#{Rails.root}/test/fixtures/#{file_name}", 'a') do |out|
16
+ File.open("#{Dir.pwd}/test/fixtures/#{file_name}", 'a') do |out|
17
17
  out.write(string)
18
18
  end
19
19
  end
@@ -30,18 +30,21 @@ module FixtureMe
30
30
  string += "\n"
31
31
  table_name = self.class.table_name
32
32
  file_name = table_name + ".yml"
33
- File.open("#{Rails.root}/test/fixtures/#{file_name}", 'a') do |out|
33
+ File.open("#{Dir.pwd}/test/fixtures/#{file_name}", 'a') do |out|
34
34
  out.write(string)
35
35
  end
36
36
  end
37
37
 
38
38
 
39
39
 
40
+
41
+
42
+
40
43
  class AddFixtures
41
44
 
42
45
 
43
46
  def initialize
44
- @fixtures_dir = FileUtils.mkdir_p( "#{Rails.root}/tmp/fixtures/").first
47
+ @fixtures_dir = FileUtils.mkdir_p( "#{Dir.pwd}/tmp/fixtures/").first
45
48
  end
46
49
 
47
50
  def fixtures_dir
@@ -51,7 +54,7 @@ module FixtureMe
51
54
 
52
55
  def all_models
53
56
  # must eager load all the classes...
54
- Dir.glob("#{RAILS_ROOT}/app/models/**/*.rb") do |model_path|
57
+ Dir.glob("#{Dir.pwd}/app/models/**/*.rb") do |model_path|
55
58
  begin
56
59
  require model_path
57
60
  rescue
@@ -69,7 +72,7 @@ module FixtureMe
69
72
 
70
73
 
71
74
  table_names = ActiveRecord::Base.connection.tables #.map{|a| a.capitalize.singularize}
72
- model_names = Dir["#{Rails.root}/app/models/**/*.rb"].map {|f| File.basename(f, '.*').pluralize}
75
+ model_names = Dir["#{Dir.pwd}/app/models/**/*.rb"].map {|f| File.basename(f, '.*').pluralize}
73
76
 
74
77
  #Rails.application.eager_load! unless Rails.configuration.cache_classes
75
78
  #ActiveRecord::Base.descendants
@@ -1,3 +1,3 @@
1
1
  module FixtureMe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,9 +1,45 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'yaml'
3
+
2
4
  class FitureMeTest < Minitest::Test
3
5
 
4
6
 
5
- #def test_that_life_is_good
6
- # assert_equal "hello", FixtureMe::Fixme.nice
7
- #end
8
-
7
+ def test_check_for_add_fixture_no_id_timestamps_file
8
+ the_file = "#{Dir.pwd}/test/fixtures/tasks.yml"
9
+ File.delete(the_file) if File.exist?(the_file)
10
+ task = Task.create! name: "test"
11
+ tsk = Task.first.add_fixture_no_id_timestamps
12
+ assert File.exists?(the_file), "tasks.tml file is not there"
13
+ parsing = YAML.load_file(the_file)
14
+ first_itm = parsing.keys[0]
15
+ exp_hasg = {"name"=> "test"}.to_s
16
+ assert_equal exp_hasg, parsing[first_itm].to_s
17
+ end
18
+
19
+
20
+ def test_check_for_add_fixture_no_id_timestamps_file
21
+ the_file = "#{Dir.pwd}/test/fixtures/tasks.yml"
22
+ File.delete(the_file) if File.exist?(the_file)
23
+ task = Task.create! name: "test"
24
+ tsk = Task.first.add_fixture
25
+ assert File.exists?(the_file), "tasks.tml file is not there"
26
+ parsing = YAML.load_file(the_file)
27
+ first_itm = parsing.keys[0]
28
+ exp_hasg = {"id" => 1, "name"=> "test"}.to_s
29
+ assert_equal exp_hasg, parsing[first_itm].to_s
30
+ end
31
+
32
+
33
+ def test_check_for_add_fixture_no_id_timestamps_file
34
+ the_file = "#{Dir.pwd}/test/fixtures/tasks.yml"
35
+ File.delete(the_file) if File.exist?(the_file)
36
+ task = Task.create! name: "test"
37
+ server1 = Server.create! name: "main1", server_type: "main"
38
+ server2 = Server.create! name: "main2", server_type: "main"
39
+ fixme = FixtureMe::AddFixtures.new
40
+ assert fixme.create_all_fixtures_no_timestamps
41
+ end
42
+
43
+
44
+
9
45
  end
@@ -1,9 +1,41 @@
1
1
  require 'rubygems'
2
2
  require "minitest/autorun"
3
+ require 'active_record'
4
+ require 'logger'
3
5
 
4
6
  libpath = File.dirname(__FILE__)
5
7
  $LOAD_PATH.unshift File.join(libpath, "..", "lib")
6
8
 
9
+ require_relative "../lib/fixture_me"
7
10
 
8
11
 
9
- require_relative "../lib/fixture_me"
12
+ ActiveRecord::Base.establish_connection 'sqlite3::memory:'
13
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
14
+
15
+ ActiveRecord::Schema.define do
16
+ create_table "tasks", force: true do |t|
17
+ t.string "name"
18
+ end
19
+
20
+ create_table "servers" do |t|
21
+ t.string "name"
22
+ t.string "server_type"
23
+ end
24
+
25
+ create_table "servers_tasks", :id => false do |t|
26
+ t.references :task
27
+ t.references :server
28
+ end
29
+ end
30
+
31
+ class Task < ActiveRecord::Base
32
+ end
33
+ class Server < ActiveRecord::Base
34
+
35
+ end
36
+
37
+
38
+ # Load fixtures from the engine
39
+ #if ActiveSupport::TestCase.method_defined?(:fixture_path=)
40
+ # ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
41
+ #end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - anthony de silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: If you want to generate fixtures from development database for a Ruby
42
70
  on Rails application here is a helper
43
71
  email:
@@ -46,20 +74,16 @@ executables: []
46
74
  extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
- - ".DS_Store"
50
77
  - ".gitignore"
51
78
  - Gemfile
52
79
  - LICENSE.txt
53
80
  - README.md
54
81
  - Rakefile
55
- - fixture_me-0.0.1.gem
56
82
  - fixture_me.gemspec
57
- - lib/.DS_Store
58
83
  - lib/fixture_me.rb
59
84
  - lib/fixture_me/version.rb
60
85
  - test/fixture_me_test.rb
61
86
  - test/test_helper.rb
62
- - tests/fixture_me_test.rb
63
87
  homepage: https://github.com/iamfree-com/fixture_me
64
88
  licenses:
65
89
  - MIT
data/.DS_Store DELETED
Binary file
Binary file
Binary file
@@ -1,9 +0,0 @@
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