Rails 0.8.5: Better fixtures, shared generators, sendmail for AM, lots of fixes!

Despite the best intentions with release 0.8.0, I still managed to drag
this release on for so long that a total of 76 changes made its way in.
But it’s all good. This release features yet another incredibly strong
showing from the community with some 22 contributors seeing their code
in the release. Special notice must go to Jeremy Kemper aka bitsweat
that has contributed a third of the changes in this release! And super
high quality patches too. Thanks, man.

On top of countless fixes and minor tweaks, we have a much improved new
approach to instantiating fixtures (with instant availability as
instance variables) and along the same lines a new way to reference
helpers. This heralds the way for more good things to come where
dependencies, whether it’s test cases on fixtures or controllers on
helpers, becomes part of the Rails domain language.

That’s a preview for how Rails will function after Needle has been
integrated, which will hopefully happen from release 0.9 thanks to the
incredible work of Jamis Buck and many good thoughts on the subject by
Dave Thomas and Jim Weirich. Rails will blaze the trail of transparent
depency injection with dynamic constants. Exciting stuff!

Get it all from http://www.rubyonrails.org, talk it up on #rubyonrails
(FreeNet).

Or even easier, just do “gem install rails” (or “gem update” if you’re
already running on Gem Rails) – you’ll automatically install all the
newest versions of the required dependencies.

Upgrading from 0.8.0 (refering to gems version):

  1. Create a new empty Rails project using “rails
    /some/path/empty_project”
  2. Copy over the new generators from script/ (hopefully for the last
    time)
  3. Copy over test/test_helper.rb (needed for the new fixture style)

Commercial announcement: If you’re looking for a place to host your
Rails project or just to play around with it online, we now have an
official hosting partner in TextDrive. I’m on board to ensure that the
Rails experience is top notch and in return 50% of the gross profits
are going to help further Rails. Read more on:

Rails 0.8.5: Shared generators, new_crud, breakpoints, fixes

···

================================================================

  • Made dev-util available to all tests, so you can insert breakpoints
    in any test case to get an IRB prompt at that point [bitsweat]:

    def test_complex_stuff
    @david.projects << @new_project
    breakpoint "Let’s have a closer look at @david"
    end

    You need to install dev-utils yourself for this to work (“gem install
    dev-util”).

  • Added shared generator behavior so future upgrades should be possible
    without manually copying over files [bitsweat]

  • Added the new helper style to both controller and helper templates
    [bitsweat]

  • Added new_crud generator for creating a model and controller at the
    same time with explicit scaffolding [bitsweat]

  • Added configuration of Test::Unit::TestCase.fixture_path to
    test_helper to concide with the new AR fixtures style

  • Fixed that new_model was generating singular table/fixture names

  • Upgraded to Action Mailer 0.4.0

  • Upgraded to Action Pack 0.9.5

  • Upgraded to Active Record 1.1.0

Action Mailer 0.4.0: Sendmail, better testing, more configurations

  • Consolidated the server configuration options into
    Base#server_settings= and expanded that with controls for
    authentication and more [Marten] NOTE: This is an API change that could
    potentially break your application if you used the old application
    form. Please do change!

  • Added Base#deliveries as an accessor for an array of emails sent out
    through that ActionMailer class when using the :test delivery option.
    [bitsweat]

  • Added Base#perform_deliveries= which can be set to false to turn off
    the actual delivery of the email through smtp or sendmail. This is
    especially useful for functional testing that shouldn’t send off real
    emails, but still trigger delivery_* methods.

  • Added option to specify delivery method with Base#delivery_method=.
    Default is :smtp and :sendmail is currently the only other option.
    Sendmail is assumed to be present at “/usr/sbin/sendmail” if that
    option is used. [Kent Sibilev]

  • Dropped “include TMail” as it added to much baggage into the default
    namespace (like Version) [Chad Fowler]

Active Record 1.0.0: Better fixtures, rich habtm associations,
equality, fixes

======

  • Added automatic fixture setup and instance variable availability.
    Fixtures can also be automatically instantiated in instance variables
    relating to their names using the following style:

    class FixturesTest < Test::Unit::TestCase
    fixtures :developers # you can add more with comma separation

     def test_developers
       assert_equal 3, @developers.size # the container for all the  
    

