Ticket #41: published_date.diff

File published_date.diff, 3.9 kB (added by Daniel Sheppard, 2 years ago)

Implementation

  • test/functional/admin/page_controller_test.rb

    old new  
    9393    assert_match /error/, flash[:error] 
    9494    assert_nil get_test_page 
    9595    assert_nil get_test_part 
    96   end 
     96  end 
     97  def test_new__post_with_published_date 
     98    date = Time.now.utc 
     99    post :new, :parent_id => '1', :page => page_params(:published_at => date) 
     100    assert_redirected_to page_index_url 
     101    @page = get_test_page 
     102    assert_kind_of Page, @page 
     103    assert_equal date.to_i, @page.published_at.to_i 
     104  end    
     105  def test_new__post_with_published_date_on_automatic 
     106    post :new, :parent_id => '1', :page => page_params(:published_at => Date.today), :automatic_published_at => true 
     107    assert_redirected_to page_index_url 
     108    @page = get_test_page 
     109    assert_kind_of Page, @page 
     110    assert_nil @page.published_at 
     111  end     
     112  def test_new__post_with_published_date_when_published 
     113    post :new, :parent_id => '1', :page => page_params(:status_id => Status[:published].id, :published_at => Date.today), :automatic_published_at => true 
     114    assert_redirected_to page_index_url 
     115    @page = get_test_page 
     116    assert_kind_of Page, @page 
     117    assert @page.published_at 
     118  end   
     119   
    97120  def test_new__save_and_continue_editing 
    98121    post :new, :parent_id => '1', :page => page_params, :continue => 'Save and Continue Editing' 
    99122    @page = get_test_page 
  • app/controllers/admin/page_controller.rb

    old new  
    8383    end 
    8484     
    8585    def handle_new_or_edit_post 
    86       if request.post? 
    87         @page.attributes = params[:page] 
     86      if request.post? 
     87        page_params = params[:page] 
     88        page_params.delete(:published_at) if params[:automatic_published_at] 
     89        @page.attributes = page_params 
    8890         
    8991        original_names = @page.parts.map { |part| part.name } 
    9092        new_names = (params[:part] || {}).values.map { |part| part[:name] } 
  • app/views/admin/page/new.rhtml

    old new  
    7575          <td><label for="page_breadcrumb">Breadcrumb</label></td> 
    7676          <td class="field"><%= text_field "page", "breadcrumb", :class => 'textbox', :maxlength => 160 %></td> 
    7777        </tr> 
     78        <tr> 
     79          <td><label>Published Date</label></td> 
     80          <td class="field"> 
     81            <% if @page.published_at -%> 
     82              <%= datetime_select "page", "published_at" %> 
     83            <% else -%> 
     84              <span id="published_at_wrapper"><%= datetime_select "page", "published_at" %></span> 
     85              <label> 
     86                <%= check_box_tag("automatic_published_at", "1",  true, :id => 'automatic_published_at') %> 
     87                Automatic 
     88              </label> 
     89              <script type="text/javascript"> 
     90              // <![CDATA[ 
     91                function automatic_published_at_updated() { 
     92                  selects = $('published_at_wrapper').getElementsByTagName('select'); 
     93                  for(i=0; i < selects.length; i++) { 
     94                    selects[i].disabled = $F('automatic_published_at'); 
     95                  } 
     96                } 
     97                selects = $('published_at_wrapper').getElementsByTagName('select'); 
     98                for(i=0; i < selects.length; i++) { 
     99                  selects[i].disabled = true; 
     100                } 
     101                Event.observe('automatic_published_at', 'click', automatic_published_at_updated); 
     102              // ]]> 
     103              </script>               
     104            <% end -%> 
     105          </td> 
     106        </tr> 
    78107      </table> 
    79108      <script type="text/javascript"> 
    80109      // <![CDATA[