Skip to content

Commit

Permalink
Merge branch 'master' into set_binds
Browse files Browse the repository at this point in the history
* master: (24 commits)
  unscope should remove bind values associated with the where
  reverse_order_value= is not private, so no need to send
  avoid more dynamic symbols
  no need to to_sym
  recover from test runs that leave the database in a bad state
  updates screenshot data [ci skip]
  "serie" => "series"
  revises a few things in the getting started guide [ci skip]
  Favor canonical environment variables for secrets
  removed extra comma [ci skip]
  Only lookup `config.log_level` for stdlib `::Logger`. Closes #11665.
  Updated Changelog to reflect removal of :dependent => :restrict
  standardize on jruby_skip & rbx_skip
  fix bug in becomes! when changing from base to subclass. Closes #13272.
  highlight http://localhost:3000 in README.md. Closes #13643. [ci skip]
  doc proc/lambda arg on inclusion validation. Closes #13689. [ci skip]
  Skip Spring App Generator tests on JRuby
  fixes a typo in a CHANGELOG
  upgrade SDoc
  fixes the Gemfile generator templates
  ...

Conflicts:
	activerecord/test/cases/hot_compatibility_test.rb
  • Loading branch information
tenderlove committed Jan 14, 2014
2 parents aec4aa1 + f1764a2 commit bf48af5
Show file tree
Hide file tree
Showing 38 changed files with 291 additions and 188 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -18,7 +18,7 @@ gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0', require: false

group :doc do
gem 'sdoc'
gem 'sdoc', '~> 0.4.0'
gem 'redcarpet', '~> 2.2.2', platforms: :ruby
gem 'w3c_validators'
gem 'kindlerb'
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -59,7 +59,8 @@ independently outside Rails.

Run with `--help` or `-h` for options.

4. Using a browser, go to http://localhost:3000 and you'll see: "Welcome aboard: You're riding Ruby on Rails!"
4. Using a browser, go to `http://localhost:3000` and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"

5. Follow the guidelines to start developing your application. You may find
the following resources handy:
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Expand Up @@ -674,7 +674,7 @@ def attachments
# For example:
#
# class Notifier < ActionMailer::Base
# default from: 'no-reply@test.lindsaar.net',
# default from: 'no-reply@test.lindsaar.net'
#
# def welcome
# mail(to: 'mikel@test.lindsaar.net')
Expand Down
9 changes: 9 additions & 0 deletions actionmailer/test/abstract_unit.rb
Expand Up @@ -62,3 +62,12 @@ def set_delivery_method(method)
def restore_delivery_method
ActionMailer::Base.delivery_method = @old_delivery_method
end

# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
9 changes: 9 additions & 0 deletions actionpack/test/abstract_unit.rb
Expand Up @@ -351,3 +351,12 @@ class ProductsController < ResourcesController; end
class ImagesController < ResourcesController; end
end
end

# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
4 changes: 1 addition & 3 deletions actionpack/test/dispatch/static_test.rb
Expand Up @@ -37,10 +37,8 @@ def test_serves_static_index_file_in_directory
end

def test_served_static_file_with_non_english_filename
if RUBY_ENGINE == 'jruby '
skip "Stop skipping if following bug gets fixed: " \
jruby_skip "Stop skipping if following bug gets fixed: " \
"http://jira.codehaus.org/browse/JRUBY-7192"
end
assert_html "means hello in Japanese\n", get("/foo/#{Rack::Utils.escape("こんにちは.html")}")
end

Expand Down
8 changes: 8 additions & 0 deletions actionview/test/abstract_unit.rb
Expand Up @@ -331,3 +331,11 @@ def stderr_logger
end
end

# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
4 changes: 2 additions & 2 deletions actionview/test/template/form_collections_helper_test.rb
Expand Up @@ -182,7 +182,7 @@ def with_collection_check_boxes(*args, &block)
end

# COLLECTION CHECK BOXES
test 'collection check boxes accepts a collection and generate a serie of checkboxes for value method' do
test 'collection check boxes accepts a collection and generate a series of checkboxes for value method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name

Expand All @@ -204,7 +204,7 @@ def with_collection_check_boxes(*args, &block)
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
end

