Project

General

Profile

Defect #5538 ยป keep_default_widgets.diff

Holger Just, 2010-05-17 15:44

View differences:

app/controllers/my_controller.rb (working copy)
136 136
    block = params[:block].to_s.underscore
137 137
    (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
138 138
    @user = User.current
139
    layout = @user.pref[:my_page_layout] || {}
139
    layout = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
140 140
    # remove if already present in a group
141 141
    %w(top left right).each {|f| (layout[f] ||= []).delete block }
142 142
    # add it on top
......
152 152
    block = params[:block].to_s.underscore
153 153
    @user = User.current
154 154
    # remove block in all groups
155
    layout = @user.pref[:my_page_layout] || {}
155
    layout = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
156 156
    %w(top left right).each {|f| (layout[f] ||= []).delete block }
157 157
    @user.pref[:my_page_layout] = layout
158 158
    @user.pref.save 
......
168 168
    if group.is_a?(String)
169 169
      group_items = (params["list-#{group}"] || []).collect(&:underscore)
170 170
      if group_items and group_items.is_a? Array
171
        layout = @user.pref[:my_page_layout] || {}
171
        layout = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
172 172
        # remove group blocks if they are presents in other groups
173 173
        %w(top left right).each {|f|
174 174
          layout[f] = (layout[f] || []) - group_items
test/functional/my_controller_test.rb (working copy)
129 129
    assert_response :success
130 130
    assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
131 131
  end
132
  
133
  context "MyPage layout for new users" do
134
    setup do
135
      @user = User.find(2)
136
      assert_equal @user.preference, nil
137
      @user.save
138
    end
139
    
140
    should "add block" do
141
      xhr :post, :add_block, :block => 'issueswatched'
142
      assert_response :success
143
      
144
      @user.reload
145
      assert @user.pref[:my_page_layout]['top'].include?('issueswatched')
146
      assert @user.pref[:my_page_layout]['right'].include?('issuesreportedbyme')
147
    end
148
    
149
    should "remove block" do
150
      xhr :post, :remove_block, :block => 'issueswatched'
151
      assert_response :success
152
      
153
      @user.reload
154
      assert !@user.pref[:my_page_layout]['top'].include?('issueswatched')
155
      assert @user.pref[:my_page_layout]['right'].include?('issuesreportedbyme')
156
    end
157
    
158
    should "order blocks" do
159
      xhr :post, :order_blocks, :group => 'top', 'list-top' => ['issuesreportedbyme', 'issuesassignedtome']
160
      assert_response :success
161
      
162
      @user.reload
163
      assert_equal ['issuesreportedbyme', 'issuesassignedtome'], @user.pref[:my_page_layout]['top']
164
      
165
      assert_equal [], @user.pref[:my_page_layout]['left']
166
      assert_equal [], @user.pref[:my_page_layout]['right']
167
    end
168
  end
132 169

  
133 170
  context "POST to reset_rss_key" do
134 171
    context "with an existing rss_token" do
    (1-1/1)