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:
parent
49794485b6
commit
43b81d01d0
47 changed files with 47 additions and 48 deletions
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
@ -23,7 +23,7 @@ class Author < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :special_posts
|
has_many :special_posts
|
||||||
has_many :special_post_comments, :through => :special_posts, :source => :comments
|
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_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 :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
|
||||||
has_many :nonexistant_comments, :through => :posts
|
has_many :nonexistant_comments, :through => :posts
|
||||||
|
@ -34,7 +34,7 @@ class Author < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :other_posts, :class_name => "Post"
|
has_many :other_posts, :class_name => "Post"
|
||||||
has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
|
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,
|
:before_remove => :log_before_removing,
|
||||||
:after_remove => :log_after_removing
|
:after_remove => :log_after_removing
|
||||||
has_many :posts_with_proc_callbacks, :class_name => "Post",
|
has_many :posts_with_proc_callbacks, :class_name => "Post",
|
|
@ -2,7 +2,7 @@ class Category < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :posts
|
has_and_belongs_to_many :posts
|
||||||
has_and_belongs_to_many :special_posts, :class_name => "Post"
|
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 :other_posts, :class_name => "Post"
|
||||||
|
|
||||||
has_and_belongs_to_many(:select_testing_posts,
|
has_and_belongs_to_many(:select_testing_posts,
|
||||||
:class_name => 'Post',
|
:class_name => 'Post',
|
||||||
:foreign_key => 'category_id',
|
:foreign_key => 'category_id',
|
||||||
|
@ -12,15 +12,15 @@ class Category < ActiveRecord::Base
|
||||||
def self.what_are_you
|
def self.what_are_you
|
||||||
'a category...'
|
'a category...'
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :categorizations
|
has_many :categorizations
|
||||||
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
|
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
|
||||||
end
|
end
|
||||||
|
|
||||||
class SpecialCategory < Category
|
class SpecialCategory < Category
|
||||||
|
|
||||||
def self.what_are_you
|
def self.what_are_you
|
||||||
'a special category...'
|
'a special category...'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,10 +1,10 @@
|
||||||
class Comment < ActiveRecord::Base
|
class Comment < ActiveRecord::Base
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
|
|
||||||
def self.what_are_you
|
def self.what_are_you
|
||||||
'a comment...'
|
'a comment...'
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search_by_type(q)
|
def self.search_by_type(q)
|
||||||
self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
|
self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
|
||||||
end
|
end
|
|
@ -9,7 +9,7 @@ class Company < AbstractCompany
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
|
|
||||||
has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
|
has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
|
||||||
|
|
||||||
def arbitrary_method
|
def arbitrary_method
|
||||||
"I am Jack's profound disappointment"
|
"I am Jack's profound disappointment"
|
||||||
end
|
end
|
||||||
|
@ -74,12 +74,12 @@ class Client < Company
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used to test that read and question methods are not generated for these attributes
|
# Used to test that read and question methods are not generated for these attributes
|
||||||
def ruby_type
|
def ruby_type
|
||||||
read_attribute :ruby_type
|
read_attribute :ruby_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def rating?
|
def rating?
|
||||||
query_attribute :rating
|
query_attribute :rating
|
||||||
end
|
end
|
||||||
|
@ -94,7 +94,7 @@ end
|
||||||
|
|
||||||
class Account < ActiveRecord::Base
|
class Account < ActiveRecord::Base
|
||||||
belongs_to :firm
|
belongs_to :firm
|
||||||
|
|
||||||
def self.destroyed_account_ids
|
def self.destroyed_account_ids
|
||||||
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
|
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
|
||||||
end
|
end
|
||||||
|
@ -105,8 +105,8 @@ class Account < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def validate
|
def validate
|
||||||
errors.add_on_empty "credit_limit"
|
errors.add_on_empty "credit_limit"
|
|
@ -3,7 +3,7 @@ module MyApplication
|
||||||
class Company < ActiveRecord::Base
|
class Company < ActiveRecord::Base
|
||||||
attr_protected :rating
|
attr_protected :rating
|
||||||
end
|
end
|
||||||
|
|
||||||
class Firm < Company
|
class Firm < Company
|
||||||
has_many :clients, :order => "id", :dependent => :destroy
|
has_many :clients, :order => "id", :dependent => :destroy
|
||||||
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
|
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, :foreign_key => "client_of"
|
||||||
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
|
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
|
||||||
end
|
end
|
||||||
|
|
||||||
class Developer < ActiveRecord::Base
|
class Developer < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :projects
|
has_and_belongs_to_many :projects
|
||||||
validates_length_of :name, :within => (3..20)
|
validates_length_of :name, :within => (3..20)
|
||||||
end
|
end
|
||||||
|
|
||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :developers
|
has_and_belongs_to_many :developers
|
||||||
end
|
end
|
|
@ -1,4 +1,3 @@
|
||||||
class Computer < ActiveRecord::Base
|
class Computer < ActiveRecord::Base
|
||||||
belongs_to :developer, :foreign_key=>'developer'
|
belongs_to :developer, :foreign_key=>'developer'
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,6 @@ class Contact < ActiveRecord::Base
|
||||||
column :created_at, :datetime
|
column :created_at, :datetime
|
||||||
column :awesome, :boolean
|
column :awesome, :boolean
|
||||||
column :preferences, :string
|
column :preferences, :string
|
||||||
|
|
||||||
serialize :preferences
|
serialize :preferences
|
||||||
end
|
end
|
|
@ -10,25 +10,25 @@ class Address
|
||||||
def initialize(street, city, country)
|
def initialize(street, city, country)
|
||||||
@street, @city, @country = street, city, country
|
@street, @city, @country = street, city, country
|
||||||
end
|
end
|
||||||
|
|
||||||
def close_to?(other_address)
|
def close_to?(other_address)
|
||||||
city == other_address.city && country == other_address.country
|
city == other_address.city && country == other_address.country
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
|
other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Money
|
class Money
|
||||||
attr_reader :amount, :currency
|
attr_reader :amount, :currency
|
||||||
|
|
||||||
EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
|
EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
|
||||||
|
|
||||||
def initialize(amount, currency = "USD")
|
def initialize(amount, currency = "USD")
|
||||||
@amount, @currency = amount, currency
|
@amount, @currency = amount, currency
|
||||||
end
|
end
|
||||||
|
|
||||||
def exchange_to(other_currency)
|
def exchange_to(other_currency)
|
||||||
Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
|
Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
|
||||||
end
|
end
|
||||||
|
@ -36,15 +36,15 @@ end
|
||||||
|
|
||||||
class GpsLocation
|
class GpsLocation
|
||||||
attr_reader :gps_location
|
attr_reader :gps_location
|
||||||
|
|
||||||
def initialize(gps_location)
|
def initialize(gps_location)
|
||||||
@gps_location = gps_location
|
@gps_location = gps_location
|
||||||
end
|
end
|
||||||
|
|
||||||
def latitude
|
def latitude
|
||||||
gps_location.split("x").first
|
gps_location.split("x").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def longitude
|
def longitude
|
||||||
gps_location.split("x").last
|
gps_location.split("x").last
|
||||||
end
|
end
|
|
@ -16,22 +16,22 @@ class Developer < ActiveRecord::Base
|
||||||
find(:first, :order => "id DESC")
|
find(:first, :order => "id DESC")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
has_and_belongs_to_many :projects_extended_by_name,
|
has_and_belongs_to_many :projects_extended_by_name,
|
||||||
:class_name => "Project",
|
:class_name => "Project",
|
||||||
:join_table => "developers_projects",
|
:join_table => "developers_projects",
|
||||||
:association_foreign_key => "project_id",
|
:association_foreign_key => "project_id",
|
||||||
:extend => DeveloperProjectsAssociationExtension
|
:extend => DeveloperProjectsAssociationExtension
|
||||||
|
|
||||||
has_and_belongs_to_many :projects_extended_by_name_twice,
|
has_and_belongs_to_many :projects_extended_by_name_twice,
|
||||||
:class_name => "Project",
|
:class_name => "Project",
|
||||||
:join_table => "developers_projects",
|
:join_table => "developers_projects",
|
||||||
:association_foreign_key => "project_id",
|
:association_foreign_key => "project_id",
|
||||||
:extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
|
:extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
|
||||||
|
|
||||||
has_and_belongs_to_many :projects_extended_by_name_and_block,
|
has_and_belongs_to_many :projects_extended_by_name_and_block,
|
||||||
:class_name => "Project",
|
:class_name => "Project",
|
||||||
:join_table => "developers_projects",
|
:join_table => "developers_projects",
|
||||||
:association_foreign_key => "project_id",
|
:association_foreign_key => "project_id",
|
||||||
:extend => DeveloperProjectsAssociationExtension do
|
:extend => DeveloperProjectsAssociationExtension do
|
||||||
def find_least_recent
|
def find_least_recent
|
|
@ -1,4 +1,4 @@
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
|
belongs_to :billing, :class_name => 'Customer', :foreign_key => 'billing_customer_id'
|
||||||
belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
|
belongs_to :shipping, :class_name => 'Customer', :foreign_key => 'shipping_customer_id'
|
||||||
end
|
end
|
|
@ -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'
|
:joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :funky_tags, :through => :taggings, :source => :tag
|
has_many :funky_tags, :through => :taggings, :source => :tag
|
||||||
has_many :super_tags, :through => :taggings
|
has_many :super_tags, :through => :taggings
|
||||||
has_one :tagging, :as => :taggable
|
has_one :tagging, :as => :taggable
|
|
@ -6,20 +6,20 @@ class Reply < Topic
|
||||||
|
|
||||||
validate :errors_on_empty_content
|
validate :errors_on_empty_content
|
||||||
validate_on_create :title_is_wrong_create
|
validate_on_create :title_is_wrong_create
|
||||||
|
|
||||||
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
|
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
errors.add("title", "Empty") unless attribute_present? "title"
|
errors.add("title", "Empty") unless attribute_present? "title"
|
||||||
end
|
end
|
||||||
|
|
||||||
def errors_on_empty_content
|
def errors_on_empty_content
|
||||||
errors.add("content", "Empty") unless attribute_present? "content"
|
errors.add("content", "Empty") unless attribute_present? "content"
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_on_create
|
def validate_on_create
|
||||||
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
||||||
errors.add("title", "is Content Mismatch")
|
errors.add("title", "is Content Mismatch")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
class Topic < ActiveRecord::Base
|
class Topic < ActiveRecord::Base
|
||||||
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
|
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
|
||||||
serialize :content
|
serialize :content
|
||||||
|
|
||||||
before_create :default_written_on
|
before_create :default_written_on
|
||||||
before_destroy :destroy_children
|
before_destroy :destroy_children
|
||||||
|
|
||||||
def parent
|
def parent
|
||||||
Topic.find(parent_id)
|
Topic.find(parent_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# trivial method for testing Array#to_xml with :methods
|
# trivial method for testing Array#to_xml with :methods
|
||||||
def topic_id
|
def topic_id
|
||||||
id
|
id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def approved=(val)
|
def approved=(val)
|
Loading…
Reference in a new issue