add contacts_visible field in aspects
This commit is contained in:
parent
86ab893a63
commit
a23290986a
3 changed files with 25 additions and 5 deletions
17
db/migrate/20110126200714_add_contacts_visible.rb
Normal file
17
db/migrate/20110126200714_add_contacts_visible.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class AddContactsVisible < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :aspects, :contacts_visible, :boolean, :default => true, :null => false
|
||||
add_index :aspects, [:user_id, :contacts_visible]
|
||||
|
||||
ActiveRecord::Base.connection.execute <<-SQL
|
||||
UPDATE `aspects`
|
||||
SET contacts_visible = false
|
||||
WHERE contacts_visible IS NULL
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :aspects, [:user_id, :contacts_visible]
|
||||
remove_column :aspects, :contacts_visible
|
||||
end
|
||||
end
|
||||
|
|
@ -24,15 +24,17 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
|||
add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id"
|
||||
|
||||
create_table "aspects", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.string "name", :null => false
|
||||
t.integer "user_id", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "mongo_id"
|
||||
t.string "user_mongo_id"
|
||||
t.boolean "contacts_visible", :default => true, :null => false
|
||||
end
|
||||
|
||||
add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id"
|
||||
add_index "aspects", ["user_id", "contacts_visible"], :name => "index_aspects_on_user_id_and_contacts_visible"
|
||||
add_index "aspects", ["user_id"], :name => "index_aspects_on_user_id"
|
||||
|
||||
create_table "comments", :force => true do |t|
|
||||
|
|
|
|||
|
|
@ -47,12 +47,13 @@ describe Aspect do
|
|||
aspect.contacts.include?(contact2).should be_true
|
||||
aspect.save.should be_true
|
||||
end
|
||||
|
||||
it 'has a contacts_visible? method' do
|
||||
aspect.contacts_visible?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
before do
|
||||
aspect
|
||||
end
|
||||
it 'has a unique name for one user' do
|
||||
aspect2 = user.aspects.create(:name => aspect.name)
|
||||
aspect2.valid?.should be_false
|
||||
|
|
|
|||
Loading…
Reference in a new issue