railties 4.0.0.beta1 → 4.0.0.rc1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +120 -27
- data/RDOC_MAIN.rdoc +73 -0
- data/bin/rails +3 -1
- data/lib/rails/api/task.rb +158 -0
- data/lib/rails/app_rails_loader.rb +44 -20
- data/lib/rails/application.rb +55 -32
- data/lib/rails/application/configuration.rb +9 -7
- data/lib/rails/commands.rb +2 -0
- data/lib/rails/commands/console.rb +3 -1
- data/lib/rails/commands/server.rb +6 -2
- data/lib/rails/engine.rb +4 -3
- data/lib/rails/generators/actions.rb +1 -1
- data/lib/rails/generators/app_base.rb +52 -30
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +10 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +9 -9
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb +1 -2
- data/lib/rails/generators/generated_attribute.rb +4 -0
- data/lib/rails/generators/named_base.rb +2 -1
- data/lib/rails/generators/rails/app/templates/Gemfile +9 -4
- data/lib/rails/generators/rails/app/templates/config.ru +1 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +3 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -0
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/public/404.html +41 -10
- data/lib/rails/generators/rails/app/templates/public/422.html +42 -10
- data/lib/rails/generators/rails/app/templates/public/500.html +41 -10
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +1 -1
- data/lib/rails/generators/rails/model/USAGE +16 -10
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +9 -5
- data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +0 -3
- data/lib/rails/generators/rails/plugin_new/templates/Gemfile +0 -8
- data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +4 -8
- data/lib/rails/generators/rails/plugin_new/templates/rails/javascripts.js +13 -0
- data/lib/rails/generators/rails/plugin_new/templates/rails/stylesheets.css +13 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +1 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
- data/lib/rails/generators/test_case.rb +6 -211
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +7 -9
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/testing/assertions.rb +121 -0
- data/lib/rails/generators/testing/behaviour.rb +106 -0
- data/lib/rails/generators/testing/setup_and_teardown.rb +18 -0
- data/lib/rails/info.rb +2 -2
- data/lib/rails/tasks/documentation.rake +2 -46
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
- data/lib/rails/test_unit/railtie.rb +4 -0
- data/lib/rails/test_unit/sub_test_task.rb +78 -1
- data/lib/rails/test_unit/testing.rake +32 -42
- data/lib/rails/version.rb +3 -3
- metadata +15 -23
- data/lib/rails/generators/rails/app/templates/app/assets/images/rails.png +0 -0
@@ -19,9 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
<% end -%>
|
20
20
|
|
21
21
|
<%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
|
22
|
-
<% if engine? && !options[:skip_javascript] -%>
|
23
|
-
# s.add_dependency "<%= "#{options[:javascript]}-rails" %>"
|
24
|
-
<% end -%>
|
25
22
|
<% unless options[:skip_active_record] -%>
|
26
23
|
|
27
24
|
s.add_development_dependency "<%= gem_for_database %>"
|
@@ -2,9 +2,6 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
<% if options[:skip_gemspec] -%>
|
4
4
|
<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>"
|
5
|
-
<% if engine? && !options[:skip_javascript] -%>
|
6
|
-
# gem "<%= "#{options[:javascript]}-rails" %>"
|
7
|
-
<% end -%>
|
8
5
|
<% else -%>
|
9
6
|
# Declare your gem's dependencies in <%= name %>.gemspec.
|
10
7
|
# Bundler will treat runtime dependencies like base dependencies, and
|
@@ -12,11 +9,6 @@ source "https://rubygems.org"
|
|
12
9
|
gemspec
|
13
10
|
<% end -%>
|
14
11
|
|
15
|
-
<% unless options[:javascript] == 'jquery' -%>
|
16
|
-
# jquery-rails is used by the dummy application
|
17
|
-
gem "jquery-rails"
|
18
|
-
|
19
|
-
<% end -%>
|
20
12
|
<% if options[:skip_gemspec] -%>
|
21
13
|
group :development do
|
22
14
|
gem "<%= gem_for_database %>"
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
1
|
+
# Set up gems listed in the Gemfile.
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
|
2
3
|
|
3
|
-
if File.
|
4
|
-
|
5
|
-
require 'bundler'
|
6
|
-
Bundler.setup
|
7
|
-
end
|
8
|
-
|
9
|
-
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
4
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
5
|
+
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -10,6 +10,7 @@ module Rails
|
|
10
10
|
class_option :stylesheet_engine, desc: "Engine for Stylesheets"
|
11
11
|
|
12
12
|
def handle_skip
|
13
|
+
@options = @options.merge(stylesheets: false) unless options[:assets]
|
13
14
|
@options = @options.merge(stylesheet_engine: false) unless options[:stylesheets]
|
14
15
|
end
|
15
16
|
|
@@ -56,7 +56,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
56
56
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
57
57
|
end
|
58
58
|
|
59
|
-
#
|
59
|
+
# Only allow a trusted parameter "white list" through.
|
60
60
|
def <%= "#{singular_table_name}_params" %>
|
61
61
|
<%- if attributes_names.empty? -%>
|
62
62
|
params[<%= ":#{singular_table_name}" %>]
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'active_support/core_ext/hash/reverse_merge'
|
4
|
-
require 'active_support/core_ext/kernel/reporting'
|
5
1
|
require 'rails/generators'
|
2
|
+
require 'rails/generators/testing/behaviour'
|
3
|
+
require 'rails/generators/testing/setup_and_teardown'
|
4
|
+
require 'rails/generators/testing/assertions'
|
6
5
|
require 'fileutils'
|
7
6
|
|
8
7
|
module Rails
|
@@ -27,215 +26,11 @@ module Rails
|
|
27
26
|
# setup :prepare_destination
|
28
27
|
# end
|
29
28
|
class TestCase < ActiveSupport::TestCase
|
29
|
+
include Rails::Generators::Testing::Behaviour
|
30
|
+
include Rails::Generators::Testing::SetupAndTeardown
|
31
|
+
include Rails::Generators::Testing::Assertions
|
30
32
|
include FileUtils
|
31
33
|
|
32
|
-
class_attribute :destination_root, :current_path, :generator_class, :default_arguments
|
33
|
-
|
34
|
-
# Generators frequently change the current path using +FileUtils.cd+.
|
35
|
-
# So we need to store the path at file load and revert back to it after each test.
|
36
|
-
self.current_path = File.expand_path(Dir.pwd)
|
37
|
-
self.default_arguments = []
|
38
|
-
|
39
|
-
def setup # :nodoc:
|
40
|
-
destination_root_is_set?
|
41
|
-
ensure_current_path
|
42
|
-
super
|
43
|
-
end
|
44
|
-
|
45
|
-
def teardown # :nodoc:
|
46
|
-
ensure_current_path
|
47
|
-
super
|
48
|
-
end
|
49
|
-
|
50
|
-
# Sets which generator should be tested:
|
51
|
-
#
|
52
|
-
# tests AppGenerator
|
53
|
-
def self.tests(klass)
|
54
|
-
self.generator_class = klass
|
55
|
-
end
|
56
|
-
|
57
|
-
# Sets default arguments on generator invocation. This can be overwritten when
|
58
|
-
# invoking it.
|
59
|
-
#
|
60
|
-
# arguments %w(app_name --skip-active-record)
|
61
|
-
def self.arguments(array)
|
62
|
-
self.default_arguments = array
|
63
|
-
end
|
64
|
-
|
65
|
-
# Sets the destination of generator files:
|
66
|
-
#
|
67
|
-
# destination File.expand_path("../tmp", File.dirname(__FILE__))
|
68
|
-
def self.destination(path)
|
69
|
-
self.destination_root = path
|
70
|
-
end
|
71
|
-
|
72
|
-
# Asserts a given file exists. You need to supply an absolute path or a path relative
|
73
|
-
# to the configured destination:
|
74
|
-
#
|
75
|
-
# assert_file "config/environment.rb"
|
76
|
-
#
|
77
|
-
# You can also give extra arguments. If the argument is a regexp, it will check if the
|
78
|
-
# regular expression matches the given file content. If it's a string, it compares the
|
79
|
-
# file with the given string:
|
80
|
-
#
|
81
|
-
# assert_file "config/environment.rb", /initialize/
|
82
|
-
#
|
83
|
-
# Finally, when a block is given, it yields the file content:
|
84
|
-
#
|
85
|
-
# assert_file "app/controllers/products_controller.rb" do |controller|
|
86
|
-
# assert_instance_method :index, controller do |index|
|
87
|
-
# assert_match(/Product\.all/, index)
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
def assert_file(relative, *contents)
|
91
|
-
absolute = File.expand_path(relative, destination_root)
|
92
|
-
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
93
|
-
|
94
|
-
read = File.read(absolute) if block_given? || !contents.empty?
|
95
|
-
yield read if block_given?
|
96
|
-
|
97
|
-
contents.each do |content|
|
98
|
-
case content
|
99
|
-
when String
|
100
|
-
assert_equal content, read
|
101
|
-
when Regexp
|
102
|
-
assert_match content, read
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
alias :assert_directory :assert_file
|
107
|
-
|
108
|
-
# Asserts a given file does not exist. You need to supply an absolute path or a
|
109
|
-
# path relative to the configured destination:
|
110
|
-
#
|
111
|
-
# assert_no_file "config/random.rb"
|
112
|
-
def assert_no_file(relative)
|
113
|
-
absolute = File.expand_path(relative, destination_root)
|
114
|
-
assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
|
115
|
-
end
|
116
|
-
alias :assert_no_directory :assert_no_file
|
117
|
-
|
118
|
-
# Asserts a given migration exists. You need to supply an absolute path or a
|
119
|
-
# path relative to the configured destination:
|
120
|
-
#
|
121
|
-
# assert_migration "db/migrate/create_products.rb"
|
122
|
-
#
|
123
|
-
# This method manipulates the given path and tries to find any migration which
|
124
|
-
# matches the migration name. For example, the call above is converted to:
|
125
|
-
#
|
126
|
-
# assert_file "db/migrate/003_create_products.rb"
|
127
|
-
#
|
128
|
-
# Consequently, assert_migration accepts the same arguments has assert_file.
|
129
|
-
def assert_migration(relative, *contents, &block)
|
130
|
-
file_name = migration_file_name(relative)
|
131
|
-
assert file_name, "Expected migration #{relative} to exist, but was not found"
|
132
|
-
assert_file file_name, *contents, &block
|
133
|
-
end
|
134
|
-
|
135
|
-
# Asserts a given migration does not exist. You need to supply an absolute path or a
|
136
|
-
# path relative to the configured destination:
|
137
|
-
#
|
138
|
-
# assert_no_migration "db/migrate/create_products.rb"
|
139
|
-
def assert_no_migration(relative)
|
140
|
-
file_name = migration_file_name(relative)
|
141
|
-
assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
|
142
|
-
end
|
143
|
-
|
144
|
-
# Asserts the given class method exists in the given content. This method does not detect
|
145
|
-
# class methods inside (class << self), only class methods which starts with "self.".
|
146
|
-
# When a block is given, it yields the content of the method.
|
147
|
-
#
|
148
|
-
# assert_migration "db/migrate/create_products.rb" do |migration|
|
149
|
-
# assert_class_method :up, migration do |up|
|
150
|
-
# assert_match(/create_table/, up)
|
151
|
-
# end
|
152
|
-
# end
|
153
|
-
def assert_class_method(method, content, &block)
|
154
|
-
assert_instance_method "self.#{method}", content, &block
|
155
|
-
end
|
156
|
-
|
157
|
-
# Asserts the given method exists in the given content. When a block is given,
|
158
|
-
# it yields the content of the method.
|
159
|
-
#
|
160
|
-
# assert_file "app/controllers/products_controller.rb" do |controller|
|
161
|
-
# assert_instance_method :index, controller do |index|
|
162
|
-
# assert_match(/Product\.all/, index)
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
def assert_instance_method(method, content)
|
166
|
-
assert content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m, "Expected to have method #{method}"
|
167
|
-
yield $3.strip if block_given?
|
168
|
-
end
|
169
|
-
alias :assert_method :assert_instance_method
|
170
|
-
|
171
|
-
# Asserts the given attribute type gets translated to a field type
|
172
|
-
# properly:
|
173
|
-
#
|
174
|
-
# assert_field_type :date, :date_select
|
175
|
-
def assert_field_type(attribute_type, field_type)
|
176
|
-
assert_equal(field_type, create_generated_attribute(attribute_type).field_type)
|
177
|
-
end
|
178
|
-
|
179
|
-
# Asserts the given attribute type gets a proper default value:
|
180
|
-
#
|
181
|
-
# assert_field_default_value :string, "MyString"
|
182
|
-
def assert_field_default_value(attribute_type, value)
|
183
|
-
assert_equal(value, create_generated_attribute(attribute_type).default)
|
184
|
-
end
|
185
|
-
|
186
|
-
# Runs the generator configured for this class. The first argument is an array like
|
187
|
-
# command line arguments:
|
188
|
-
#
|
189
|
-
# class AppGeneratorTest < Rails::Generators::TestCase
|
190
|
-
# tests AppGenerator
|
191
|
-
# destination File.expand_path("../tmp", File.dirname(__FILE__))
|
192
|
-
# teardown :cleanup_destination_root
|
193
|
-
#
|
194
|
-
# test "database.yml is not created when skipping Active Record" do
|
195
|
-
# run_generator %w(myapp --skip-active-record)
|
196
|
-
# assert_no_file "config/database.yml"
|
197
|
-
# end
|
198
|
-
# end
|
199
|
-
#
|
200
|
-
# You can provide a configuration hash as second argument. This method returns the output
|
201
|
-
# printed by the generator.
|
202
|
-
def run_generator(args=self.default_arguments, config={})
|
203
|
-
capture(:stdout) { self.generator_class.start(args, config.reverse_merge(destination_root: destination_root)) }
|
204
|
-
end
|
205
|
-
|
206
|
-
# Instantiate the generator.
|
207
|
-
def generator(args=self.default_arguments, options={}, config={})
|
208
|
-
@generator ||= self.generator_class.new(args, options, config.reverse_merge(destination_root: destination_root))
|
209
|
-
end
|
210
|
-
|
211
|
-
# Create a Rails::Generators::GeneratedAttribute by supplying the
|
212
|
-
# attribute type and, optionally, the attribute name:
|
213
|
-
#
|
214
|
-
# create_generated_attribute(:string, 'name')
|
215
|
-
def create_generated_attribute(attribute_type, name = 'test', index = nil)
|
216
|
-
Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':'))
|
217
|
-
end
|
218
|
-
|
219
|
-
protected
|
220
|
-
|
221
|
-
def destination_root_is_set? # :nodoc:
|
222
|
-
raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
|
223
|
-
end
|
224
|
-
|
225
|
-
def ensure_current_path # :nodoc:
|
226
|
-
cd current_path
|
227
|
-
end
|
228
|
-
|
229
|
-
def prepare_destination # :nodoc:
|
230
|
-
rm_rf(destination_root)
|
231
|
-
mkdir_p(destination_root)
|
232
|
-
end
|
233
|
-
|
234
|
-
def migration_file_name(relative) # :nodoc:
|
235
|
-
absolute = File.expand_path(relative, destination_root)
|
236
|
-
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
|
237
|
-
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
238
|
-
end
|
239
34
|
end
|
240
35
|
end
|
241
36
|
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
2
|
-
|
3
2
|
<% unless attributes.empty? -%>
|
4
|
-
one
|
3
|
+
<% %w(one two).each do |name| %>
|
4
|
+
<%= name %>:
|
5
5
|
<% attributes.each do |attribute| -%>
|
6
|
+
<%- if attribute.password_digest? -%>
|
7
|
+
password_digest: <%%= BCrypt::Password.create('secret') %>
|
8
|
+
<%- else -%>
|
6
9
|
<%= yaml_key_value(attribute.column_name, attribute.default) %>
|
7
|
-
<%- if attribute.polymorphic? -%>
|
8
|
-
<%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %>
|
9
10
|
<%- end -%>
|
10
|
-
<% end -%>
|
11
|
-
|
12
|
-
two:
|
13
|
-
<% attributes.each do |attribute| -%>
|
14
|
-
<%= yaml_key_value(attribute.column_name, attribute.default) %>
|
15
11
|
<%- if attribute.polymorphic? -%>
|
16
12
|
<%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %>
|
17
13
|
<%- end -%>
|
18
14
|
<% end -%>
|
15
|
+
<% end -%>
|
19
16
|
<% else -%>
|
17
|
+
|
20
18
|
# This model initially had no columns defined. If you add columns to the
|
21
19
|
# model remove the '{}' from the fixture names and add the columns immediately
|
22
20
|
# below each fixture, per the syntax in the comments below
|
@@ -21,7 +21,11 @@ module TestUnit # :nodoc:
|
|
21
21
|
return if attributes_names.empty?
|
22
22
|
|
23
23
|
attributes_names.map do |name|
|
24
|
-
|
24
|
+
if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
|
25
|
+
"#{name}: 'secret'"
|
26
|
+
else
|
27
|
+
"#{name}: @#{singular_table_name}.#{name}"
|
28
|
+
end
|
25
29
|
end.sort.join(', ')
|
26
30
|
end
|
27
31
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
module Testing
|
4
|
+
module Assertions
|
5
|
+
# Asserts a given file exists. You need to supply an absolute path or a path relative
|
6
|
+
# to the configured destination:
|
7
|
+
#
|
8
|
+
# assert_file "config/environment.rb"
|
9
|
+
#
|
10
|
+
# You can also give extra arguments. If the argument is a regexp, it will check if the
|
11
|
+
# regular expression matches the given file content. If it's a string, it compares the
|
12
|
+
# file with the given string:
|
13
|
+
#
|
14
|
+
# assert_file "config/environment.rb", /initialize/
|
15
|
+
#
|
16
|
+
# Finally, when a block is given, it yields the file content:
|
17
|
+
#
|
18
|
+
# assert_file "app/controllers/products_controller.rb" do |controller|
|
19
|
+
# assert_instance_method :index, controller do |index|
|
20
|
+
# assert_match(/Product\.all/, index)
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
def assert_file(relative, *contents)
|
24
|
+
absolute = File.expand_path(relative, destination_root)
|
25
|
+
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
26
|
+
|
27
|
+
read = File.read(absolute) if block_given? || !contents.empty?
|
28
|
+
yield read if block_given?
|
29
|
+
|
30
|
+
contents.each do |content|
|
31
|
+
case content
|
32
|
+
when String
|
33
|
+
assert_equal content, read
|
34
|
+
when Regexp
|
35
|
+
assert_match content, read
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias :assert_directory :assert_file
|
40
|
+
|
41
|
+
# Asserts a given file does not exist. You need to supply an absolute path or a
|
42
|
+
# path relative to the configured destination:
|
43
|
+
#
|
44
|
+
# assert_no_file "config/random.rb"
|
45
|
+
def assert_no_file(relative)
|
46
|
+
absolute = File.expand_path(relative, destination_root)
|
47
|
+
assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
|
48
|
+
end
|
49
|
+
alias :assert_no_directory :assert_no_file
|
50
|
+
|
51
|
+
# Asserts a given migration exists. You need to supply an absolute path or a
|
52
|
+
# path relative to the configured destination:
|
53
|
+
#
|
54
|
+
# assert_migration "db/migrate/create_products.rb"
|
55
|
+
#
|
56
|
+
# This method manipulates the given path and tries to find any migration which
|
57
|
+
# matches the migration name. For example, the call above is converted to:
|
58
|
+
#
|
59
|
+
# assert_file "db/migrate/003_create_products.rb"
|
60
|
+
#
|
61
|
+
# Consequently, assert_migration accepts the same arguments has assert_file.
|
62
|
+
def assert_migration(relative, *contents, &block)
|
63
|
+
file_name = migration_file_name(relative)
|
64
|
+
assert file_name, "Expected migration #{relative} to exist, but was not found"
|
65
|
+
assert_file file_name, *contents, &block
|
66
|
+
end
|
67
|
+
|
68
|
+
# Asserts a given migration does not exist. You need to supply an absolute path or a
|
69
|
+
# path relative to the configured destination:
|
70
|
+
#
|
71
|
+
# assert_no_migration "db/migrate/create_products.rb"
|
72
|
+
def assert_no_migration(relative)
|
73
|
+
file_name = migration_file_name(relative)
|
74
|
+
assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
|
75
|
+
end
|
76
|
+
|
77
|
+
# Asserts the given class method exists in the given content. This method does not detect
|
78
|
+
# class methods inside (class << self), only class methods which starts with "self.".
|
79
|
+
# When a block is given, it yields the content of the method.
|
80
|
+
#
|
81
|
+
# assert_migration "db/migrate/create_products.rb" do |migration|
|
82
|
+
# assert_class_method :up, migration do |up|
|
83
|
+
# assert_match(/create_table/, up)
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
def assert_class_method(method, content, &block)
|
87
|
+
assert_instance_method "self.#{method}", content, &block
|
88
|
+
end
|
89
|
+
|
90
|
+
# Asserts the given method exists in the given content. When a block is given,
|
91
|
+
# it yields the content of the method.
|
92
|
+
#
|
93
|
+
# assert_file "app/controllers/products_controller.rb" do |controller|
|
94
|
+
# assert_instance_method :index, controller do |index|
|
95
|
+
# assert_match(/Product\.all/, index)
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
def assert_instance_method(method, content)
|
99
|
+
assert content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m, "Expected to have method #{method}"
|
100
|
+
yield $3.strip if block_given?
|
101
|
+
end
|
102
|
+
alias :assert_method :assert_instance_method
|
103
|
+
|
104
|
+
# Asserts the given attribute type gets translated to a field type
|
105
|
+
# properly:
|
106
|
+
#
|
107
|
+
# assert_field_type :date, :date_select
|
108
|
+
def assert_field_type(attribute_type, field_type)
|
109
|
+
assert_equal(field_type, create_generated_attribute(attribute_type).field_type)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Asserts the given attribute type gets a proper default value:
|
113
|
+
#
|
114
|
+
# assert_field_default_value :string, "MyString"
|
115
|
+
def assert_field_default_value(attribute_type, value)
|
116
|
+
assert_equal(value, create_generated_attribute(attribute_type).default)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|