fixtures is automatically set
assert_kind_of Developer, @david # works like
@developers[“david”].find
assert_equal “David Heinemeier Hansson”, @david.name
end
end

  • Added HasAndBelongsToManyAssociation#push_with_attributes(object,
    join_attributes) that can create associations in the join table with
    additional attributes. This is really useful when you have information
    that’s only relevant to the join itself, such as a “added_on” column
    for an association between post and category. The added attributes will
    automatically be injected into objects retrieved through the
    association similar to the piggy-back approach:

    post.categories.push_with_attributes(category, :added_on =>
    Date.today)
    post.categories.first.added_on # => Date.today

    NOTE: The categories table doesn’t have a added_on column, it’s the
    categories_post join table that does!

  • Added Base#hash and Base#eql? which means that all of the equality
    using features of array and other containers now works:

    [ Person.find(1), Person.find(2), Person.find(3) ] &
    [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]

  • Fixed that :exclusively_dependent and :dependent can’t be activated
    at the same time on has_many associations [bitsweat]

  • Fixed that database passwords couldn’t be all numeric [bitsweat]

  • Fixed that calling id would create the instance variable for
    new_records preventing them from being saved correctly [bitsweat]

  • Added sanitization feature to HasManyAssociation#find_all so it works
    just like Base.find_all [Sam Stephenson/bitsweat]

  • Added that you can pass overlapping ids to find without getting
    duplicated records back [bitsweat]

  • Added that Base.benchmark returns the result of the block [bitsweat]

  • Fixed problem with unit tests on Windows with SQLite [paterno]

  • Fixed that quotes would break regular non-yaml fixtures [Dmitry
    Sabanin/daft]

  • Fixed fixtures on windows with line endings cause problems under unix
    / mac [Tobias Luetke]

  • Added HasAndBelongsToManyAssociation#find(id) that’ll search inside
    the collection and find the object or record with that id

  • Added :conditions option to has_and_belongs_to_many that works just
    like the one on all the other associations

  • Added AssociationCollection#clear to remove all associations from
    has_many and has_and_belongs_to_many associations without destroying
    the records [geech]

  • Added type-checking and remove in 1-instead-of-N sql statements to
    AssociationCollection#delete [geech]

  • Added a return of self to AssociationCollection#<< so appending can
    be chained, like project << Milestone.create << Milestone.create
    [geech]

  • Added :uniq as an option to has_and_belongs_to_many which will
    automatically ensure that AssociateCollection#uniq is called before
    pulling records out of the association. This is especially useful for
    three-way (and above) has_and_belongs_to_many associations.

  • Added AssociateCollection#uniq which is especially useful for
    has_and_belongs_to_many associations that can include duplicates,
    which is common on associations that also use metadata. Usage:
    post.categories.uniq

  • Fixed respond_to? to use a subclass specific hash instead of an
    Active Record-wide one

  • Fixed has_and_belongs_to_many to treat associations between classes
    in modules properly [Florian Weber]

  • Added a NoMethod exception to be raised when query and writer methods
    are called for attributes that doesn’t exist [geech]

  • Added a more robust version of Fixtures that throws meaningful errors
    when on formatting issues [geech]

  • Added Base#transaction as a compliment to Base.transaction for
    prettier use in instance methods [geech]

  • Improved the speed of respond_to? by placing the dynamic methods
    lookup table in a hash [geech]

  • Added that any additional fields added to the join table in a
    has_and_belongs_to_many association will be placed as attributes when
    pulling records out through has_and_belongs_to_many associations. This
    is helpful when have information about the association itself that you
    want available on retrival.

  • Added better loading exception catching and RubyGems retries to the
    database adapters [alexeyv]

  • Fixed bug with per-model transactions [daniel]

  • Fixed Base#transaction so that it returns the result of the last
    expression in the transaction block [alexeyv]

  • Added Fixture#find to find the record corresponding to the fixture
    id. The record class name is guessed by using Inflector#classify (also
    new) on the fixture directory name.

    Before: Document.find(@documents[“first”][“id”])
    After : @documents[“first”].find

  • Fixed that the table name part of column names (“TABLE.COLUMN”)
    wasn’t removed properly [Andreas Schwarz]

  • Fixed a bug with Base#size when a finder_sql was used that didn’t
    capitalize SELECT and FROM [geech]

  • Fixed quoting problems on SQLite by adding quote_string to the
    AbstractAdapter that can be overwritten by the concrete adapters for a
    call to the dbm. [Andreas Schwarz]

  • Removed RubyGems backup strategy for requiring SQLite-adapter – if
    people want to use gems, they’re already doing it with AR.