test 'collection check boxes accepts a collection and generate a serie of checkboxes with labels for label method' do
test 'collection check boxes accepts a collection and generate a series of checkboxes with labels for label method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name

Expand Down
3 changes: 2 additions & 1 deletion activemodel/lib/active_model/validations/inclusion.rb
Expand Up @@ -29,7 +29,8 @@ module HelperMethods
# * <tt>:in</tt> - An enumerable object of available items. This can be
# supplied as a proc, lambda or symbol which returns an enumerable. If the
# enumerable is a numerical range the test is performed with <tt>Range#cover?</tt>,
# otherwise with <tt>include?</tt>.
# otherwise with <tt>include?</tt>. When using a proc or lambda the instance
# under validation is passed as an argument.
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
# not included in the list").
Expand Down
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
* Fix bug in `becomes!` when changing from the base model to a STI sub-class.

Fixes #13272.

*the-web-dev*, *Yves Senn*

* Currently Active Record can be configured via the environment variable
`DATABASE_URL` or by manually injecting a hash of values which is what Rails does,
reading in `database.yml` and setting Active Record appropriately. Active Record
Expand Down
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/enum.rb
Expand Up @@ -87,6 +87,9 @@ def enum(definitions)
# def status() STATUS.key self[:status] end
define_method(name) { enum_values.key self[name] }

# def status_before_type_cast() STATUS.key self[:status] end
define_method("#{name}_before_type_cast") { enum_values.key self[name] }

pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index
pairs.each do |value, i|
enum_values[value] = i
Expand Down
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/persistence.rb
Expand Up @@ -196,7 +196,11 @@ def becomes(klass)
# share the same set of attributes.
def becomes!(klass)
became = becomes(klass)
became.public_send("#{klass.inheritance_column}=", klass.sti_name) unless self.class.descends_from_active_record?
sti_type = nil
if !klass.descends_from_active_record?
sti_type = klass.sti_name
end
became.public_send("#{klass.inheritance_column}=", sti_type)
became
end

Expand Down
10 changes: 6 additions & 4 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -858,11 +858,11 @@ def symbol_unscoping(scope)
end

single_val_method = Relation::SINGLE_VALUE_METHODS.include?(scope)
unscope_code = :"#{scope}_value#{'s' unless single_val_method}="
unscope_code = "#{scope}_value#{'s' unless single_val_method}="

case scope
when :order
self.send(:reverse_order_value=, false)
self.reverse_order_value = false
result = []
else
result = [] unless single_val_method
Expand All @@ -872,17 +872,19 @@ def symbol_unscoping(scope)
end

def where_unscoping(target_value)
target_value_sym = target_value.to_sym
target_value = target_value.to_s

where_values.reject! do |rel|
case rel
when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name.to_sym == target_value_sym
subrelation.name == target_value
else
raise "unscope(where: #{target_value.inspect}) failed: unscoping #{rel.class} is unimplemented."
end
end

bind_values.reject! { |col,_| col.name == target_value }
end

def custom_join_ast(table, joins)
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/enum_test.rb
Expand Up @@ -88,4 +88,8 @@ class EnumTest < ActiveRecord::TestCase
assert Book.written.create.written?
assert Book.read.create.read?
end

test "_before_type_cast returns the enum label (required for form fields)" do
assert_equal "proposed", @book.status_before_type_cast
end
end
2 changes: 1 addition & 1 deletion activerecord/test/cases/hot_compatibility_test.rb
Expand Up @@ -5,7 +5,7 @@ class HotCompatibilityTest < ActiveRecord::TestCase

setup do
@klass = Class.new(ActiveRecord::Base) do
connection.create_table :hot_compatibilities, :force => true do |t|
connection.create_table :hot_compatibilities, force: true do |t|
t.string :foo
t.string :bar
end
Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/inheritance_test.rb
Expand Up @@ -128,6 +128,17 @@ def test_alt_becomes_works_with_sti
assert_kind_of Cabbage, cabbage
end

def test_alt_becomes_bang_resets_inheritance_type_column
vegetable = Vegetable.create!(name: "Red Pepper")
assert_nil vegetable.custom_type

cabbage = vegetable.becomes!(Cabbage)
assert_equal "Cabbage", cabbage.custom_type

