1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

move assets and models

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8657 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2008-01-18 07:27:03 +00:00
parent 49794485b6
commit 43b81d01d0
47 changed files with 47 additions and 48 deletions

View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -23,7 +23,7 @@ class Author < ActiveRecord::Base
has_many :special_posts
has_many :special_post_comments, :through => :special_posts, :source => :comments
has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
has_many :nonexistant_comments, :through => :posts
@ -34,7 +34,7 @@ class Author < ActiveRecord::Base
has_many :other_posts, :class_name => "Post"
has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
:after_add => :log_after_adding,
:after_add => :log_after_adding,
:before_remove => :log_before_removing,
:after_remove => :log_after_removing
has_many :posts_with_proc_callbacks, :class_name => "Post",

View file

@ -2,7 +2,7 @@ class Category < ActiveRecord::Base
has_and_belongs_to_many :posts
has_and_belongs_to_many :special_posts, :class_name => "Post"
has_and_belongs_to_many :other_posts, :class_name => "Post"
has_and_belongs_to_many(:select_testing_posts,
:class_name => 'Post',
:foreign_key => 'category_id',
@ -12,15 +12,15 @@ class Category < ActiveRecord::Base
def self.what_are_you
'a category...'
end
has_many :categorizations
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
end
class SpecialCategory < Category
def self.what_are_you
'a special category...'
end
end
end

View file

@ -1,10 +1,10 @@
class Comment < ActiveRecord::Base
belongs_to :post
def self.what_are_you
'a comment...'
end
def self.search_by_type(q)
self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
end

View file

@ -9,7 +9,7 @@ class Company < AbstractCompany
validates_presence_of :name
has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
def arbitrary_method
"I am Jack's profound disappointment"
end
@ -74,12 +74,12 @@ class Client < Company
end
true
end
# Used to test that read and question methods are not generated for these attributes
def ruby_type
read_attribute :ruby_type
end
def rating?
query_attribute :rating
end
@ -94,7 +94,7 @@ end
class Account < ActiveRecord::Base
belongs_to :firm
def self.destroyed_account_ids
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
end
@ -105,8 +105,8 @@ class Account < ActiveRecord::Base
end
true
end
protected
def validate
errors.add_on_empty "credit_limit"

View file

@ -3,7 +3,7 @@ module MyApplication
class Company < ActiveRecord::Base
attr_protected :rating
end
class Firm < Company
has_many :clients, :order => "id", :dependent => :destroy
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
@ -18,12 +18,12 @@ module MyApplication
belongs_to :firm, :foreign_key => "client_of"
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
end
class Developer < ActiveRecord::Base
has_and_belongs_to_many :projects
validates_length_of :name, :within => (3..20)
end
class Project < ActiveRecord::Base
has_and_belongs_to_many :developers
end

View file

@ -1,4 +1,3 @@
class Computer < ActiveRecord::Base
belongs_to :developer, :foreign_key=>'developer'
end

View file

@ -11,6 +11,6 @@ class Contact < ActiveRecord::Base
column :created_at, :datetime
column :awesome, :boolean
column :preferences, :string
serialize :preferences
end

View file

@ -10,25 +10,25 @@ class Address
def initialize(street, city, country)
@street, @city, @country = street, city, country
end
def close_to?(other_address)
city == other_address.city && country == other_address.country
end
def ==(other)
other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
end
end
end
class Money
attr_reader :amount, :currency
EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
def initialize(amount, currency = "USD")
@amount, @currency = amount, currency
end
def exchange_to(other_currency)
Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
end
@ -36,15 +36,15 @@ end
class GpsLocation
attr_reader :gps_location
def initialize(gps_location)
@gps_location = gps_location
end
def latitude
gps_location.split("x").first
end
def longitude
gps_location.split("x").last
end

View file

@ -16,22 +16,22 @@ class Developer < ActiveRecord::Base
find(:first, :order => "id DESC")
end
end
has_and_belongs_to_many :projects_extended_by_name,
:class_name => "Project",
:join_table => "developers_projects",
has_and_belongs_to_many :projects_extended_by_name,
:class_name => "Project",
:join_table => "developers_projects",
:association_foreign_key => "project_id",
:extend => DeveloperProjectsAssociationExtension
has_and_belongs_to_many :projects_extended_by_name_twice,
:class_name => "Project",
:join_table => "developers_projects",
has_and_belongs_to_many :projects_extended_by_name_twice,
:class_name => "Project",
:join_table => "developers_projects",
:association_foreign_key => "project_id",
:extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
has_and_belongs_to_many :projects_extended_by_name_and_block,
:class_name => "Project",
:join_table => "developers_projects",
has_and_belongs_to_many :projects_extended_by_name_and_block,
:class_name => "Project",
:join_table => "developers_projects",
:association_foreign_key => "project_id",
:extend => DeveloperProjectsAssociationExtension do
def find_least_recent

View file

@ -1,4 +1,4 @@
class Order < ActiveRecord::Base
belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
end

View file

@ -28,7 +28,7 @@ class Post < ActiveRecord::Base
:joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
end
end
has_many :funky_tags, :through => :taggings, :source => :tag
has_many :super_tags, :through => :taggings
has_one :tagging, :as => :taggable

View file

@ -6,20 +6,20 @@ class Reply < Topic
validate :errors_on_empty_content
validate_on_create :title_is_wrong_create
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
def validate
errors.add("title", "Empty") unless attribute_present? "title"
end
def errors_on_empty_content
errors.add("content", "Empty") unless attribute_present? "content"
end
def validate_on_create
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
errors.add("title", "is Content Mismatch")
errors.add("title", "is Content Mismatch")
end
end

View file

@ -1,19 +1,19 @@
class Topic < ActiveRecord::Base
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
serialize :content
before_create :default_written_on
before_destroy :destroy_children
def parent
Topic.find(parent_id)
end
# trivial method for testing Array#to_xml with :methods
def topic_id
id
end
protected
def approved=(val)