mirror of https://github.com/rails/rails
Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the future
Follow up of #31432.
This commit is contained in:
parent
65e994c063
commit
245c1dafa8
|
@ -58,6 +58,9 @@ Layout/IndentationConsistency:
|
||||||
Layout/IndentationWidth:
|
Layout/IndentationWidth:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Layout/LeadingCommentSpace:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Layout/SpaceAfterColon:
|
Layout/SpaceAfterColon:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -66,7 +66,7 @@ group :job do
|
||||||
gem "sneakers", require: false
|
gem "sneakers", require: false
|
||||||
gem "que", require: false
|
gem "que", require: false
|
||||||
gem "backburner", require: false
|
gem "backburner", require: false
|
||||||
#TODO: add qu after it support Rails 5.1
|
# TODO: add qu after it support Rails 5.1
|
||||||
# gem 'qu-rails', github: "bkeepers/qu", branch: "master", require: false
|
# gem 'qu-rails', github: "bkeepers/qu", branch: "master", require: false
|
||||||
# gem "qu-redis", require: false
|
# gem "qu-redis", require: false
|
||||||
gem "delayed_job_active_record", require: false
|
gem "delayed_job_active_record", require: false
|
||||||
|
|
|
@ -9,16 +9,16 @@ module ActionDispatch
|
||||||
" #{from} -> #{to} [label=\"#{sym || 'ε'}\"];"
|
" #{from} -> #{to} [label=\"#{sym || 'ε'}\"];"
|
||||||
}
|
}
|
||||||
|
|
||||||
#memo_nodes = memos.values.flatten.map { |n|
|
# memo_nodes = memos.values.flatten.map { |n|
|
||||||
# label = n
|
# label = n
|
||||||
# if Journey::Route === n
|
# if Journey::Route === n
|
||||||
# label = "#{n.verb.source} #{n.path.spec}"
|
# label = "#{n.verb.source} #{n.path.spec}"
|
||||||
# end
|
# end
|
||||||
# " #{n.object_id} [label=\"#{label}\", shape=box];"
|
# " #{n.object_id} [label=\"#{label}\", shape=box];"
|
||||||
#}
|
# }
|
||||||
#memo_edges = memos.flat_map { |k, memos|
|
# memo_edges = memos.flat_map { |k, memos|
|
||||||
# (memos || []).map { |v| " #{k} -> #{v.object_id};" }
|
# (memos || []).map { |v| " #{k} -> #{v.object_id};" }
|
||||||
#}.uniq
|
# }.uniq
|
||||||
|
|
||||||
<<-eodot
|
<<-eodot
|
||||||
digraph nfa {
|
digraph nfa {
|
||||||
|
|
|
@ -35,7 +35,6 @@ module ActionPack
|
||||||
as: "blog"
|
as: "blog"
|
||||||
|
|
||||||
resources :people
|
resources :people
|
||||||
#match 'legacy/people' => "people#index", :legacy => "true"
|
|
||||||
|
|
||||||
get "symbols", controller: :symbols, action: :show, name: :as_symbol
|
get "symbols", controller: :symbols, action: :show, name: :as_symbol
|
||||||
get "id_default(/:id)" => "foo#id_default", :id => 1
|
get "id_default(/:id)" => "foo#id_default", :id => 1
|
||||||
|
|
|
@ -19,7 +19,7 @@ class UrlRewriterTests < ActionController::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@params = {}
|
@params = {}
|
||||||
@rewriter = Rewriter.new(@request) #.new(@request, @params)
|
@rewriter = Rewriter.new(@request)
|
||||||
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
||||||
r.draw do
|
r.draw do
|
||||||
ActiveSupport::Deprecation.silence do
|
ActiveSupport::Deprecation.silence do
|
||||||
|
|
|
@ -4225,7 +4225,7 @@ class TestGlobRoutingMapper < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#include Routes.url_helpers
|
# include Routes.url_helpers
|
||||||
APP = build_app Routes
|
APP = build_app Routes
|
||||||
def app; APP end
|
def app; APP end
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ module ActionDispatch
|
||||||
def test_unicode
|
def test_unicode
|
||||||
get "/ほげ", to: "foo#bar"
|
get "/ほげ", to: "foo#bar"
|
||||||
|
|
||||||
#match the escaped version of /ほげ
|
# match the escaped version of /ほげ
|
||||||
env = rails_env "PATH_INFO" => "/%E3%81%BB%E3%81%92"
|
env = rails_env "PATH_INFO" => "/%E3%81%BB%E3%81%92"
|
||||||
called = false
|
called = false
|
||||||
router.recognize(env) do |r, params|
|
router.recognize(env) do |r, params|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
module Quiz
|
module Quiz
|
||||||
#Models
|
# Models
|
||||||
Question = Struct.new(:name, :id) do
|
Question = Struct.new(:name, :id) do
|
||||||
extend ActiveModel::Naming
|
extend ActiveModel::Naming
|
||||||
include ActiveModel::Conversion
|
include ActiveModel::Conversion
|
||||||
|
|
|
@ -38,7 +38,7 @@ class ActiveRecordTestConnector
|
||||||
end
|
end
|
||||||
rescue Exception => e # errors from ActiveRecord setup
|
rescue Exception => e # errors from ActiveRecord setup
|
||||||
$stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
|
$stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
|
||||||
#$stderr.puts " #{e.backtrace.join("\n ")}\n"
|
# $stderr.puts " #{e.backtrace.join("\n ")}\n"
|
||||||
self.able_to_connect = false
|
self.able_to_connect = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class NumberHelperTest < ActionView::TestCase
|
||||||
assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, units: volume)
|
assert_equal "1.23 <b>km3</b>", number_to_human(1_234_567_000_000, units: volume)
|
||||||
assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, units: volume)
|
assert_equal "1.23 <b>Pl</b>", number_to_human(1_234_567_000_000_000, units: volume)
|
||||||
|
|
||||||
#Including fractionals
|
# Including fractionals
|
||||||
distance = { mili: "<b>mm</b>", centi: "<b>cm</b>", deci: "<b>dm</b>", unit: "<b>m</b>",
|
distance = { mili: "<b>mm</b>", centi: "<b>cm</b>", deci: "<b>dm</b>", unit: "<b>m</b>",
|
||||||
ten: "<b>dam</b>", hundred: "<b>hm</b>", thousand: "<b>km</b>",
|
ten: "<b>dam</b>", hundred: "<b>hm</b>", thousand: "<b>km</b>",
|
||||||
micro: "<b>um</b>", nano: "<b>nm</b>", pico: "<b>pm</b>", femto: "<b>fm</b>" }
|
micro: "<b>um</b>", nano: "<b>nm</b>", pico: "<b>pm</b>", femto: "<b>fm</b>" }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require "rake/testtask"
|
require "rake/testtask"
|
||||||
|
|
||||||
#TODO: add qu back to the list after it support Rails 5.1
|
# TODO: add qu back to the list after it support Rails 5.1
|
||||||
ACTIVEJOB_ADAPTERS = %w(async inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner test)
|
ACTIVEJOB_ADAPTERS = %w(async inline delayed_job que queue_classic resque sidekiq sneakers sucker_punch backburner test)
|
||||||
ACTIVEJOB_ADAPTERS.delete("queue_classic") if defined?(JRUBY_VERSION)
|
ACTIVEJOB_ADAPTERS.delete("queue_classic") if defined?(JRUBY_VERSION)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
#copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb
|
# copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
|
|
||||||
# An in-memory backend suitable only for testing. Tries to behave as if it were an ORM.
|
# An in-memory backend suitable only for testing. Tries to behave as if it were an ORM.
|
||||||
|
|
|
@ -1073,7 +1073,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_load_with_sti_sharing_association
|
def test_load_with_sti_sharing_association
|
||||||
assert_queries(2) do #should not do 1 query per subclass
|
assert_queries(2) do # should not do 1 query per subclass
|
||||||
Comment.includes(:post).to_a
|
Comment.includes(:post).to_a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -100,7 +100,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_has_one_through_eager_loading
|
def test_has_one_through_eager_loading
|
||||||
members = assert_queries(3) do #base table, through table, clubs table
|
members = assert_queries(3) do # base table, through table, clubs table
|
||||||
Member.all.merge!(includes: :club, where: ["name = ?", "Groucho Marx"]).to_a
|
Member.all.merge!(includes: :club, where: ["name = ?", "Groucho Marx"]).to_a
|
||||||
end
|
end
|
||||||
assert_equal 1, members.size
|
assert_equal 1, members.size
|
||||||
|
@ -108,7 +108,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_has_one_through_eager_loading_through_polymorphic
|
def test_has_one_through_eager_loading_through_polymorphic
|
||||||
members = assert_queries(3) do #base table, through table, clubs table
|
members = assert_queries(3) do # base table, through table, clubs table
|
||||||
Member.all.merge!(includes: :sponsor_club, where: ["name = ?", "Groucho Marx"]).to_a
|
Member.all.merge!(includes: :sponsor_club, where: ["name = ?", "Groucho Marx"]).to_a
|
||||||
end
|
end
|
||||||
assert_equal 1, members.size
|
assert_equal 1, members.size
|
||||||
|
@ -139,7 +139,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_has_one_through_nonpreload_eagerloading
|
def test_has_one_through_nonpreload_eagerloading
|
||||||
members = assert_queries(1) do
|
members = assert_queries(1) do
|
||||||
Member.all.merge!(includes: :club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name").to_a #force fallback
|
Member.all.merge!(includes: :club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name").to_a # force fallback
|
||||||
end
|
end
|
||||||
assert_equal 1, members.size
|
assert_equal 1, members.size
|
||||||
assert_not_nil assert_no_queries { members[0].club }
|
assert_not_nil assert_no_queries { members[0].club }
|
||||||
|
@ -147,7 +147,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_has_one_through_nonpreload_eager_loading_through_polymorphic
|
def test_has_one_through_nonpreload_eager_loading_through_polymorphic
|
||||||
members = assert_queries(1) do
|
members = assert_queries(1) do
|
||||||
Member.all.merge!(includes: :sponsor_club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name").to_a #force fallback
|
Member.all.merge!(includes: :sponsor_club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name").to_a # force fallback
|
||||||
end
|
end
|
||||||
assert_equal 1, members.size
|
assert_equal 1, members.size
|
||||||
assert_not_nil assert_no_queries { members[0].sponsor_club }
|
assert_not_nil assert_no_queries { members[0].sponsor_club }
|
||||||
|
@ -156,7 +156,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
||||||
def test_has_one_through_nonpreload_eager_loading_through_polymorphic_with_more_than_one_through_record
|
def test_has_one_through_nonpreload_eager_loading_through_polymorphic_with_more_than_one_through_record
|
||||||
Sponsor.new(sponsor_club: clubs(:crazy_club), sponsorable: members(:groucho)).save!
|
Sponsor.new(sponsor_club: clubs(:crazy_club), sponsorable: members(:groucho)).save!
|
||||||
members = assert_queries(1) do
|
members = assert_queries(1) do
|
||||||
Member.all.merge!(includes: :sponsor_club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name DESC").to_a #force fallback
|
Member.all.merge!(includes: :sponsor_club, where: ["members.name = ?", "Groucho Marx"], order: "clubs.name DESC").to_a # force fallback
|
||||||
end
|
end
|
||||||
assert_equal 1, members.size
|
assert_equal 1, members.size
|
||||||
assert_not_nil assert_no_queries { members[0].sponsor_club }
|
assert_not_nil assert_no_queries { members[0].sponsor_club }
|
||||||
|
|
|
@ -467,7 +467,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
||||||
new_tag = Tag.new(name: "new")
|
new_tag = Tag.new(name: "new")
|
||||||
|
|
||||||
saved_post.tags << new_tag
|
saved_post.tags << new_tag
|
||||||
assert new_tag.persisted? #consistent with habtm!
|
assert new_tag.persisted? # consistent with habtm!
|
||||||
assert saved_post.persisted?
|
assert saved_post.persisted?
|
||||||
assert_includes saved_post.tags, new_tag
|
assert_includes saved_post.tags, new_tag
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,10 @@ module ActiveRecord
|
||||||
|
|
||||||
topic.attributes = dbtopic.attributes.except("id")
|
topic.attributes = dbtopic.attributes.except("id")
|
||||||
|
|
||||||
#duped has no timestamp values
|
# duped has no timestamp values
|
||||||
duped = dbtopic.dup
|
duped = dbtopic.dup
|
||||||
|
|
||||||
#clear topic timestamp values
|
# clear topic timestamp values
|
||||||
topic.send(:clear_timestamp_attributes)
|
topic.send(:clear_timestamp_attributes)
|
||||||
|
|
||||||
assert_equal topic.changes, duped.changes
|
assert_equal topic.changes, duped.changes
|
||||||
|
@ -100,7 +100,7 @@ module ActiveRecord
|
||||||
# temporary change to the topic object
|
# temporary change to the topic object
|
||||||
topic.updated_at -= 3.days
|
topic.updated_at -= 3.days
|
||||||
|
|
||||||
#dup should not preserve the timestamps if present
|
# dup should not preserve the timestamps if present
|
||||||
new_topic = topic.dup
|
new_topic = topic.dup
|
||||||
assert_nil new_topic.updated_at
|
assert_nil new_topic.updated_at
|
||||||
assert_nil new_topic.created_at
|
assert_nil new_topic.created_at
|
||||||
|
|
|
@ -565,7 +565,7 @@ class FinderTest < ActiveRecord::TestCase
|
||||||
assert_nil Topic.offset(4).second_to_last
|
assert_nil Topic.offset(4).second_to_last
|
||||||
assert_nil Topic.offset(5).second_to_last
|
assert_nil Topic.offset(5).second_to_last
|
||||||
|
|
||||||
#test with limit
|
# test with limit
|
||||||
assert_nil Topic.limit(1).second
|
assert_nil Topic.limit(1).second
|
||||||
assert_nil Topic.limit(1).second_to_last
|
assert_nil Topic.limit(1).second_to_last
|
||||||
end
|
end
|
||||||
|
|
|
@ -247,7 +247,7 @@ class FixturesTest < ActiveRecord::TestCase
|
||||||
def test_nonexistent_fixture_file
|
def test_nonexistent_fixture_file
|
||||||
nonexistent_fixture_path = FIXTURES_ROOT + "/imnothere"
|
nonexistent_fixture_path = FIXTURES_ROOT + "/imnothere"
|
||||||
|
|
||||||
#sanity check to make sure that this file never exists
|
# sanity check to make sure that this file never exists
|
||||||
assert Dir[nonexistent_fixture_path + "*"].empty?
|
assert Dir[nonexistent_fixture_path + "*"].empty?
|
||||||
|
|
||||||
assert_raise(Errno::ENOENT) do
|
assert_raise(Errno::ENOENT) do
|
||||||
|
|
|
@ -12,7 +12,6 @@ module ActiveRecord
|
||||||
@connection = ActiveRecord::Base.connection
|
@connection = ActiveRecord::Base.connection
|
||||||
end
|
end
|
||||||
|
|
||||||
#Cache v 1.1 tests
|
|
||||||
def test_statement_cache
|
def test_statement_cache
|
||||||
Book.create(name: "my book")
|
Book.create(name: "my book")
|
||||||
Book.create(name: "my other book")
|
Book.create(name: "my other book")
|
||||||
|
@ -51,8 +50,6 @@ module ActiveRecord
|
||||||
assert_equal("my other book", b.name)
|
assert_equal("my other book", b.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
#End
|
|
||||||
|
|
||||||
def test_statement_cache_with_simple_statement
|
def test_statement_cache_with_simple_statement
|
||||||
cache = ActiveRecord::StatementCache.create(Book.connection) do |params|
|
cache = ActiveRecord::StatementCache.create(Book.connection) do |params|
|
||||||
Book.where(name: "my book").where("author_id > 3")
|
Book.where(name: "my book").where("author_id > 3")
|
||||||
|
|
|
@ -10,10 +10,6 @@ require "action_controller/railtie"
|
||||||
require "action_view/railtie"
|
require "action_view/railtie"
|
||||||
require "sprockets/railtie"
|
require "sprockets/railtie"
|
||||||
require "active_storage/engine"
|
require "active_storage/engine"
|
||||||
#require "action_mailer/railtie"
|
|
||||||
#require "rails/test_unit/railtie"
|
|
||||||
#require "action_cable/engine"
|
|
||||||
|
|
||||||
|
|
||||||
Bundler.require(*Rails.groups)
|
Bundler.require(*Rails.groups)
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
@namespace = "namespace"
|
@namespace = "namespace"
|
||||||
|
|
||||||
@cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace, expires_in: 60)
|
@cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace, expires_in: 60)
|
||||||
#@cache.logger = Logger.new($stdout) # For test debugging
|
# @cache.logger = Logger.new($stdout) # For test debugging
|
||||||
|
|
||||||
# For LocalCacheBehavior tests
|
# For LocalCacheBehavior tests
|
||||||
@peek = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace)
|
@peek = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace)
|
||||||
|
|
|
@ -297,24 +297,24 @@ module DateAndTimeBehavior
|
||||||
|
|
||||||
def test_beginning_of_week
|
def test_beginning_of_week
|
||||||
assert_equal date_time_init(2005, 1, 31, 0, 0, 0), date_time_init(2005, 2, 4, 10, 10, 10).beginning_of_week
|
assert_equal date_time_init(2005, 1, 31, 0, 0, 0), date_time_init(2005, 2, 4, 10, 10, 10).beginning_of_week
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 28, 0, 0, 0).beginning_of_week #monday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 28, 0, 0, 0).beginning_of_week # monday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 29, 0, 0, 0).beginning_of_week #tuesday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 29, 0, 0, 0).beginning_of_week # tuesday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 30, 0, 0, 0).beginning_of_week #wednesday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 11, 30, 0, 0, 0).beginning_of_week # wednesday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 01, 0, 0, 0).beginning_of_week #thursday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 01, 0, 0, 0).beginning_of_week # thursday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 02, 0, 0, 0).beginning_of_week #friday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 02, 0, 0, 0).beginning_of_week # friday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 03, 0, 0, 0).beginning_of_week #saturday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 03, 0, 0, 0).beginning_of_week # saturday
|
||||||
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 04, 0, 0, 0).beginning_of_week #sunday
|
assert_equal date_time_init(2005, 11, 28, 0, 0, 0), date_time_init(2005, 12, 04, 0, 0, 0).beginning_of_week # sunday
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_end_of_week
|
def test_end_of_week
|
||||||
assert_equal date_time_init(2008, 1, 6, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 12, 31, 10, 10, 10).end_of_week
|
assert_equal date_time_init(2008, 1, 6, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 12, 31, 10, 10, 10).end_of_week
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 27, 0, 0, 0).end_of_week #monday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 27, 0, 0, 0).end_of_week # monday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 28, 0, 0, 0).end_of_week #tuesday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 28, 0, 0, 0).end_of_week # tuesday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 29, 0, 0, 0).end_of_week #wednesday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 29, 0, 0, 0).end_of_week # wednesday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 30, 0, 0, 0).end_of_week #thursday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 30, 0, 0, 0).end_of_week # thursday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 31, 0, 0, 0).end_of_week #friday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 8, 31, 0, 0, 0).end_of_week # friday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 9, 01, 0, 0, 0).end_of_week #saturday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 9, 01, 0, 0, 0).end_of_week # saturday
|
||||||
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 9, 02, 0, 0, 0).end_of_week #sunday
|
assert_equal date_time_init(2007, 9, 2, 23, 59, 59, Rational(999999999, 1000)), date_time_init(2007, 9, 02, 0, 0, 0).end_of_week # sunday
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_end_of_month
|
def test_end_of_month
|
||||||
|
|
|
@ -95,11 +95,11 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_beginning_of_week_in_calendar_reform
|
def test_beginning_of_week_in_calendar_reform
|
||||||
assert_equal Date.new(1582, 10, 1), Date.new(1582, 10, 15).beginning_of_week #friday
|
assert_equal Date.new(1582, 10, 1), Date.new(1582, 10, 15).beginning_of_week # friday
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_end_of_week_in_calendar_reform
|
def test_end_of_week_in_calendar_reform
|
||||||
assert_equal Date.new(1582, 10, 17), Date.new(1582, 10, 4).end_of_week #thursday
|
assert_equal Date.new(1582, 10, 17), Date.new(1582, 10, 4).end_of_week # thursday
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_end_of_year
|
def test_end_of_year
|
||||||
|
@ -144,7 +144,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
|
||||||
assert_equal Date.new(2012, 9, 28), Date.new(2005, 2, 28).advance(years: 7, months: 7)
|
assert_equal Date.new(2012, 9, 28), Date.new(2005, 2, 28).advance(years: 7, months: 7)
|
||||||
assert_equal Date.new(2013, 10, 3), Date.new(2005, 2, 28).advance(years: 7, months: 19, days: 5)
|
assert_equal Date.new(2013, 10, 3), Date.new(2005, 2, 28).advance(years: 7, months: 19, days: 5)
|
||||||
assert_equal Date.new(2013, 10, 17), Date.new(2005, 2, 28).advance(years: 7, months: 19, weeks: 2, days: 5)
|
assert_equal Date.new(2013, 10, 17), Date.new(2005, 2, 28).advance(years: 7, months: 19, weeks: 2, days: 5)
|
||||||
assert_equal Date.new(2005, 2, 28), Date.new(2004, 2, 29).advance(years: 1) #leap day plus one year
|
assert_equal Date.new(2005, 2, 28), Date.new(2004, 2, 29).advance(years: 1) # leap day plus one year
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_advance_does_first_years_and_then_days
|
def test_advance_does_first_years_and_then_days
|
||||||
|
|
|
@ -187,7 +187,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
|
||||||
assert_equal DateTime.civil(2013, 10, 3, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, days: 5)
|
assert_equal DateTime.civil(2013, 10, 3, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, days: 5)
|
||||||
assert_equal DateTime.civil(2013, 10, 17, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
assert_equal DateTime.civil(2013, 10, 17, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
||||||
assert_equal DateTime.civil(2001, 12, 27, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
assert_equal DateTime.civil(2001, 12, 27, 15, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
||||||
assert_equal DateTime.civil(2005, 2, 28, 15, 15, 10), DateTime.civil(2004, 2, 29, 15, 15, 10).advance(years: 1) #leap day plus one year
|
assert_equal DateTime.civil(2005, 2, 28, 15, 15, 10), DateTime.civil(2004, 2, 29, 15, 15, 10).advance(years: 1) # leap day plus one year
|
||||||
assert_equal DateTime.civil(2005, 2, 28, 20, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
assert_equal DateTime.civil(2005, 2, 28, 20, 15, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
||||||
assert_equal DateTime.civil(2005, 2, 28, 15, 22, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
assert_equal DateTime.civil(2005, 2, 28, 15, 22, 10), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
||||||
assert_equal DateTime.civil(2005, 2, 28, 15, 15, 19), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
assert_equal DateTime.civil(2005, 2, 28, 15, 15, 19), DateTime.civil(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
||||||
|
|
|
@ -302,7 +302,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
|
||||||
assert_equal "40 KB", 41100.to_s(:human_size, precision: 2)
|
assert_equal "40 KB", 41100.to_s(:human_size, precision: 2)
|
||||||
assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, precision: 2, strip_insignificant_zeros: false)
|
assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, precision: 2, strip_insignificant_zeros: false)
|
||||||
assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, significant: false)
|
assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, significant: false)
|
||||||
assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 0, significant: true) #ignores significant it precision is 0
|
assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 0, significant: true) # ignores significant it precision is 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_s__human_size_with_custom_delimiter_and_separator
|
def test_to_s__human_size_with_custom_delimiter_and_separator
|
||||||
|
@ -330,17 +330,17 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
|
||||||
assert_equal "489.0 Thousand", 489000.to_s(:human, precision: 4, strip_insignificant_zeros: false)
|
assert_equal "489.0 Thousand", 489000.to_s(:human, precision: 4, strip_insignificant_zeros: false)
|
||||||
assert_equal "1.2346 Million", 1234567.to_s(:human, precision: 4, significant: false)
|
assert_equal "1.2346 Million", 1234567.to_s(:human, precision: 4, significant: false)
|
||||||
assert_equal "1,2 Million", 1234567.to_s(:human, precision: 1, significant: false, separator: ",")
|
assert_equal "1,2 Million", 1234567.to_s(:human, precision: 1, significant: false, separator: ",")
|
||||||
assert_equal "1 Million", 1234567.to_s(:human, precision: 0, significant: true, separator: ",") #significant forced to false
|
assert_equal "1 Million", 1234567.to_s(:human, precision: 0, significant: true, separator: ",") # significant forced to false
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_to_human_with_custom_units
|
def test_number_to_human_with_custom_units
|
||||||
#Only integers
|
# Only integers
|
||||||
volume = { unit: "ml", thousand: "lt", million: "m3" }
|
volume = { unit: "ml", thousand: "lt", million: "m3" }
|
||||||
assert_equal "123 lt", 123456.to_s(:human, units: volume)
|
assert_equal "123 lt", 123456.to_s(:human, units: volume)
|
||||||
assert_equal "12 ml", 12.to_s(:human, units: volume)
|
assert_equal "12 ml", 12.to_s(:human, units: volume)
|
||||||
assert_equal "1.23 m3", 1234567.to_s(:human, units: volume)
|
assert_equal "1.23 m3", 1234567.to_s(:human, units: volume)
|
||||||
|
|
||||||
#Including fractionals
|
# Including fractionals
|
||||||
distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" }
|
distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" }
|
||||||
assert_equal "1.23 mm", 0.00123.to_s(:human, units: distance)
|
assert_equal "1.23 mm", 0.00123.to_s(:human, units: distance)
|
||||||
assert_equal "1.23 cm", 0.0123.to_s(:human, units: distance)
|
assert_equal "1.23 cm", 0.0123.to_s(:human, units: distance)
|
||||||
|
@ -353,14 +353,14 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
|
||||||
assert_equal "1.23 km", 1230.to_s(:human, units: distance)
|
assert_equal "1.23 km", 1230.to_s(:human, units: distance)
|
||||||
assert_equal "12.3 km", 12300.to_s(:human, units: distance)
|
assert_equal "12.3 km", 12300.to_s(:human, units: distance)
|
||||||
|
|
||||||
#The quantifiers don't need to be a continuous sequence
|
# The quantifiers don't need to be a continuous sequence
|
||||||
gangster = { hundred: "hundred bucks", million: "thousand quids" }
|
gangster = { hundred: "hundred bucks", million: "thousand quids" }
|
||||||
assert_equal "1 hundred bucks", 100.to_s(:human, units: gangster)
|
assert_equal "1 hundred bucks", 100.to_s(:human, units: gangster)
|
||||||
assert_equal "25 hundred bucks", 2500.to_s(:human, units: gangster)
|
assert_equal "25 hundred bucks", 2500.to_s(:human, units: gangster)
|
||||||
assert_equal "25 thousand quids", 25000000.to_s(:human, units: gangster)
|
assert_equal "25 thousand quids", 25000000.to_s(:human, units: gangster)
|
||||||
assert_equal "12300 thousand quids", 12345000000.to_s(:human, units: gangster)
|
assert_equal "12300 thousand quids", 12345000000.to_s(:human, units: gangster)
|
||||||
|
|
||||||
#Spaces are stripped from the resulting string
|
# Spaces are stripped from the resulting string
|
||||||
assert_equal "4", 4.to_s(:human, units: { unit: "", ten: "tens " })
|
assert_equal "4", 4.to_s(:human, units: { unit: "", ten: "tens " })
|
||||||
assert_equal "4.5 tens", 45.to_s(:human, units: { unit: "", ten: " tens " })
|
assert_equal "4.5 tens", 45.to_s(:human, units: { unit: "", ten: " tens " })
|
||||||
end
|
end
|
||||||
|
|
|
@ -451,7 +451,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
|
||||||
assert_equal Time.local(2013, 10, 3, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, days: 5)
|
assert_equal Time.local(2013, 10, 3, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, days: 5)
|
||||||
assert_equal Time.local(2013, 10, 17, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
assert_equal Time.local(2013, 10, 17, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
||||||
assert_equal Time.local(2001, 12, 27, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
assert_equal Time.local(2001, 12, 27, 15, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
||||||
assert_equal Time.local(2005, 2, 28, 15, 15, 10), Time.local(2004, 2, 29, 15, 15, 10).advance(years: 1) #leap day plus one year
|
assert_equal Time.local(2005, 2, 28, 15, 15, 10), Time.local(2004, 2, 29, 15, 15, 10).advance(years: 1) # leap day plus one year
|
||||||
assert_equal Time.local(2005, 2, 28, 20, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
assert_equal Time.local(2005, 2, 28, 20, 15, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
||||||
assert_equal Time.local(2005, 2, 28, 15, 22, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
assert_equal Time.local(2005, 2, 28, 15, 22, 10), Time.local(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
||||||
assert_equal Time.local(2005, 2, 28, 15, 15, 19), Time.local(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
assert_equal Time.local(2005, 2, 28, 15, 15, 19), Time.local(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
||||||
|
@ -473,7 +473,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
|
||||||
assert_equal Time.utc(2013, 10, 3, 15, 15, 10), Time.utc(2005, 2, 22, 15, 15, 10).advance(years: 7, months: 19, days: 11)
|
assert_equal Time.utc(2013, 10, 3, 15, 15, 10), Time.utc(2005, 2, 22, 15, 15, 10).advance(years: 7, months: 19, days: 11)
|
||||||
assert_equal Time.utc(2013, 10, 17, 15, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
assert_equal Time.utc(2013, 10, 17, 15, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(years: 7, months: 19, weeks: 2, days: 5)
|
||||||
assert_equal Time.utc(2001, 12, 27, 15, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
assert_equal Time.utc(2001, 12, 27, 15, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(years: -3, months: -2, days: -1)
|
||||||
assert_equal Time.utc(2005, 2, 28, 15, 15, 10), Time.utc(2004, 2, 29, 15, 15, 10).advance(years: 1) #leap day plus one year
|
assert_equal Time.utc(2005, 2, 28, 15, 15, 10), Time.utc(2004, 2, 29, 15, 15, 10).advance(years: 1) # leap day plus one year
|
||||||
assert_equal Time.utc(2005, 2, 28, 20, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
assert_equal Time.utc(2005, 2, 28, 20, 15, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(hours: 5)
|
||||||
assert_equal Time.utc(2005, 2, 28, 15, 22, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
assert_equal Time.utc(2005, 2, 28, 15, 22, 10), Time.utc(2005, 2, 28, 15, 15, 10).advance(minutes: 7)
|
||||||
assert_equal Time.utc(2005, 2, 28, 15, 15, 19), Time.utc(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
assert_equal Time.utc(2005, 2, 28, 15, 15, 19), Time.utc(2005, 2, 28, 15, 15, 10).advance(seconds: 9)
|
||||||
|
@ -495,7 +495,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
|
||||||
assert_equal Time.new(2013, 10, 3, 15, 15, 10, "-08:00"), Time.new(2005, 2, 22, 15, 15, 10, "-08:00").advance(years: 7, months: 19, days: 11)
|
assert_equal Time.new(2013, 10, 3, 15, 15, 10, "-08:00"), Time.new(2005, 2, 22, 15, 15, 10, "-08:00").advance(years: 7, months: 19, days: 11)
|
||||||
assert_equal Time.new(2013, 10, 17, 15, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(years: 7, months: 19, weeks: 2, days: 5)
|
assert_equal Time.new(2013, 10, 17, 15, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(years: 7, months: 19, weeks: 2, days: 5)
|
||||||
assert_equal Time.new(2001, 12, 27, 15, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(years: -3, months: -2, days: -1)
|
assert_equal Time.new(2001, 12, 27, 15, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(years: -3, months: -2, days: -1)
|
||||||
assert_equal Time.new(2005, 2, 28, 15, 15, 10, "-08:00"), Time.new(2004, 2, 29, 15, 15, 10, "-08:00").advance(years: 1) #leap day plus one year
|
assert_equal Time.new(2005, 2, 28, 15, 15, 10, "-08:00"), Time.new(2004, 2, 29, 15, 15, 10, "-08:00").advance(years: 1) # leap day plus one year
|
||||||
assert_equal Time.new(2005, 2, 28, 20, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(hours: 5)
|
assert_equal Time.new(2005, 2, 28, 20, 15, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(hours: 5)
|
||||||
assert_equal Time.new(2005, 2, 28, 15, 22, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(minutes: 7)
|
assert_equal Time.new(2005, 2, 28, 15, 22, 10, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(minutes: 7)
|
||||||
assert_equal Time.new(2005, 2, 28, 15, 15, 19, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(seconds: 9)
|
assert_equal Time.new(2005, 2, 28, 15, 15, 19, "-08:00"), Time.new(2005, 2, 28, 15, 15, 10, "-08:00").advance(seconds: 9)
|
||||||
|
|
|
@ -84,7 +84,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_formatted_offset
|
def test_formatted_offset
|
||||||
assert_equal "-05:00", @twz.formatted_offset
|
assert_equal "-05:00", @twz.formatted_offset
|
||||||
assert_equal "-04:00", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).formatted_offset #dst
|
assert_equal "-04:00", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).formatted_offset # dst
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dst?
|
def test_dst?
|
||||||
|
@ -94,7 +94,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_zone
|
def test_zone
|
||||||
assert_equal "EST", @twz.zone
|
assert_equal "EST", @twz.zone
|
||||||
assert_equal "EDT", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone #dst
|
assert_equal "EDT", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone # dst
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nsec
|
def test_nsec
|
||||||
|
|
|
@ -77,10 +77,10 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_with_i18n_precision
|
def test_number_with_i18n_precision
|
||||||
#Delimiter was set to ""
|
# Delimiter was set to ""
|
||||||
assert_equal("10000", number_to_rounded(10000, locale: "ts"))
|
assert_equal("10000", number_to_rounded(10000, locale: "ts"))
|
||||||
|
|
||||||
#Precision inherited and significant was set
|
# Precision inherited and significant was set
|
||||||
assert_equal("1.00", number_to_rounded(1.0, locale: "ts"))
|
assert_equal("1.00", number_to_rounded(1.0, locale: "ts"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_with_i18n_delimiter
|
def test_number_with_i18n_delimiter
|
||||||
#Delimiter "," and separator "."
|
# Delimiter "," and separator "."
|
||||||
assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "ts"))
|
assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "ts"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_to_i18n_human_size
|
def test_number_to_i18n_human_size
|
||||||
#b for bytes and k for kbytes
|
# b for bytes and k for kbytes
|
||||||
assert_equal("2 k", number_to_human_size(2048, locale: "ts"))
|
assert_equal("2 k", number_to_human_size(2048, locale: "ts"))
|
||||||
assert_equal("42 b", number_to_human_size(42, locale: "ts"))
|
assert_equal("42 b", number_to_human_size(42, locale: "ts"))
|
||||||
end
|
end
|
||||||
|
@ -125,11 +125,11 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_to_human_with_default_translation_scope
|
def test_number_to_human_with_default_translation_scope
|
||||||
#Using t for thousand
|
# Using t for thousand
|
||||||
assert_equal "2 t", number_to_human(2000, locale: "ts")
|
assert_equal "2 t", number_to_human(2000, locale: "ts")
|
||||||
#Significant was set to true with precision 2, using b for billion
|
# Significant was set to true with precision 2, using b for billion
|
||||||
assert_equal "1.2 b", number_to_human(1234567890, locale: "ts")
|
assert_equal "1.2 b", number_to_human(1234567890, locale: "ts")
|
||||||
#Using pluralization (Ten/Tens and Tenth/Tenths)
|
# Using pluralization (Ten/Tens and Tenth/Tenths)
|
||||||
assert_equal "1 Tenth", number_to_human(0.1, locale: "ts")
|
assert_equal "1 Tenth", number_to_human(0.1, locale: "ts")
|
||||||
assert_equal "1.3 Tenth", number_to_human(0.134, locale: "ts")
|
assert_equal "1.3 Tenth", number_to_human(0.134, locale: "ts")
|
||||||
assert_equal "2 Tenths", number_to_human(0.2, locale: "ts")
|
assert_equal "2 Tenths", number_to_human(0.2, locale: "ts")
|
||||||
|
@ -144,7 +144,7 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_number_to_human_with_custom_translation_scope
|
def test_number_to_human_with_custom_translation_scope
|
||||||
#Significant was set to true with precision 2, with custom translated units
|
# Significant was set to true with precision 2, with custom translated units
|
||||||
assert_equal "4.3 cm", number_to_human(0.0432, locale: "ts", units: :custom_units_for_number_to_human)
|
assert_equal "4.3 cm", number_to_human(0.0432, locale: "ts", units: :custom_units_for_number_to_human)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -260,7 +260,7 @@ module ActiveSupport
|
||||||
assert_equal "40 KB", number_helper.number_to_human_size(41100, precision: 2)
|
assert_equal "40 KB", number_helper.number_to_human_size(41100, precision: 2)
|
||||||
assert_equal "1.0 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2, strip_insignificant_zeros: false)
|
assert_equal "1.0 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2, strip_insignificant_zeros: false)
|
||||||
assert_equal "1.012 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, significant: false)
|
assert_equal "1.012 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, significant: false)
|
||||||
assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 0, significant: true) #ignores significant it precision is 0
|
assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 0, significant: true) # ignores significant it precision is 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ module ActiveSupport
|
||||||
assert_equal "489.0 Thousand", number_helper.number_to_human(489000, precision: 4, strip_insignificant_zeros: false)
|
assert_equal "489.0 Thousand", number_helper.number_to_human(489000, precision: 4, strip_insignificant_zeros: false)
|
||||||
assert_equal "1.2346 Million", number_helper.number_to_human(1234567, precision: 4, significant: false)
|
assert_equal "1.2346 Million", number_helper.number_to_human(1234567, precision: 4, significant: false)
|
||||||
assert_equal "1,2 Million", number_helper.number_to_human(1234567, precision: 1, significant: false, separator: ",")
|
assert_equal "1,2 Million", number_helper.number_to_human(1234567, precision: 1, significant: false, separator: ",")
|
||||||
assert_equal "1 Million", number_helper.number_to_human(1234567, precision: 0, significant: true, separator: ",") #significant forced to false
|
assert_equal "1 Million", number_helper.number_to_human(1234567, precision: 0, significant: true, separator: ",") # significant forced to false
|
||||||
assert_equal "1 Million", number_helper.number_to_human(999999)
|
assert_equal "1 Million", number_helper.number_to_human(999999)
|
||||||
assert_equal "1 Billion", number_helper.number_to_human(999999999)
|
assert_equal "1 Billion", number_helper.number_to_human(999999999)
|
||||||
end
|
end
|
||||||
|
@ -300,13 +300,13 @@ module ActiveSupport
|
||||||
|
|
||||||
def test_number_to_human_with_custom_units
|
def test_number_to_human_with_custom_units
|
||||||
[@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper|
|
[@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper|
|
||||||
#Only integers
|
# Only integers
|
||||||
volume = { unit: "ml", thousand: "lt", million: "m3" }
|
volume = { unit: "ml", thousand: "lt", million: "m3" }
|
||||||
assert_equal "123 lt", number_helper.number_to_human(123456, units: volume)
|
assert_equal "123 lt", number_helper.number_to_human(123456, units: volume)
|
||||||
assert_equal "12 ml", number_helper.number_to_human(12, units: volume)
|
assert_equal "12 ml", number_helper.number_to_human(12, units: volume)
|
||||||
assert_equal "1.23 m3", number_helper.number_to_human(1234567, units: volume)
|
assert_equal "1.23 m3", number_helper.number_to_human(1234567, units: volume)
|
||||||
|
|
||||||
#Including fractionals
|
# Including fractionals
|
||||||
distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" }
|
distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" }
|
||||||
assert_equal "1.23 mm", number_helper.number_to_human(0.00123, units: distance)
|
assert_equal "1.23 mm", number_helper.number_to_human(0.00123, units: distance)
|
||||||
assert_equal "1.23 cm", number_helper.number_to_human(0.0123, units: distance)
|
assert_equal "1.23 cm", number_helper.number_to_human(0.0123, units: distance)
|
||||||
|
@ -319,7 +319,7 @@ module ActiveSupport
|
||||||
assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance)
|
assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance)
|
||||||
assert_equal "12.3 km", number_helper.number_to_human(12300, units: distance)
|
assert_equal "12.3 km", number_helper.number_to_human(12300, units: distance)
|
||||||
|
|
||||||
#The quantifiers don't need to be a continuous sequence
|
# The quantifiers don't need to be a continuous sequence
|
||||||
gangster = { hundred: "hundred bucks", million: "thousand quids" }
|
gangster = { hundred: "hundred bucks", million: "thousand quids" }
|
||||||
assert_equal "1 hundred bucks", number_helper.number_to_human(100, units: gangster)
|
assert_equal "1 hundred bucks", number_helper.number_to_human(100, units: gangster)
|
||||||
assert_equal "25 hundred bucks", number_helper.number_to_human(2500, units: gangster)
|
assert_equal "25 hundred bucks", number_helper.number_to_human(2500, units: gangster)
|
||||||
|
@ -329,11 +329,11 @@ module ActiveSupport
|
||||||
assert_equal "25 thousand quids", number_helper.number_to_human(25000000, units: gangster)
|
assert_equal "25 thousand quids", number_helper.number_to_human(25000000, units: gangster)
|
||||||
assert_equal "12300 thousand quids", number_helper.number_to_human(12345000000, units: gangster)
|
assert_equal "12300 thousand quids", number_helper.number_to_human(12345000000, units: gangster)
|
||||||
|
|
||||||
#Spaces are stripped from the resulting string
|
# Spaces are stripped from the resulting string
|
||||||
assert_equal "4", number_helper.number_to_human(4, units: { unit: "", ten: "tens " })
|
assert_equal "4", number_helper.number_to_human(4, units: { unit: "", ten: "tens " })
|
||||||
assert_equal "4.5 tens", number_helper.number_to_human(45, units: { unit: "", ten: " tens " })
|
assert_equal "4.5 tens", number_helper.number_to_human(45, units: { unit: "", ten: " tens " })
|
||||||
|
|
||||||
#Uses only the provided units and does not try to use larger ones
|
# Uses only the provided units and does not try to use larger ones
|
||||||
assert_equal "1000 kilometers", number_helper.number_to_human(1_000_000, units: { unit: "meter", thousand: "kilometers" })
|
assert_equal "1000 kilometers", number_helper.number_to_human(1_000_000, units: { unit: "meter", thousand: "kilometers" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,7 +98,7 @@ class TimeTravelTest < ActiveSupport::TestCase
|
||||||
travel_to outer_expected_time do
|
travel_to outer_expected_time do
|
||||||
e = assert_raises(RuntimeError) do
|
e = assert_raises(RuntimeError) do
|
||||||
travel_to(inner_expected_time) do
|
travel_to(inner_expected_time) do
|
||||||
#noop
|
# noop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_match(/Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing\./, e.message)
|
assert_match(/Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing\./, e.message)
|
||||||
|
|
|
@ -6,7 +6,7 @@ XMLMiniEngineTest.run_with_gem("libxml") do
|
||||||
class LibxmlEngineTest < XMLMiniEngineTest
|
class LibxmlEngineTest < XMLMiniEngineTest
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do
|
LibXML::XML::Error.set_handler(&lambda { |error| }) # silence libxml, exceptions will do
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -203,7 +203,7 @@ module ApplicationTests
|
||||||
rails "environment", "db:drop", "db:structure:load"
|
rails "environment", "db:drop", "db:structure:load"
|
||||||
assert_match expected_database, ActiveRecord::Base.connection_config[:database]
|
assert_match expected_database, ActiveRecord::Base.connection_config[:database]
|
||||||
require "#{app_path}/app/models/book"
|
require "#{app_path}/app/models/book"
|
||||||
#if structure is not loaded correctly, exception would be raised
|
# if structure is not loaded correctly, exception would be raised
|
||||||
assert_equal 0, Book.count
|
assert_equal 0, Book.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -298,7 +298,7 @@ module ApplicationTests
|
||||||
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
||||||
ActiveRecord::Base.establish_connection :test
|
ActiveRecord::Base.establish_connection :test
|
||||||
require "#{app_path}/app/models/book"
|
require "#{app_path}/app/models/book"
|
||||||
#if structure is not loaded correctly, exception would be raised
|
# if structure is not loaded correctly, exception would be raised
|
||||||
assert_equal 0, Book.count
|
assert_equal 0, Book.count
|
||||||
assert_match ActiveRecord::Base.configurations["test"]["database"],
|
assert_match ActiveRecord::Base.configurations["test"]["database"],
|
||||||
ActiveRecord::Base.connection_config[:database]
|
ActiveRecord::Base.connection_config[:database]
|
||||||
|
|
Loading…
Reference in New Issue