vegetable = cabbage.becomes!(Vegetable)
assert_nil cabbage.custom_type
end

def test_inheritance_find_all
companies = Company.all.merge!(:order => 'id').to_a
assert_kind_of Firm, companies[0], "37signals should be a firm"
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -1524,6 +1524,15 @@ def test_presence
assert merged.to_sql.include?("bbq")
end

def test_unscope_removes_binds
left = Post.where(id: Arel::Nodes::BindParam.new('?'))
column = Post.columns_hash['id']
left.bind_values += [[column, 20]]

relation = left.unscope(where: :id)
assert_equal [], relation.bind_values
end

def test_merging_removes_rhs_bind_parameters
left = Post.where(id: Arel::Nodes::BindParam.new('?'))
column = Post.columns_hash['id']
Expand Down
3 changes: 1 addition & 2 deletions activesupport/lib/active_support/core_ext/range/each.rb
@@ -1,5 +1,4 @@
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/object/acts_like'

class Range #:nodoc:

Expand All @@ -17,7 +16,7 @@ def step_with_time_with_zone(n = 1, &block)

private
def ensure_iteration_allowed
if first.acts_like?(:time)
if first.is_a?(Time)
raise TypeError, "can't iterate from #{first.class}"
end
end
Expand Down
24 changes: 12 additions & 12 deletions activesupport/lib/active_support/core_ext/string/output_safety.rb
Expand Up @@ -70,9 +70,20 @@ def html_escape_once(s)
# them inside a script tag to avoid XSS vulnerability:
#
# <script>
# var currentUser = <%= json_escape current_user.to_json %>;
# var currentUser = <%= raw json_escape(current_user.to_json) %>;
# </script>
#
# It is necessary to +raw+ the result of +json_escape+, so that quotation marks
# don't get converted to <tt>&quot;</tt> entities. +json_escape+ doesn't
# automatically flag the result as HTML safe, since the raw value is unsafe to
# use inside HTML attributes.
#
# If you need to output JSON elsewhere in your HTML, you can just do something
# like this, as any unsafe characters (including quotation marks) will be
# automatically escaped for you:
#
# <div data-user-info="<%= current_user.to_json %>">...</div>
#
# WARNING: this helper only works with valid JSON. Using this on non-JSON values
# will open up serious XSS vulnerabilities. For example, if you replace the
# +current_user.to_json+ in the example above with user input instead, the browser
Expand All @@ -88,17 +99,6 @@ def html_escape_once(s)
# is recommended that you always apply this helper (other libraries, such as the
# JSON gem, do not provide this kind of protection by default; also some gems
# might override +to_json+ to bypass Active Support's encoder).
#
# The output of this helper method is marked as HTML safe so that you can directly
# include it inside a <tt><script></tt> tag as shown above.
#
# However, it is NOT safe to use the output of this inside an HTML attribute,
# because quotation marks are not escaped. Doing so might break your page's layout.
# If you intend to use this inside an HTML attribute, you should use the
# +html_escape+ helper (or its +h+ alias) instead:
#
# <div data-user-info="<%= h current_user.to_json %>">...</div>
#
def json_escape(s)
result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
s.html_safe? ? result.html_safe : result
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/abstract_unit.rb
Expand Up @@ -34,5 +34,5 @@ def rubinius_skip(message = '')

# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if RUBY_ENGINE == 'jruby'
skip message if defined?(JRUBY_VERSION)
end
4 changes: 4 additions & 0 deletions activesupport/test/core_ext/range_ext_test.rb
Expand Up @@ -112,4 +112,8 @@ def test_include_on_time_with_zone
end
end

def test_date_time_with_each
datetime = DateTime.now
assert ((datetime - 1.hour)..datetime).each {}
end
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
41 changes: 19 additions & 22 deletions guides/code/getting_started/Gemfile
@@ -1,43 +1,40 @@
source 'https://rubygems.org'

gem 'rails', '4.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails'

gem 'sass-rails', '~> 4.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'

gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.0.3'
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# To use ActiveModel has_secure_password
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/jonleighton/spring
gem 'spring', group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano', group: :development
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# To use debugger
# gem 'debugger'

0 comments on commit bf48af5

Please sign in to comment.