storing it as a boolean in the aspect
This commit is contained in:
parent
7f026e8271
commit
59f1bff046
6 changed files with 14 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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] )
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue