From 0303c2325fab253adf5e4a0b738cb469c048f008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Wed, 4 Jul 2012 14:57:31 +0200 Subject: Add the options method to action_controller testcase. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: François de Metz --- actionpack/lib/action_controller/test_case.rb | 9 +++++++-- actionpack/test/controller/test_case_test.rb | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a1f29ea1bc..555f4de3ac 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -430,8 +430,13 @@ module ActionController end # Executes a request simulating HEAD HTTP method and set/volley the response - def head(action, parameters = nil, session = nil, flash = nil) - process(action, "HEAD", parameters, session, flash) + def head(action, *args) + process(action, "HEAD", *args) + end + + # Executes a request simulating OPTIONS HTTP method and set/volley the response + def options(action, *args) + process(action, "OPTIONS", *args) end def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 49137946fe..f868451678 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -197,6 +197,11 @@ XML assert_raise(NoMethodError) { head :test_params, "document body", :id => 10 } end + def test_options + options :test_params + assert_equal 200, @response.status + end + def test_process_without_flash process :set_flash assert_equal '><', flash['test'] -- cgit v1.2.3 From 2f6004de6e692da81237a4d978b273acfbc9f396 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Wed, 4 Jul 2012 17:26:19 +0300 Subject: Add few information on the field types --- railties/lib/rails/generators/rails/model/USAGE | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index 67f76aad01..c46c86076e 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -19,6 +19,55 @@ Description: then the generator will create a module with a table_name_prefix method to prefix the model's table name with the module name (e.g. admin_account) +Available field types: + + Just after the field name you can specify a type like text or boolean. + It will generate the column with the associated SQL type. For instance: + + `rails generate model post title:string body:text` + + will generate a title column with a varchar type and a body column with a text + type. You can use the following types: + + integer + primary_key + decimal + float + boolean + binary + string + text + date + time + datetime + timestamp + + You can also consider `references` as a kind of type. For instance, if you run: + + `rails generate model photo title:string album:references` + + It will generate an album_id column. You should generate this kind of fields when + you will use a `belongs_to` association for instance. `references` also support + the polymorphism, you could enable the polymorphism like this: + + `rails generate model product supplier:references{polymorphic}` + + You can also specify some options just after the field type. You can use the + following options: + + limit Set the maximum size of the field giving a number between curly braces + default Set a default value for the field + precision Defines the precision for the decimal fields + scale Defines the scale for the decimal fields + uniq Defines the field values as unique + index Will add an index on the field + + Examples: + + `rails generate model user pseudo:string{30}` + `rails generate model user pseudo:string:uniq` + + Examples: `rails generate model account` -- cgit v1.2.3 From b5bb35355d68eab0343637980a231c8a4eb6093c Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Wed, 4 Jul 2012 22:39:16 -0500 Subject: fix quoting for ActiveSupport::Duration instances This patch fixes quoting for ActiveSupport::Duration instances: # before >> ActiveRecord::Base.connection.quote 30.minutes => "'--- 1800\n...\n'" # after >> ActiveRecord::Base.connection.quote 30.minutes => "1800" Also, adds a test for type casting ActiveSupport::Duration instances. Related to #1119. --- .../lib/active_record/connection_adapters/abstract/quoting.rb | 2 +- activerecord/test/cases/column_test.rb | 6 ++++++ activerecord/test/cases/quoting_test.rb | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 6f9f0399db..60a9eee7c7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -31,7 +31,7 @@ module ActiveRecord # BigDecimals need to be put in a non-normalized form and quoted. when nil then "NULL" when BigDecimal then value.to_s('F') - when Numeric then value.to_s + when Numeric, ActiveSupport::Duration then value.to_s when Date, Time then "'#{quoted_date(value)}'" when Symbol then "'#{quote_string(value.to_s)}'" when Class then "'#{value.to_s}'" diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb index 4111a5f808..a7b63d15c9 100644 --- a/activerecord/test/cases/column_test.rb +++ b/activerecord/test/cases/column_test.rb @@ -76,6 +76,12 @@ module ActiveRecord date_string = Time.now.utc.strftime("%F") assert_equal date_string, column.type_cast(date_string).strftime("%F") end + + def test_type_cast_duration_to_integer + column = Column.new("field", nil, "integer") + assert_equal 1800, column.type_cast(30.minutes) + assert_equal 7200, column.type_cast(2.hours) + end end end end diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 80ee74e41e..3dd11ae89d 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -216,6 +216,14 @@ module ActiveRecord def test_string_with_crazy_column assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo)) end + + def test_quote_duration + assert_equal "1800", @quoter.quote(30.minutes) + end + + def test_quote_duration_int_column + assert_equal "7200", @quoter.quote(2.hours, FakeColumn.new(:integer)) + end end end end -- cgit v1.2.3 From 5be3d89f4e2ecd78d631a33f2ebbf4a8cd017096 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Wed, 4 Jul 2012 23:47:41 -0500 Subject: CSV fixtures aren't supported by default anymore, update generated test_helper.rb to reflect that --- railties/lib/rails/generators/rails/app/templates/test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index 0090293200..9afda2d0df 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -6,7 +6,7 @@ class ActiveSupport::TestCase <% unless options[:skip_active_record] -%> ActiveRecord::Migration.check_pending! - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting -- cgit v1.2.3 From 9208879d6e3824dda5cf4cdf0d616e6ed5d3240e Mon Sep 17 00:00:00 2001 From: Mark Dodwell Date: Wed, 4 Jul 2012 22:34:31 -0700 Subject: Use ArgumentError vs. RuntimeError, which is more precise. --- actionmailer/lib/action_mailer/collector.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index 17b22aea2a..b8d1db9558 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -15,7 +15,7 @@ module ActionMailer #:nodoc: def any(*args, &block) options = args.extract_options! - raise "You have to supply at least one format" if args.empty? + raise ArgumentError, "You have to supply at least one format" if args.empty? args.each { |type| send(type, options.dup, &block) } end alias :all :any -- cgit v1.2.3 From 294219226175f8d17fb0348ceaba51caa5936ec3 Mon Sep 17 00:00:00 2001 From: Vitor Balocco Date: Thu, 5 Jul 2012 18:59:42 +0300 Subject: Add documentation for inheritance_column method --- activerecord/lib/active_record/model.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/model.rb b/activerecord/lib/active_record/model.rb index 7b3d926d91..0015e3a567 100644 --- a/activerecord/lib/active_record/model.rb +++ b/activerecord/lib/active_record/model.rb @@ -103,7 +103,9 @@ module ActiveRecord def abstract_class? false end - + + # Defines the name of the table column which will store the class name on single-table + # inheritance situations. def inheritance_column 'type' end -- cgit v1.2.3