Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6051

Show
Ignore:
Timestamp:
01/28/07 01:31:31 (2 years ago)
Author:
rick
Message:

Don't create instance writer methods for class attributes. Closes #7401 [Rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r6031 r6051  
    11*SVN* 
     2 
     3* Don't create instance writer methods for class attributes.  Closes #7401 [Rick] 
    24 
    35* Docs: validations examples.  #7343 [zackchandler] 
  • trunk/activerecord/lib/active_record/base.rb

    r6018 r6051  
    266266    # Accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then passed 
    267267    # on to any new database connections made and which can be retrieved on both a class and instance level by calling +logger+. 
    268     cattr_accessor :logger 
     268    cattr_accessor :logger, :instance_writer => false 
    269269     
    270270    include Reloadable::Deprecated 
     
    292292    @@subclasses = {} 
    293293 
    294     cattr_accessor :configurations 
     294    cattr_accessor :configurations, :instance_writer => false 
    295295    @@configurations = {} 
    296296 
     
    299299    # the primary column. If the latter is specified, the Product class will look for "product_id" instead of "id". Remember 
    300300    # that this is a global setting for all Active Records. 
    301     cattr_accessor :primary_key_prefix_type 
     301    cattr_accessor :primary_key_prefix_type, :instance_writer => false 
    302302    @@primary_key_prefix_type = nil 
    303303 
     
    305305    # table names will be named like "basecamp_projects", "basecamp_people", etc. This is a convenient way of creating a namespace 
    306306    # for tables in a shared database. By default, the prefix is the empty string. 
    307     cattr_accessor :table_name_prefix 
     307    cattr_accessor :table_name_prefix, :instance_writer => false 
    308308    @@table_name_prefix = "" 
    309309 
    310310    # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", 
    311311    # "people_basecamp"). By default, the suffix is the empty string. 
    312     cattr_accessor :table_name_suffix 
     312    cattr_accessor :table_name_suffix, :instance_writer => false 
    313313    @@table_name_suffix = "" 
    314314 
     
    316316    # If true, the default table name for a +Product+ class will be +products+. If false, it would just be +product+. 
    317317    # See table_name for the full rules on table/class naming. This is true, by default. 
    318     cattr_accessor :pluralize_table_names 
     318    cattr_accessor :pluralize_table_names, :instance_writer => false 
    319319    @@pluralize_table_names = true 
    320320 
     
    322322    # make it much easier to overview things during debugging (when used through a reader like +tail+ and on a black background), but 
    323323    # may complicate matters if you use software like syslog. This is true, by default. 
    324     cattr_accessor :colorize_logging 
     324    cattr_accessor :colorize_logging, :instance_writer => false 
    325325    @@colorize_logging = true 
    326326 
    327327    # Determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. 
    328328    # This is set to :local by default. 
    329     cattr_accessor :default_timezone 
     329    cattr_accessor :default_timezone, :instance_writer => false 
    330330    @@default_timezone = :local 
    331331 
    332332    # Determines whether or not to use a connection for each thread, or a single shared connection for all threads. 
    333333    # Defaults to false. Set to true if you're writing a threaded application. 
    334     cattr_accessor :allow_concurrency 
     334    cattr_accessor :allow_concurrency, :instance_writer => false 
    335335    @@allow_concurrency = false 
    336336 
     
    339339    # attributes by name. You might want to set this to false in development 
    340340    # mode, because the methods would be regenerated on each request. 
    341     cattr_accessor :generate_read_methods 
     341    cattr_accessor :generate_read_methods, :instance_writer => false 
    342342    @@generate_read_methods = true 
    343343     
     
    348348    # supports migrations.  Use :ruby if you want to have different database 
    349349    # adapters for, e.g., your development and test environments. 
    350     cattr_accessor :schema_format  
     350    cattr_accessor :schema_format , :instance_writer => false 
    351351    @@schema_format = :ruby 
    352352 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb

    r5955 r6051  
    1212    # Check for activity after at least +verification_timeout+ seconds. 
    1313    # Defaults to 0 (always check.) 
    14     cattr_accessor :verification_timeout 
     14    cattr_accessor :verification_timeout, :instance_writer => false 
    1515    @@verification_timeout = 0 
    1616 
  • trunk/activerecord/lib/active_record/locking/optimistic.rb

    r5007 r6051  
    2727        base.extend ClassMethods 
    2828 
    29         base.cattr_accessor :lock_optimistically 
     29        base.cattr_accessor :lock_optimistically, :instance_writer => false 
    3030        base.lock_optimistically = true 
    3131 
  • trunk/activerecord/lib/active_record/timestamp.rb

    r4706 r6051  
    2424      base.alias_method_chain :update, :timestamps 
    2525 
    26       base.cattr_accessor :record_timestamps 
     26      base.cattr_accessor :record_timestamps, :instance_writer => false 
    2727      base.record_timestamps = true 
    2828    end 
  • trunk/activerecord/test/base_test.rb

    r5958 r6051  
    749749    assert_equal 1, firm.rating 
    750750  end 
     751   
     752  def test_mass_assignment_protection_against_class_attribute_writers 
     753    [:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :colorize_logging, 
     754      :default_timezone, :allow_concurrency, :generate_read_methods, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method| 
     755      assert  Task.respond_to?(method) 
     756      assert  Task.respond_to?("#{method}=") 
     757      assert  Task.new.respond_to?(method) 
     758      assert !Task.new.respond_to?("#{method}=") 
     759    end 
     760  end 
    751761 
    752762  def test_customized_primary_key_remains_protected