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]
|
if params[:home]
|
||||||
redirect_to :controller => 'aspects', :action => 'index'
|
redirect_to :controller => 'aspects', :action => 'index'
|
||||||
else
|
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
|
end
|
||||||
elsif is_mobile_device?
|
elsif is_mobile_device?
|
||||||
redirect_to user_session_path
|
redirect_to user_session_path
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,10 @@ class UsersController < ApplicationController
|
||||||
flash[:error] = I18n.t 'users.update.language_not_changed'
|
flash[:error] = I18n.t 'users.update.language_not_changed'
|
||||||
end
|
end
|
||||||
elsif params[:user][:a_ids]
|
elsif params[:user][:a_ids]
|
||||||
if params[:user][:a_ids] == ["home"]
|
@user.aspects.update_all(:open => false)
|
||||||
@user.open_aspects = nil
|
unless params[:user][:a_ids] == ["home"]
|
||||||
else
|
@user.aspects.where(:id => params[:user][:a_ids]).update_all(:open => true)
|
||||||
@user.open_aspects = params[:user][:a_ids]
|
|
||||||
end
|
end
|
||||||
@user.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to edit_user_path(@user)
|
redirect_to edit_user_path(@user)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
class AddOpenAspectsToUser < ActiveRecord::Migration
|
class AddOpenAspectsToUser < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
add_column(:users, :open_aspects, :text)
|
add_column(:aspects, :open, :boolean, :default => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
remove_column(:users, :open_aspects)
|
remove_column(:aspects, :open)
|
||||||
end
|
end
|
||||||
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"
|
add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id"
|
||||||
|
|
||||||
create_table "aspects", :force => true do |t|
|
create_table "aspects", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
t.string "mongo_id"
|
||||||
t.string "user_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
|
end
|
||||||
|
|
||||||
add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id"
|
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 "mongo_id"
|
||||||
t.string "invitation_service"
|
t.string "invitation_service"
|
||||||
t.string "invitation_identifier"
|
t.string "invitation_identifier"
|
||||||
t.text "open_aspects"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["email"], :name => "index_users_on_email"
|
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
|
it 'redirects to aspects index if user is logged in' do
|
||||||
sign_in @user
|
sign_in @user
|
||||||
get :show
|
get :show, :home => true
|
||||||
response.should redirect_to( :controller => 'aspects', :action => 'index')
|
response.should redirect_to( :controller => 'aspects', :action => 'index')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ describe HomeController do
|
||||||
@aspect0 = @user.aspects.all[0]
|
@aspect0 = @user.aspects.all[0]
|
||||||
@aspect1 = @user.aspects.create(:name => "Yeaaaah!")
|
@aspect1 = @user.aspects.create(:name => "Yeaaaah!")
|
||||||
@index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]}
|
@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
|
@user.save
|
||||||
get :show
|
get :show
|
||||||
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
|
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
|
it "stores the aspect params in the user" do
|
||||||
put :update, @index_params
|
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
|
end
|
||||||
|
|
||||||
it "correctly resets the home state" do
|
it "correctly resets the home state" do
|
||||||
@index_params[:user][:a_ids] = ["home"]
|
@index_params[:user][:a_ids] = ["home"]
|
||||||
|
|
||||||
put :update, @index_params
|
put :update, @index_params
|
||||||
@user.reload.open_aspects.should == nil
|
@user.aspects.where(:open => true).should == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue