blackbird 1.0.0.pre

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.
Files changed (43) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG.md +9 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +19 -0
  5. data/README.md +77 -0
  6. data/ROADMAP.md +5 -0
  7. data/Rakefile +15 -0
  8. data/blackbird.gemspec +22 -0
  9. data/lib/blackbird.rb +39 -0
  10. data/lib/blackbird/column.rb +32 -0
  11. data/lib/blackbird/fragment.rb +58 -0
  12. data/lib/blackbird/helpers/join_tables.rb +50 -0
  13. data/lib/blackbird/helpers/typed_columns.rb +50 -0
  14. data/lib/blackbird/index.rb +29 -0
  15. data/lib/blackbird/migration.rb +218 -0
  16. data/lib/blackbird/patch.rb +64 -0
  17. data/lib/blackbird/processor_list.rb +41 -0
  18. data/lib/blackbird/processors/indexed_columns.rb +22 -0
  19. data/lib/blackbird/processors/normal_default.rb +7 -0
  20. data/lib/blackbird/railtie.rb +55 -0
  21. data/lib/blackbird/railtie/tasks.rake +8 -0
  22. data/lib/blackbird/schema.rb +25 -0
  23. data/lib/blackbird/schema/builder.rb +31 -0
  24. data/lib/blackbird/schema/changes.rb +77 -0
  25. data/lib/blackbird/schema/loader.rb +79 -0
  26. data/lib/blackbird/table.rb +71 -0
  27. data/lib/blackbird/table/builder.rb +124 -0
  28. data/lib/blackbird/table/changes.rb +86 -0
  29. data/lib/blackbird/transition.rb +85 -0
  30. data/lib/blackbird/version.rb +3 -0
  31. data/lib/rails/generators/active_record/transition/templates/fragment.rb +12 -0
  32. data/lib/rails/generators/active_record/transition/transition_generator.rb +25 -0
  33. data/spec/fixtures/a/comments_fragment.rb +10 -0
  34. data/spec/fixtures/a/pages_fragment.rb +9 -0
  35. data/spec/fixtures/a/posts_fragment.rb +9 -0
  36. data/spec/fixtures/a/users_fragment.rb +7 -0
  37. data/spec/fixtures/b/comments_fragment.rb +23 -0
  38. data/spec/fixtures/b/posts_fragment.rb +8 -0
  39. data/spec/spec.opts +4 -0
  40. data/spec/spec_helper.rb +72 -0
  41. data/spec/transitions/migration_spec.rb +116 -0
  42. data/spec/transitions/schema_loader_spec.rb +35 -0
  43. metadata +127 -0