Action Pack 0.9.5: New helper style, fix for unchecked checkboxes, fixes

  • Added a new way to include helpers that doesn’t require the include
    hack and can go without the explicit require. [bitsweat]

    Before:

    module WeblogHelper
    def self.append_features(controller) #:nodoc:
    controller.ancestors.include?(ActionController::Base) ?
    controller.add_template_helper(self) : super
    end
    end

    require 'weblog_helper’
    class WeblogController < ActionController::Base
    include WeblogHelper
    end

    After:

    module WeblogHelper
    end

    class WeblogController < ActionController::Base
    helper :weblog
    end

  • Added helper_method to designate that a given private or protected
    method you should available as a helper in the view. [bitsweat]

  • Added a hidden field to checkboxes generated with
    FormHelper#check_box that will make sure that the unchecked value
    (usually 0) is sent even if the checkbox is not checked. This relieves
    the controller from doing custom checking if the the checkbox wasn’t
    checked. BEWARE: This might conflict with your run-on-the-mill
    work-around code. [Tobias Luetke]

  • Fixed assert_rendered_file so it actually verifies if that was the
    rendered file [htonl]

  • Added the option for sharing partial spacer templates just like
    partials themselves [radsaq]

  • Fixed that Russia was named twice in country_select [alexey]

  • Fixed request_origin to use remote_ip instead of remote_addr
    [bitsweat]

  • Fixed link_to breakage when nil was passed for html_options [alexey]

  • Fixed redirect_to on a virtual server setup with apache with a port
    other than the default where it would forget the port number
    [seanohalpin]

  • Fixed that auto-loading webrick on Windows would cause file uploads
    to fail [bitsweat]

  • Fixed issues with sending files on WEBrick by setting the proper
    binmode [bitsweat]

  • Added send_data as an alternative to send_file when the stream is not
    read off the filesystem but from a database or generated live
    [bitsweat]

  • Added a default content-type of “text/xml” to .rxml renders [Ryan
    Platte]

  • Fixed that when /controller/index was requested by the browser,
    url_for would generates wrong URLs [Ryan Platte]

  • Fixed a bug that would share cookies between users when using FastCGI
    and mod_ruby [The Robot Co-op]

  • Added an optional third hash parameter to the process method in
    functional tests that takes the session data to be used [alexey]

  • Added UrlHelper#mail_to to make it easier to create mailto: style
    ahrefs

  • Added better error messages for layouts declared with the .rhtml
    extension (which they shouldn’t) [geech]

  • Added another case to DateHelper#distance_in_minutes to return “less
    than a minute” instead of “0 minutes” and “1 minute” instead of “1
    minutes”

  • Fixed error_message_on to just use the first if more than one error
    had been added [marcel]

  • Fixed that URL rewriting with /controller/ was working but
    /controller was not and that you couldn’t use :id on index [geech]

  • Fixed a bug with link_to where the :confirm option wouldn’t be picked
    up if the link was a straight url instead of an option hash

  • Changed scaffolding of forms to use tags instead of to
    please W3C [evl]

  • Added DateHelper#distance_of_time_in_words_to_now(from_time) that
    works like distance_of_time_in_words, but where to_time is
    fixed to Time.now.

  • Added assert_flash_equal(expected, key, message),
    assert_session_equal(expected, key, message),
    assert_assigned_equal(expected, key, message) to test the contents of
    flash, session, and template assigns.

  • Improved the failure report on assert_success when the action
    triggered a redirection [alexey].

  • Added “markdown” to accompany “textilize” as a TextHelper method for
    converting text to HTML using the Markdown syntax. BlueCloth must be
    installed in order for this method to become available.

  • Made sure that an active session exists before we attempt to delete
    it [Samuel]

  • Changed link_to with Javascript confirmation to use onclick instead
    of onClick for XHTML validity [Scott Barron]

David Heinemeier Hansson wrote:


Or even easier, just do “gem install rails” (or “gem update” if you’re
already running on Gem Rails) – you’ll automatically install all the
newest versions of the required dependencies.

I just gave that a whirl, using gems to update my current rails
installation, and got this:

gem update
Upgrading installed gems…
Attempting remote upgrade of actionmailer
Attempting remote installation of ‘actionmailer’
ERROR: While executing gem … (NoMethodError)
undefined method `serialize’ for
CGI::Session::ActiveRecordStore::Session:Class

gem -v => 0.8.1

ruby -v => ruby 1.8.2 (2004-07-29) [i386-mswin32]

Thanks,

James

PS

Running ‘gem update’ will update all installed gems. If any gem has a
an update that breaks compatibility, then people may end up with
unexpected/unwanted code changes.

I believe that just running
gem install rails
will update just rails, or install it if there is no existing
installation, so it may be a safer way to get the gem set up.

I just gave that a whirl, using gems to update my current rails installation, and got this:

Sounds like you were on Rails 0.7.0 or older. There was an issue with actionpack back then.

Solution: Remove all the old Rails' gems and do "gem install rails".

···

--
David Heinemeier Hansson,
http://www.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://macromates.com/ -- TextMate: Code and markup editor (OS X)
http://www.loudthinking.com/ -- Broadcasting Brain

David Heinemeier Hansson wrote:

I just gave that a whirl, using gems to update my current rails installation, and got this:

Sounds like you were on Rails 0.7.0 or older. There was an issue with actionpack back then.

Rails 0.8.0, but snuffing the actionmailer gem folder, and running install rails again, seemed to work.

Thanks,

James