padrino-gen 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,7 @@ module <%= @project_name %>
31
31
  # set :public_folder, 'foo/bar' # Location for static assets (default root/public)
32
32
  # set :reload, false # Reload application files (default in development)
33
33
  # set :default_builder, 'foo' # Set a custom form builder (default 'StandardFormBuilder')
34
- # set :locale_path, 'bar' # Set path for I18n translations (default your_app/locales)
34
+ # set :locale_path, 'bar' # Set path for I18n translations (default your_apps_root_path/locale)
35
35
  # disable :sessions # Disabled sessions by default (enable if needed)
36
36
  # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
37
37
  # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
@@ -33,9 +33,9 @@ module Padrino
33
33
  contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
34
34
  contents = contents.gsub(/!NAME!/, model_name.underscore.camelize).gsub(/!TABLE!/, model_name.underscore)
35
35
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
36
- current_migration_number = return_last_migration_number
37
- contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, (current_migration_number + 1).to_s)
38
- migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
36
+ migration_number = current_migration_number
37
+ contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, migration_number)
38
+ migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb"
39
39
  create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true)
40
40
  end
41
41
  end
@@ -98,7 +98,7 @@ module Padrino
98
98
  # For migration files
99
99
  # returns the number of the migration that is being created
100
100
  # returna timestamp instead if :migration_format: in .components is "timestamp"
101
- #
101
+ #
102
102
  # @api private
103
103
  def current_migration_number
104
104
  if fetch_component_choice(:migration_format).to_s == 'timestamp'
@@ -100,7 +100,7 @@ MIGRATION
100
100
 
101
101
  def create_model_migration(migration_name, name, columns)
102
102
  output_model_migration(migration_name, name, columns,
103
- :column_format => Proc.new { |field, kind| "column :#{field}, #{kind.classify}#{', :length => 255' if kind =~ /string/i}" },
103
+ :column_format => Proc.new { |field, kind| "column :#{field}, DataMapper::Property::#{kind.classify}#{', :length => 255' if kind =~ /string/i}" },
104
104
  :base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
105
105
  end
106
106
 
@@ -20,63 +20,10 @@ OHM = (<<-OHM) unless defined?(OHM)
20
20
  # when :production then Ohm.connect(:db => 1)
21
21
  # when :test then Ohm.connect(:db => 2)
22
22
  # end
23
-
24
- # This monkey patch provides traditional (hash of arrays) error handling for ohm models
25
- # Also add compatiblity with admin generator.
26
- module Ohm
27
- class Model
28
-
29
- alias_method :old_errors, :errors
30
- def errors
31
- @errors ||= ErrorsHash.new(self.class.to_reference, self.old_errors)
32
- end
33
-
34
- def update_attributes(attrs)
35
- attrs.each do |key, value|
36
- send(:"\#{key}=", value)
37
- end if attrs
38
- end
39
-
40
- class << self
41
- alias_method :old_attribute, :attribute
42
- def attribute(name, cast=nil)
43
- attributes << name
44
- old_attribute(name, cast)
45
- end
46
-
47
- def attributes
48
- @_attributes ||= []
49
- end
50
- end
51
-
52
- class ErrorsHash < Hash
53
- def initialize(scope, errors)
54
- @scope = scope
55
- self.replace Hash.new { |hash, key| hash[key] = [] }
56
-
57
- errors.each do |key, value|
58
- self[key] << value
59
- end
60
- end
61
-
62
- def push(arr)
63
- self[arr[0]] << arr[1]
64
- end
65
-
66
- def full_messages
67
- self.map do |key, value|
68
- value.uniq.map do |reason|
69
- I18n::t("ohm.%s.%s.%s" % [@scope, key, reason])
70
- end.join(', ')
71
- end
72
- end
73
- end
74
- end
75
- end # unless Ohm::Model.new.errors.is_a?(Hash)
76
23
  OHM
77
24
 
78
25
  def setup_orm
79
- require_dependencies 'ohm'
26
+ require_dependencies 'ohm', :version => "~> 1.3.0"
80
27
  create_file("config/database.rb", OHM)
81
28
  end
82
29
 
@@ -32,9 +32,9 @@ def setup_orm
32
32
  require_dependencies 'pg'
33
33
  'pg'
34
34
  else
35
- sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_development.db\")")
36
- sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_production.db\")")
37
- sequel.gsub!(/!DB_TEST!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_test.db\")")
35
+ sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_development.db\")")
36
+ sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_production.db\")")
37
+ sequel.gsub!(/!DB_TEST!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_test.db\")")
38
38
  require_dependencies 'sqlite3'
39
39
  'sqlite3'
40
40
  end
@@ -6,11 +6,18 @@ class Bacon::Context
6
6
  include Rack::Test::Methods
7
7
  end
8
8
 
