Skip to content

Commit

Permalink
+models: Prase,Translate,TranslatesFrases
Browse files Browse the repository at this point in the history
  • Loading branch information
DarTSeNSe committed Dec 9, 2011
1 parent eeb5268 commit 61a29db
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/models/phrase.rb
@@ -0,0 +1,16 @@
class Phrase < ActiveRecord::Base
attr_accessible :phrase, :tag

has_many :translates, :dependent => :destroy
has_many :translates_phrases, :class_name => "TranslatesPhrases",
:foreign_key => "translate_id",
:dependent => :destroy

belongs_to :user

validates :phrase, :presence => true,
:length => { :maximum => 140 },
:uniqueness => { :case_sensitive => false }
validates :user_id, :presence => true

end
12 changes: 12 additions & 0 deletions app/models/translate.rb
@@ -0,0 +1,12 @@
class Translate < ActiveRecord::Base
attr_accessible :translate, :rating

belongs_to :phrase
belongs_to :translates_phrases, :foreign_key => "phrase_id",
:dependent => :destroy

validates :translate, :presence => true,
:length => { :maximum => 200 },
:uniqueness => { :case_sensitive => false }
validates :rating, :presence => true
end
10 changes: 10 additions & 0 deletions app/models/translates_phrases.rb
@@ -0,0 +1,10 @@
class TranslatesPhrases < ActiveRecord::Base
attr_accessible :translate_id, :phrase_id

belongs_to :phrase
belongs_to :translate

validates :phrase_id, :presence => true
validates :translate_id, :presence => true

end
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -2,6 +2,8 @@ class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation

has_many :phrases, :dependent => :destroy

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :name, :presence => true,
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20111209123536_create_phrases.rb
@@ -0,0 +1,14 @@
class CreatePhrases < ActiveRecord::Migration
def change
create_table :phrases do |t|
t.string :phrase, :unique => true
t.string :tag
t.integer :user_id

t.timestamps
end
add_index :phrases, :phrase
add_index :phrases, :tag
add_index :phrases, :user_id
end
end
16 changes: 16 additions & 0 deletions db/migrate/20111209123913_create_translates.rb
@@ -0,0 +1,16 @@
class CreateTranslates < ActiveRecord::Migration
def change
create_table :translates do |t|
t.string :translate
t.integer :phrase_id
t.integer :language_id
t.string :rating

t.timestamps
end
add_index :translates, :translate
add_index :translates, :phrase_id
add_index :translates, :language_id
add_index :translates, :rating
end
end
13 changes: 13 additions & 0 deletions db/migrate/20111209124823_create_translates_phrases.rb
@@ -0,0 +1,13 @@
class CreateTranslatesPhrases < ActiveRecord::Migration
def change
create_table :translates_phrases, :id => false do |t|
t.integer :phrase_id
t.integer :translate_id

t.timestamps
end
add_index :translates_phrases, :translate_id
add_index :translates_phrases, :phrase_id
add_index :translates_phrases, [:phrase_id, :translate_id], :unique => true
end
end
26 changes: 25 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,31 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111209090431) do
ActiveRecord::Schema.define(:version => 20111209124823) do

create_table "phrases", :force => true do |t|
t.string "phrase"
t.string "tag"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "translates", :force => true do |t|
t.string "translate"
t.integer "phrase_id"
t.integer "language_id"
t.string "rating"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "translates_phrases", :id => false, :force => true do |t|
t.integer "phrase_id"
t.integer "translate_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "name"
Expand Down
5 changes: 5 additions & 0 deletions spec/models/phrase_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Phrase do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/translate_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Translate do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/translates_phrases_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe TranslatesPhrases do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 61a29db

Please sign in to comment.