iron_fixture_extractor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/Gemfile +7 -9
  3. data/README.md +129 -47
  4. data/Rakefile +5 -6
  5. data/iron_fixture_extractor.gemspec +0 -3
  6. data/lib/fe.rb +18 -43
  7. data/lib/fe/extractor.rb +91 -63
  8. data/lib/fe/version.rb +1 -1
  9. data/spec/README_FOR_DEVELOPERS.md +26 -0
  10. data/spec/dummy_environments/sqlite/dummy1/config/database.yml +11 -0
  11. data/spec/dummy_environments/sqlite/dummy1/data_migrations/001_create_some_data.rb +17 -0
  12. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043601_create_posts.rb +13 -0
  13. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043602_create_authors.rb +9 -0
  14. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043603_create_different_posts.rb +14 -0
  15. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043639_create_comments.rb +13 -0
  16. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043808_create_group_members.rb +13 -0
  17. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043818_create_groups.rb +9 -0
  18. data/spec/dummy_environments/sqlite/dummy1/migrations/20120604043819_create_users.rb +10 -0
  19. data/spec/dummy_environments/sqlite/dummy1/models/author.rb +5 -0
  20. data/spec/dummy_environments/sqlite/dummy1/models/comment.rb +5 -0
  21. data/spec/dummy_environments/sqlite/dummy1/models/complex_thing.rb +4 -0
  22. data/spec/dummy_environments/sqlite/dummy1/models/different_post.rb +9 -0
  23. data/spec/dummy_environments/sqlite/dummy1/models/group.rb +5 -0
  24. data/spec/dummy_environments/sqlite/dummy1/models/group_member.rb +5 -0
  25. data/spec/dummy_environments/sqlite/dummy1/models/post.rb +7 -0
  26. data/spec/dummy_environments/sqlite/dummy1/models/serialized_attribute_encoder.rb +12 -0
  27. data/spec/dummy_environments/sqlite/dummy1/models/user.rb +2 -0
  28. data/spec/dummy_environments/sqlite/dummy1/models/user/admin.rb +3 -0
  29. data/spec/dummy_environments/sqlite/dummy1/models/user/jerk.rb +3 -0
  30. data/spec/execute_extract_code_spec.rb +29 -0
  31. data/spec/extract_spec.rb +37 -0
  32. data/spec/extract_works_with_multiple_extract_queries_in_one_command_spec.rb +12 -0
  33. data/spec/fe_test_env_spec.rb +65 -0
  34. data/spec/get_hash_spec.rb +27 -0
  35. data/spec/load_db_map_option_spec.rb +39 -0
  36. data/spec/load_db_spec.rb +48 -0
  37. data/spec/load_db_works_with_serialized_attributes_spec.rb +18 -0
  38. data/spec/rebuild_spec.rb +18 -0
  39. data/spec/spec_helper.rb +15 -0
  40. data/spec/support/fe_test_env.rb +181 -0
  41. data/spec/support/first_post_w_comments_and_authors.rb +12 -0
  42. data/spec/truncate_tables_for_spec.rb +39 -0
  43. data/spec/works_with_single_table_inheritance_spec.rb +16 -0
  44. data/test/basic_usage_test.ported.rb +114 -0
  45. data/test/{different_target_table_test.rb → different_target_table_test.not_porting.rb} +0 -0
  46. data/test/factory_girl_test.not_porting_now.rb +79 -0
  47. data/test/{fe_test_env.rb → fe_test_env.ported.rb} +0 -0
  48. data/test/{get_hash_test.rb → get_hash_test.ported.rb} +17 -1
  49. data/test/{multi_tree_usage_test.rb → multi_tree_usage_test.ported.rb} +0 -0
  50. data/test/{serialized_attribute_test.rb → serialized_attribute_test.ported.rb} +0 -0
  51. data/test/{sti_test.rb → sti_test.ported.rb} +0 -0
  52. data/test/test_helper.rb +0 -1
  53. metadata +135 -88
  54. data/lib/fe/factory_girl_dsl_methods.rb +0 -28
  55. data/test/basic_usage_test.rb +0 -106
  56. data/test/factory_girl_test.rb +0 -77
