From fa421e4649a426a9c19d7b17aeb0e6e5aa442fca Mon Sep 17 00:00:00 2001 From: Keeran Hawoldar Date: Thu, 24 Apr 2008 20:33:36 +0100 Subject: [PATCH] Added tests and associated fixtures/models for rendering has_one partials --- ...nder_partial_with_record_identification_test.rb | 14 +++++++++++++- actionpack/test/fixtures/company.rb | 1 + actionpack/test/fixtures/db_definitions/sqlite.sql | 6 ++++++ actionpack/test/fixtures/mascot.rb | 3 +++ actionpack/test/fixtures/mascots.yml | 4 ++++ actionpack/test/fixtures/mascots/_mascot.html.erb | 1 + 6 files changed, 28 insertions(+), 1 deletions(-) create mode 100644 actionpack/test/fixtures/mascot.rb create mode 100644 actionpack/test/fixtures/mascots.yml create mode 100644 actionpack/test/fixtures/mascots/_mascot.html.erb diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index 773018d..a0b95d4 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -1,7 +1,7 @@ require 'active_record_unit' class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase - fixtures :developers, :projects, :developers_projects, :topics, :replies + fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots class RenderPartialWithRecordIdentificationController < ActionController::Base def render_with_has_many_and_belongs_to_association @@ -19,6 +19,11 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase render :partial => @developer.topics end + def render_with_has_one_association + @company = Company.find(1) + render :partial => @company.mascot + end + def render_with_belongs_to_association @reply = Reply.find(1) render :partial => @reply.topic @@ -58,6 +63,13 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase assert_template 'topics/_topic' end + def test_rendering_partial_with_has_one_association + mascot = Company.find(1).mascot + get :render_with_has_one_association + assert_template 'mascots/_mascot' + assert_equal mascot.name, @response.body + end + def test_rendering_partial_with_belongs_to_association topic = Reply.find(1).topic get :render_with_belongs_to_association diff --git a/actionpack/test/fixtures/company.rb b/actionpack/test/fixtures/company.rb index 0d1c29b..cbbd0ed 100644 --- a/actionpack/test/fixtures/company.rb +++ b/actionpack/test/fixtures/company.rb @@ -1,4 +1,5 @@ class Company < ActiveRecord::Base + has_one :mascot attr_protected :rating set_sequence_name :companies_nonstd_seq diff --git a/actionpack/test/fixtures/db_definitions/sqlite.sql b/actionpack/test/fixtures/db_definitions/sqlite.sql index 358c2bb..8e1947d 100644 --- a/actionpack/test/fixtures/db_definitions/sqlite.sql +++ b/actionpack/test/fixtures/db_definitions/sqlite.sql @@ -41,3 +41,9 @@ CREATE TABLE 'developers_projects' ( 'joined_on' DATE DEFAULT NULL, 'access_level' INTEGER DEFAULT 1 ); + +CREATE TABLE 'mascots' ( + 'id' INTEGER PRIMARY KEY NOT NULL, + 'company_id' INTEGER NOT NULL, + 'name' TEXT DEFAULT NULL +); \ No newline at end of file diff --git a/actionpack/test/fixtures/mascot.rb b/actionpack/test/fixtures/mascot.rb new file mode 100644 index 0000000..f9f1448 --- /dev/null +++ b/actionpack/test/fixtures/mascot.rb @@ -0,0 +1,3 @@ +class Mascot < ActiveRecord::Base + belongs_to :company +end \ No newline at end of file diff --git a/actionpack/test/fixtures/mascots.yml b/actionpack/test/fixtures/mascots.yml new file mode 100644 index 0000000..17b7dff --- /dev/null +++ b/actionpack/test/fixtures/mascots.yml @@ -0,0 +1,4 @@ +upload_bird: + id: 1 + company_id: 1 + name: The Upload Bird \ No newline at end of file diff --git a/actionpack/test/fixtures/mascots/_mascot.html.erb b/actionpack/test/fixtures/mascots/_mascot.html.erb new file mode 100644 index 0000000..432773a --- /dev/null +++ b/actionpack/test/fixtures/mascots/_mascot.html.erb @@ -0,0 +1 @@ +<%= mascot.name %> \ No newline at end of file -- 1.5.4.5