@@ -0,0 +1,116 @@
1
+ describe 'Blackbird::Transition' do
2
+ before { reset_connection }
3
+
4
+ let(:transition) { Blackbird::Transition.build(FRAGMENT_PATHS) }
5
+
6
+ describe "changes" do
7
+ let(:changes) { transition.changes }
8
+
9
+ it "wants to remove :images" do
10
+ changes.old_tables.should == %w( images )
11
+ end
12
+
13
+ it "wants to add :comments" do
14
+ changes.new_tables.should == %w( comments )
15
+ end
16
+
17
+ it "wants to change :posts and :pages" do
18
+ changes.changed_tables.should == %w( pages posts )
19
+ end
20
+
21
+ it "doesn't want to changed :users" do
22
+ changes.unchanged_tables.should == %w( users )
23
+ end
24
+
25
+ describe ":posts(table)" do
26
+ let(:table) { transition.changes.table(:posts) }
27
+
28
+ it "doesn't want to remove any columns" do
29
+ table.old_columns.should == %w( )
30
+ end
31
+
32
+ it "doesn't want to add any columns" do
33
+ table.new_columns.should == %w( )
34
+ end
35
+
36
+ it "doesn't want to change any columns" do
37
+ table.changed_columns.should == %w( )
38
+ end
39
+
40
+ it "wants to keep all columns unchanged" do
41
+ table.unchanged_columns.should == %w( id title body )
42
+ end
43
+
44
+ end
45
+
46
+ describe ":pages(table)" do
47
+ let(:table) { transition.changes.table(:pages) }
48
+
49
+ it "wants to remove :image_id" do
50
+ table.old_columns.should == %w( image_id )
51
+ end
52
+
53
+ it "wants to add :published_at" do
54
+ table.new_columns.should == %w( published_at )
55
+ end
56
+
57
+ it "wants to change :body" do
58
+ table.changed_columns.should == %w( body )
59
+ end
60
+
61
+ it "wants to keep :id and :title unchanged" do
62
+ table.unchanged_columns.should == %w( id title )
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ it "builds instructions" do
70
+
71
+ migration = transition.migration
72
+ method = transition.fragments[CommentsFragment].method(:set_user_names)
73
+
74
+ actual = migration.instructions
75
+
76
+ expected = [
77
+ [:create_table, "comments", {:id=>true, :primary_key=>"id"}],
78
+ [:add_column, "comments", "post_id", :integer, {:null=>true}],
79
+ [:add_column, "comments", "user_id", :integer, {:null=>true}],
80
+ [:add_column, "comments", "body", :text, {:null=>true}],
81
+ [:add_column, "comments", "posted_at", :datetime, {:null=>true}],
82
+ [:add_column, "comments", "username", :string, {:null=>true}],
83
+ [:add_column, "pages", "published_at", :datetime, {:null=>true}],
84
+ [:apply, method],
85
+ [:rename_column, "posts", :published_at, :posted_at],
86
+ [:change_column, "pages", "body", :text, {:null=>true}],
87
+ [:remove_column, "pages", "image_id"],
88
+ [:drop_table, "images"],
89
+ [:add_index, "pages", ["title"], {
90
+ :name=>"index_pages_on_title"}],
91
+ [:add_index, "pages", ["published_at"], {
92
+ :name=>"index_pages_on_published_at"}],
93
+ [:add_index, "posts", ["title"], {:unique=>true,
94
+ :name=>"index_posts_on_title"}],
95
+ [:add_index, "posts", ["posted_at"], {
96
+ :name=>"index_posts_on_posted_at"}],
97
+ [:add_index, "comments", ["post_id"], {
98
+ :name=>"index_comments_on_post_id"}],
99
+ [:add_index, "comments", ["user_id"], {
100
+ :name=>"index_comments_on_user_id"}],
101
+ [:add_index, "comments", ["posted_at"], {
102
+ :name=>"index_comments_on_posted_at"}]
103
+ ]
104
+
105
+ actual.should == expected
106
+ end
107
+
108
+ it "runs instructions" do
109
+
110
+ transition.run!
111
+ transition.build
112
+ transition.migration.instructions == []
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,35 @@
1
+ describe 'Blackbird::Schema::Loader' do
2
+ before { reset_connection }
3
+
4
+ let(:schema) { Blackbird::Schema::Loader.load }
5
+
6
+ it "has a table called posts" do
7
+ schema.tables.should include('posts')
8
+ end
9
+
10
+ describe "table called 'posts'" do
11
+ let(:table) { schema.tables['posts'] }
12
+ let(:columns) { table.columns }
13
+
14
+ it "has a column called 'id'" do
15
+ columns.should include('id')
16
+ columns['id'].type.should == :integer
17
+ end
18
+
19
+ it "has a primary key called 'id'" do
20
+ columns['id'].should be_primary
21
+ table.primary_key.should == 'id'
22
+ end
23
+
24
+ it "has a column called 'body'" do
25
+ columns.should include('body')
26
+ columns['body'].type.should == :text
27
+ end
28
+
29
+ it "have column called 'title'" do
30
+ columns.should include('title')
31
+ columns['title'].type.should == :string
32
+ end
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackbird
3
+ version: !ruby/object:Gem::Version
4
+ hash: 961915988
5
+ prerelease: 6
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - pre
11
+ version: 1.0.0.pre
12
+ platform: ruby
13
+ authors:
14
+ - Simon Menke
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-31 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: activerecord
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 11
31
+ segments:
32
+ - 2
33
+ - 3
34
+ - 4
35
+ version: 2.3.4
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: Blackbird are Migrations but then better.
39
+ email:
40
+ - simon.menke@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - ROADMAP.md
54
+ - Rakefile
55
+ - blackbird.gemspec
56
+ - lib/blackbird.rb
57
+ - lib/blackbird/column.rb
58
+ - lib/blackbird/fragment.rb
59
+ - lib/blackbird/helpers/join_tables.rb
60
+ - lib/blackbird/helpers/typed_columns.rb
61
+ - lib/blackbird/index.rb
62
+ - lib/blackbird/migration.rb
63
+ - lib/blackbird/patch.rb
64
+ - lib/blackbird/processor_list.rb
65
+ - lib/blackbird/processors/indexed_columns.rb
66
+ - lib/blackbird/processors/normal_default.rb
67
+ - lib/blackbird/railtie.rb
68
+ - lib/blackbird/railtie/tasks.rake
69
+ - lib/blackbird/schema.rb
70
+ - lib/blackbird/schema/builder.rb
71
+ - lib/blackbird/schema/changes.rb
72
+ - lib/blackbird/schema/loader.rb
73
+ - lib/blackbird/table.rb
74
+ - lib/blackbird/table/builder.rb
75
+ - lib/blackbird/table/changes.rb
76
+ - lib/blackbird/transition.rb
77
+ - lib/blackbird/version.rb
78
+ - lib/rails/generators/active_record/transition/templates/fragment.rb
79
+ - lib/rails/generators/active_record/transition/transition_generator.rb
80
+ - spec/fixtures/a/comments_fragment.rb
81
+ - spec/fixtures/a/pages_fragment.rb
82
+ - spec/fixtures/a/posts_fragment.rb
83
+ - spec/fixtures/a/users_fragment.rb
84
+ - spec/fixtures/b/comments_fragment.rb
85
+ - spec/fixtures/b/posts_fragment.rb
86
+ - spec/spec.opts
87
+ - spec/spec_helper.rb
88
+ - spec/transitions/migration_spec.rb
89
+ - spec/transitions/schema_loader_spec.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/fd/blackbird
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options: []
96
+
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 23
114
+ segments:
115
+ - 1
116
+ - 3
117
+ - 6
118
+ version: 1.3.6
119
+ requirements: []
120
+
121
+ rubyforge_project: blackbird
122
+ rubygems_version: 1.4.2
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Migrations should be more adaptable
126
+ test_files: []
127
+