diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index e4529226e..64665147f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -9,7 +9,7 @@ class HomeController < ApplicationController if params[:home] redirect_to :controller => 'aspects', :action => 'index' else - redirect_to :controller => 'aspects', :action => 'index', :a_ids => current_user.open_aspects + redirect_to :controller => 'aspects', :action => 'index', :a_ids => current_user.aspects.where(:open => true).select(:id).all end elsif is_mobile_device? redirect_to user_session_path diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0ba9f9ac4..61196f288 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,12 +42,10 @@ class UsersController < ApplicationController flash[:error] = I18n.t 'users.update.language_not_changed' end elsif params[:user][:a_ids] - if params[:user][:a_ids] == ["home"] - @user.open_aspects = nil - else - @user.open_aspects = params[:user][:a_ids] + @user.aspects.update_all(:open => false) + unless params[:user][:a_ids] == ["home"] + @user.aspects.where(:id => params[:user][:a_ids]).update_all(:open => true) end - @user.save! end redirect_to edit_user_path(@user) diff --git a/db/migrate/20110201013408_add_open_aspects_to_user.rb b/db/migrate/20110201013408_add_open_aspects_to_user.rb index ddc214129..11d7f9470 100644 --- a/db/migrate/20110201013408_add_open_aspects_to_user.rb +++ b/db/migrate/20110201013408_add_open_aspects_to_user.rb @@ -1,9 +1,9 @@ class AddOpenAspectsToUser < ActiveRecord::Migration def self.up - add_column(:users, :open_aspects, :text) + add_column(:aspects, :open, :boolean, :default => false) end def self.down - remove_column(:users, :open_aspects) + remove_column(:aspects, :open) end end diff --git a/db/schema.rb b/db/schema.rb index ad00b9575..8d4dd815d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -24,13 +24,14 @@ ActiveRecord::Schema.define(:version => 20110201013408) 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 + t.boolean "contacts_visible", :default => true, :null => false + t.boolean "open", :default => false end add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id" @@ -458,7 +459,6 @@ ActiveRecord::Schema.define(:version => 20110201013408) do t.string "mongo_id" t.string "invitation_service" t.string "invitation_identifier" - t.text "open_aspects" end add_index "users", ["email"], :name => "index_users_on_email" diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index aa476e343..ab29b6d1d 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -22,7 +22,7 @@ describe HomeController do it 'redirects to aspects index if user is logged in' do sign_in @user - get :show + get :show, :home => true response.should redirect_to( :controller => 'aspects', :action => 'index') end @@ -31,7 +31,7 @@ describe HomeController do @aspect0 = @user.aspects.all[0] @aspect1 = @user.aspects.create(:name => "Yeaaaah!") @index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]} - @user.open_aspects = @index_params[:a_ids] + @user.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true) @user.save get :show response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] ) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 06ace0a34..cad5f459a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -37,14 +37,14 @@ describe UsersController do it "stores the aspect params in the user" do put :update, @index_params - @user.reload.open_aspects.should == @index_params[:user][:a_ids] + @user.reload.aspects.where(:open => true).all.to_set.should == [@aspect, @aspect1].to_set end it "correctly resets the home state" do @index_params[:user][:a_ids] = ["home"] put :update, @index_params - @user.reload.open_aspects.should == nil + @user.aspects.where(:open => true).should == [] end end