diff --git a/db/migrate/20110126200714_add_contacts_visible.rb b/db/migrate/20110126200714_add_contacts_visible.rb new file mode 100644 index 000000000..6b7af3023 --- /dev/null +++ b/db/migrate/20110126200714_add_contacts_visible.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 9ca792866..b48fb9b95 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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| diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index ff30f64c1..ff4f668f4 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -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