@@ -1,106 +0,0 @@
1
- require 'test_helper'
2
- class BasicUsage < ActiveSupport::TestCase
3
- context "Main API" do
4
- setup do
5
- @extract_code = 'Post.includes(:comments, :author).limit(1)'
6
- @extract_name = :first_post_w_comments_and_authors
7
- end
8
- context ".extract" do
9
- setup do
10
- FeTestEnv.setup
11
- end
12
- teardown do
13
- FeTestEnv.teardown
14
- end
15
- should "provide the right output, and put the file in the right place" do
16
- extractor = Fe.extract(@extract_code, :name => @extract_name)
17
- assert_kind_of Fe::Extractor, extractor
18
- assert (%w(Post Comment Author) - extractor.model_names).empty?, "only these keys should exist"
19
- assert_equal @extract_name, extractor.name
20
- assert_equal Post.table_name, extractor.table_names['Post']
21
- assert File.exists?(File.join(Fe.fixtures_root,'first_post_w_comments_and_authors','fe_manifest.yml')), "The file that allows the fixtures to get rebuilt"
22
- assert_equal 1, extractor.row_counts['Post']
23
- assert_equal 1, extractor.row_counts['Author']
24
- assert_kind_of Hash, extractor.manifest_hash
25
- assert File.exists?(File.join(Fe.fixtures_root,'first_post_w_comments_and_authors',"#{Post.table_name}.yml")), "The file is created"
26
- end
27
- end
28
- context ".load_db, .execute_extract_code" do
29
- setup do
30
- FeTestEnv.setup # regular production db
31
- extract_hash = Fe.extract(@extract_code, :name => @extract_name)
32
- FeTestEnv.the_env = 'fake_test'
33
- FeTestEnv.recreate_schema_without_data
34
- end
35
- teardown do
36
- FeTestEnv.teardown
37
- end
38
- should "provide the ability to load fixtures" do
39
- assert_equal 0, Post.count
40
- assert_equal 0, Comment.count
41
- assert_equal 0, Author.count
42
- Fe.load_db(@extract_name)
43
- assert_equal 1, Post.count
44
- assert_equal 1, Comment.count
45
- assert_equal 1, Author.count
46
- end
47
- should "provide the ability to execute the same query that built the fixtures" do
48
- Fe.load_db(@extract_name)
49
- rows = Fe.execute_extract_code(:first_post_w_comments_and_authors)
50
- assert_equal 1, rows.length
51
- assert (rows.first.association_cache.keys - [:comments,:author]).empty?, "Comments and authors should be eager loaded"
52
- end
53
- end
54
- context ".rebuild" do
55
- setup do
56
- FeTestEnv.setup
57
- @extractor = Fe.extract(@extract_code, :name => @extract_name)
58
- end
59
- teardown do
60
- FeTestEnv.teardown
61
- end
62
- should "be able to rebuild the fixture files from the manifest" do
63
- # TODO: continue here, should delete a comment, then rebuild,
64
- # and assert
65
- # all files mtimes have changed
66
- # there is no comment file
67
- results = eval(@extract_code)
68
- first_post = results.first
69
- assert_match /First post/i, first_post.name
70
- first_post.name = "UPDATED_FIRST_POST"
71
- first_post.save!
72
- rebuild_hash = Fe.rebuild(@extract_name)
73
- assert_match /UPDATED_FIRST_POST/, File.read(@extractor.fixture_path_for_model('Post'))
74
- #assert_equal 0, Post.count
75
- end
76
- end
77
-
78
- context ".truncate_tables_for" do
79
- setup do
80
- FeTestEnv.setup # regular production db
81
- extract_hash = Fe.extract(@extract_code, :name => @extract_name)
82
- FeTestEnv.the_env = 'fake_test'
83
- FeTestEnv.recreate_schema_without_data
84
- end
85
- teardown do
86
- FeTestEnv.teardown
87
- end
88
- should "truncate only the tables in the fixture set" do
89
- Group.create
90
- assert_equal 1, Group.count
91
-
92
- Fe.load_db(@extract_name)
93
- assert_equal 1, Post.count
94
- assert_equal 1, Comment.count
95
- assert_equal 1, Author.count
96
-
97
- Fe.truncate_tables_for(@extract_name)
98
- assert_equal 1, Group.count
99
- assert_equal 0, Post.count
100
- assert_equal 0, Comment.count
101
- assert_equal 0, Author.count
102
-
103
- end
104
- end
105
- end
106
- end
@@ -1,77 +0,0 @@
1
- # WARNING: THIS IS AN EXPERIMENTAL FEATURE THAT ISN'T QUITE COMPLETE AND MIGHT BE DEPRECATED
2
- # WARNING: THIS IS AN EXPERIMENTAL FEATURE THAT ISN'T QUITE COMPLETE AND MIGHT BE DEPRECATED
3
- # WARNING: THIS IS AN EXPERIMENTAL FEATURE THAT ISN'T QUITE COMPLETE AND MIGHT BE DEPRECATED
4
- # WARNING: THIS IS AN EXPERIMENTAL FEATURE THAT ISN'T QUITE COMPLETE AND MIGHT BE DEPRECATED
5
- require 'test_helper'
6
- require 'factory_girl'
7
- class FactoryGirlTest < ActiveSupport::TestCase
8
- setup do
9
-
10
- @extract_code = 'Post.includes(:comments, :author).limit(1)'
11
- @extract_name = :first_post_w_comments_and_authors
12
- FeTestEnv.setup # regular production db
13
- Fe.extract(@extract_code, :name => @extract_name) # build fixture yml
14
- FeTestEnv.the_env = 'fake_test'
15
- FeTestEnv.recreate_schema_without_data
16
-
17
- @post_hash = Fe.get_hash(:first_post_w_comments_and_authors, Post,"r1")
18
-
19
-
20
- end
21
- should "expose a .to_factory_girl_string method" do
22
- assert_kind_of Hash, @post_hash
23
- assert_respond_to @post_hash, :to_factory_girl_string
24
- assert !Hash.instance_methods.include?(:to_factory_girl_string)
25
-
26
- @fg_string = @post_hash.to_factory_girl_string
27
- assert_match /Post/, @fg_string, "The string should have the model name on the first line"
28
- end
29
-
30
- should ".to_factory_girl_string should return a monkey patched string implementing .to_proc" do
31
- @fg_string = @post_hash.to_factory_girl_string
32
- assert_respond_to @fg_string, :to_proc
33
- end
34
-
35
- should "be just like a factory produced in a non-meta way" do
36
- FactoryGirl.define do
37
- # This is the essense of the code that .to_factory_girl_string spits out
38
- factory :fe2, :class => Post do
39
- x = Post.new(Fe.get_hash(:first_post_w_comments_and_authors,Post,"r1"))
40
- id x.id
41
- author_id x.author_id
42
- name x.name
43
- content x.content
44
- serialized_thing x.serialized_thing
45
- created_at x.created_at
46
- updated_at x.updated_at
47
- end
48
-
49
- # We are evaluating the to_factory_girl_string in the block context factory girl
50
- # if you wanted to override settings you could do so afterwords
51
- factory :fe3, :class => Post, &Proc.new {
52
- self.instance_eval(Fe.get_hash(:first_post_w_comments_and_authors,Post,"r1").to_factory_girl_string)
53
- # I think You could override attributes set in the fixture here, like:
54
- # name "poo poo"
55
- }
56
-
57
- # This is two levels meta-ness away
58
- factory :fe4,
59
- :class => Post,
60
- &Fe.get_hash(:first_post_w_comments_and_authors,Post,"r1").to_factory_girl_string.to_proc
61
- end
62
-
63
- @fe2 = FactoryGirl.create(:fe2)
64
- assert_kind_of Post, @fe2
65
-
66
- @fe3 = FactoryGirl.create(:fe3)
67
- assert_kind_of Post, @fe3
68
- assert_kind_of Time, @fe3.updated_at, "Objects get the right type"
69
-
70
- @fe4 = FactoryGirl.create(:fe4)
71
- assert_kind_of Post, @fe4
72
- assert_kind_of Time, @fe4.updated_at, "Objects get the right type"
73
- end
74
- teardown do
75
- FeTestEnv.teardown
76
- end
77
- end