9
- def app
10
- ##
11
- # You can handle all padrino applications using instead:
12
- # Padrino.application
13
- CLASS_NAME.tap { |app| }
9
+ # You can use this method to custom specify a Rack app
10
+ # you want rack-test to invoke:
11
+ #
12
+ # app CLASS_NAME
13
+ # app CLASS_NAME.tap { |a| }
14
+ # app(CLASS_NAME) do
15
+ # set :foo, :bar
16
+ # end
17
+ #
18
+ def app(app = nil &blk)
19
+ @app ||= block_given? ? app.instance_eval(&blk) : app
20
+ @app ||= Padrino.application
14
21
  end
15
22
  TEST
16
23
 
@@ -5,11 +5,18 @@ require File.expand_path('../../config/boot', __FILE__)
5
5
  class MiniTest::Unit::TestCase
6
6
  include Rack::Test::Methods
7
7
 
8
- def app
9
- ##
10
- # You can handle all padrino applications using instead:
11
- # Padrino.application
12
- CLASS_NAME.tap { |app| }
8
+ # You can use this method to custom specify a Rack app
9
+ # you want rack-test to invoke:
10
+ #
11
+ # app CLASS_NAME
12
+ # app CLASS_NAME.tap { |a| }
13
+ # app(CLASS_NAME) do
14
+ # set :foo, :bar
15
+ # end
16
+ #
17
+ def app(app = nil &blk)
18
+ @app ||= block_given? ? app.instance_eval(&blk) : app
19
+ @app ||= Padrino.application
13
20
  end
14
21
  end
15
22
  TEST
@@ -9,30 +9,25 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
9
9
 
10
10
  class Riot::Situation
11
11
  include Rack::Test::Methods
12
- ##
13
- # You can handle all padrino applications using instead:
14
- # Padrino.application
15
- # Or just the Application itself like:
16
- # CLASS_NAME.tap { |app| }
17
-
18
- def app
19
- @app || Padrino.application
20
- end
21
- end
22
12
 
23
- class Riot::Context
24
- # Set the Rack app which is to be tested.
13
+ # You can use this method to custom specify a Rack app
14
+ # you want rack-test to invoke:
25
15
  #
26
- # context "MyApp" do
27
- # app { [200, {}, "Hello!"] }
28
- # setup { get '/' }
29
- # asserts(:status).equals(200)
16
+ # app CLASS_NAME
17
+ # app CLASS_NAME.tap { |a| }
18
+ # app(CLASS_NAME) do
19
+ # set :foo, :bar
30
20
  # end
31
- def app(app=nil, &block)
32
- setup { @app = (app || block.call) }
21
+ #
22
+ def app(app = nil &blk)
23
+ @app ||= block_given? ? app.instance_eval(&blk) : app
24
+ @app ||= Padrino.application
33
25
  end
34
26
  end
35
27
 
28
+ class Riot::Context
29
+ end
30
+
36
31
  TEST
37
32
 
38
33
  RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_CONTROLLER_TEST)
@@ -6,11 +6,18 @@ RSpec.configure do |conf|
6
6
  conf.include Rack::Test::Methods
7
7
  end
8
8
 
9
- def app
10
- ##
11
- # You can handle all padrino applications using instead:
12
- # Padrino.application
13
- CLASS_NAME.tap { |app| }
9
+ # You can use this method to custom specify a Rack app
10
+ # you want rack-test to invoke:
11
+ #
12
+ # app CLASS_NAME
13
+ # app CLASS_NAME.tap { |a| }
14
+ # app(CLASS_NAME) do
15
+ # set :foo, :bar
16
+ # end
17
+ #
18
+ def app(app = nil &blk)
19
+ @app ||= block_given? ? app.instance_eval(&blk) : app
20
+ @app ||= Padrino.application
14
21
  end
15
22
  TEST
16
23
 
@@ -7,11 +7,18 @@ require "test/unit"
7
7
  class Test::Unit::TestCase
8
8
  include Rack::Test::Methods
9
9
 
10
- def app
11
- ##
12
- # You can handle all padrino applications using instead:
13
- # Padrino.application
14
- CLASS_NAME.tap { |app| }
10
+ # You can use this method to custom specify a Rack app
11
+ # you want rack-test to invoke:
12
+ #
13
+ # app CLASS_NAME
14
+ # app CLASS_NAME.tap { |a| }
15
+ # app(CLASS_NAME) do
16
+ # set :foo, :bar
17
+ # end
18
+ #
19
+ def app(app = nil &blk)
20
+ @app ||= block_given? ? app.instance_eval(&blk) : app
21
+ @app ||= Padrino.application
15
22
  end
16
23
  end
17
24
  TEST
@@ -5,11 +5,18 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
5
5
  class Test::Unit::TestCase
6
6
  include Rack::Test::Methods
7
7
 
8
- def app
9
- ##
10
- # You can handle all padrino applications using instead:
11
- # Padrino.application
12
- CLASS_NAME.tap { |app| }
8
+ # You can use this method to custom specify a Rack app
9
+ # you want rack-test to invoke:
10
+ #
11
+ # app CLASS_NAME
12
+ # app CLASS_NAME.tap { |a| }
13
+ # app(CLASS_NAME) do
14
+ # set :foo, :bar
15
+ # end
16
+ #
17
+ def app(app = nil &blk)
18
+ @app ||= block_given? ? app.instance_eval(&blk) : app
19
+ @app ||= Padrino.application
13
20
  end
14
21
  end
15
22
  TEST
@@ -30,17 +30,23 @@
30
30
  #
31
31
  # set :delivery_method, :test
32
32
  #
33
+ # or storing emails locally:
34
+ #
35
+ # set :delivery_method, :file => {
36
+ # :location => "#{Padrino.root}/tmp/emails",
37
+ # }
38
+ #
33
39
  # and then all delivered mail will use these settings unless otherwise specified.
34
40
  #
35
41
 
36
42
  <%= @project_name %>::<%= @app_name %>.mailer :<%= @short_name %> do
37
43
  <%- if @actions.nil? || @actions.empty? -%>
38
- # Message definitions here...
44
+ # Message definitions here ...
39
45
  <%- else -%>
40
46
  <%- @actions.each do |action| -%>
41
47
 
42
48
  email <%=action.inspect%> do
43
- # Your mailer goes here
49
+ # Your mailer goes here ...
44
50
  end
45
51
 
46
52
  <%- end -%>
@@ -58,7 +58,12 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
58
58
  puts "=> Creating database '#{database}'"
59
59
  case config[:adapter]
60
60
  when 'postgres'
61
- system("createdb", "-E", charset, "-h", host, "-U", user, database)
61
+ arguments = []
62
+ arguments << "--encoding=#{charset}" if charset
63
+ arguments << "--host=#{host}" if host
64
+ arguments << "--username=#{user}" if user
65
+ arguments << database
66
+ system("createdb", *arguments)
62
67
  puts "<= dm:create executed"
63
68
  when 'mysql'
64
69
  arguments = ["--user=#{user}"]
@@ -88,7 +93,11 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
88
93
  puts "=> Dropping database '#{database}'"
89
94
  case config[:adapter]
90
95
  when 'postgres'
91
- system("dropdb", "-h", host, "-U", user, database)
96
+ arguments = []
97
+ arguments << "--host=#{host}" if host
98
+ arguments << "--username=#{user}" if user
99
+ arguments << database
100
+ system("dropdb", *arguments)
92
101
  puts "<= dm:drop executed"
93
102
  when 'mysql'
94
103
  arguments = ["--user=#{user}"]
@@ -67,7 +67,7 @@ describe "ModelGenerator" do
67
67
  end
68
68
 
69
69
  should "generate migration file versions properly" do
70
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
70
+ capture_io { generate(:project, 'sample_project', "--migration_format=number", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
71
71
  capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
72
72
  capture_io { generate(:model, 'account', "-r=#{@apptmp}/sample_project") }
73
73
  capture_io { generate(:model, 'bank', "-r=#{@apptmp}/sample_project") }
@@ -76,6 +76,15 @@ describe "ModelGenerator" do
76
76
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/003_create_banks.rb")
77
77
  end
78
78
 
79
+ should "generate migration file versions properly when timestamped" do
80
+ capture_io { generate(:project, 'sample_project', "--migration_format=timestamp", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
81
+
82
+ time = stop_time_for_test.utc.strftime("%Y%m%d%H%M%S")
83
+
84
+ capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
85
+ assert_file_exists("#{@apptmp}/sample_project/db/migrate/#{time}_create_users.rb")
86
+ end
87
+
79
88
  should "generate a default type value for fields" do
80
89
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
81
90
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
@@ -224,9 +233,9 @@ describe "ModelGenerator" do
224
233
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
225
234
  assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
226
235
  assert_match_in_file(/create_table :people do/m, migration_file_path)
227
- assert_match_in_file(/column :name, String/m, migration_file_path)
228
- assert_match_in_file(/column :created_at, DateTime/m, migration_file_path)
229
- assert_match_in_file(/column :email, String/m, migration_file_path)
236
+ assert_match_in_file(/column :name, DataMapper::Property::String/m, migration_file_path)
237
+ assert_match_in_file(/column :created_at, DataMapper::Property::DateTime/m, migration_file_path)
238
+ assert_match_in_file(/column :email, DataMapper::Property::String/m, migration_file_path)
230
239
  assert_match_in_file(/drop_table :people/m, migration_file_path)
231
240
  end
232
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-04-07 00:00:00.000000000 Z
15
+ date: 2013-05-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: padrino-core
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - '='
23
23
  - !ruby/object:Gem::Version
24
- version: 0.11.1
24
+ version: 0.11.2
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.11.1
32
+ version: 0.11.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
178
  version: '0'
179
179
  segments:
180
180
  - 0
181
- hash: 1271294022320842473
181
+ hash: -2733379671843302871
182
182
  required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  none: false
184
184
  requirements: