generator-spec 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{generator-spec}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
52
52
  "lib/rspec_for_generators/matchers/migration/have_table.rb",
53
53
  "lib/rspec_for_generators/matchers/migration/have_tbl_column.rb",
54
54
  "lib/rspec_for_generators/matchers/migration/have_up_down.rb",
55
+ "lib/rspec_for_generators/migration_helper.rb",
55
56
  "lib/rspec_for_generators/rails_helpers/rails_app.rb",
56
57
  "lib/rspec_for_generators/rails_helpers/rails_controller.rb",
57
58
  "lib/rspec_for_generators/rails_helpers/rails_helper.rb",
@@ -69,6 +70,8 @@ Gem::Specification.new do |s|
69
70
  "spec/rspec_for_generators/model_generator_spec.rb",
70
71
  "spec/rspec_for_generators/view_generator_spec.rb",
71
72
  "spec/spec_helper.rb",
73
+ "tmp/rails/config/routes.rb",
74
+ "tmp/rails/db/migrations/20100805160101_create_users.rb",
72
75
  "wiki/Custom Rails 3 Generators.textile",
73
76
  "wiki/content_matchers.textile",
74
77
  "wiki/file_matchers.textile",
@@ -1,13 +1,15 @@
1
- class MigrationGenerator < Rails::Generators::Base
2
- desc "Creates a migration"
1
+ require 'rspec_for_generators/migration_helper'
3
2
 
4
- argument :name, :type => :string
3
+ class MigrationGenerator < Rails::Generators::NamedBase
4
+ include MigrationHelper
5
+
6
+ desc "Creates a migration"
5
7
 
6
8
  def self.source_root
7
9
  @source_root ||= File.expand_path("../templates", __FILE__)
8
10
  end
9
11
 
10
12
  def create_migration
11
- template "#{name}.erb", 'db/migrations/20100203_create_users.rb'
13
+ migration "#{name} name:string age:integer admin:boolean"
12
14
  end
13
15
  end
@@ -33,7 +33,7 @@ module RSpec
33
33
 
34
34
  def configure_root_dir path, options = {}
35
35
  ::Rails.application.configure do
36
- config.root_dir = options == :custom ? TmpRails.root_dir(File.dirname(path) + '/../tmp', :custom) : TmpRails.root_dir(path)
36
+ config.root_dir = options == :custom ? TmpRails.root_dir(File.dirname(path) + '/../tmp', :custom) : TmpRails.root_dir(path)
37
37
  end
38
38
 
39
39
  ::RSpec.configure do |config|
@@ -0,0 +1,39 @@
1
+ module MigrationHelper
2
+ include Rails::Generators::Migration
3
+
4
+ module ClassMethods
5
+ def migration_lookup_at(dirname) #:nodoc:
6
+ Dir.glob("#{dirname}/[0-9]*_*.rb")
7
+ end
8
+
9
+ def migration_exists?(dirname, file_name) #:nodoc:
10
+ migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
11
+ end
12
+
13
+ def current_migration_number(dirname) #:nodoc:
14
+ migration_lookup_at(dirname).collect do |file|
15
+ File.basename(file).split("_").first.to_i
16
+ end.max.to_i
17
+ end
18
+
19
+ def next_migration_number(dirname) #:nodoc:
20
+ orm = Rails.configuration.generators.options[:rails][:orm]
21
+ require "rails/generators/#{orm}"
22
+ "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)
23
+ rescue
24
+ raise NotImplementedError
25
+ end
26
+ end
27
+
28
+ def self.included(base) #:nodoc:
29
+ base.extend ClassMethods
30
+ end
31
+
32
+ def info msg
33
+ Rails.logger.info msg
34
+ end
35
+
36
+ def migration(options)
37
+ migration_template "create_users.erb", "db/migrations/#{name}"
38
+ end
39
+ end
@@ -14,7 +14,7 @@ describe 'migration_generator' do
14
14
  after :each do
15
15
  end
16
16
 
17
- it "should generate create_user migration" do
17
+ it "should generate create_user migration" do
18
18
  RSpec::Generator.with_generator do |g|
19
19
  name = 'create_users'
20
20
  remove_migration 'create_users'
data/spec/spec_helper.rb CHANGED
@@ -2,10 +2,23 @@ require 'rspec'
2
2
  require 'rspec/autorun'
3
3
  require 'rspec_for_generators'
4
4
 
5
- RSpec::Generator.remove_temp_dir = true
5
+ RSpec::Generator.remove_temp_dir = false
6
6
  RSpec::Generator.configure_root_dir __FILE__
7
7
 
8
8
  class RSpec::Core::ExampleGroup
9
9
 
10
10
  end
11
11
 
12
+ module Rails
13
+ def self.logger
14
+ @logger ||= Logger.new(STDOUT)
15
+ end
16
+ end
17
+
18
+ # class Railtie < ::Rails::Railtie
19
+ # # config.
20
+ #
21
+ # initializer "logger" do |app|
22
+ # app.config.logger = Logger.new(STDOUT)
23
+ # end
24
+ # end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do |map|
2
+ end
@@ -0,0 +1,14 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.integer :age
6
+ t.boolean :admin
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :users
12
+ end
13
+
14
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -156,6 +156,7 @@ files:
156
156
  - lib/rspec_for_generators/matchers/migration/have_table.rb
157
157
  - lib/rspec_for_generators/matchers/migration/have_tbl_column.rb
158
158
  - lib/rspec_for_generators/matchers/migration/have_up_down.rb
159
+ - lib/rspec_for_generators/migration_helper.rb
159
160
  - lib/rspec_for_generators/rails_helpers/rails_app.rb
160
161
  - lib/rspec_for_generators/rails_helpers/rails_controller.rb
161
162
  - lib/rspec_for_generators/rails_helpers/rails_helper.rb
@@ -173,6 +174,8 @@ files:
173
174
  - spec/rspec_for_generators/model_generator_spec.rb
174
175
  - spec/rspec_for_generators/view_generator_spec.rb
175
176
  - spec/spec_helper.rb
177
+ - tmp/rails/config/routes.rb
178
+ - tmp/rails/db/migrations/20100805160101_create_users.rb
176
179
  - wiki/Custom Rails 3 Generators.textile
177
180
  - wiki/content_matchers.textile
178
181
  - wiki/file_matchers.textile