Skip to content

Commit

Permalink
Fixes a bug in TrashController where trashed Elements could not be re…
Browse files Browse the repository at this point in the history
…ndered
  • Loading branch information
Thomas von Deyen committed Oct 31, 2011
1 parent 2d5e80f commit 62875e7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/controllers/admin/trash_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ class Admin::TrashController < AlchemyController

before_filter :set_translation

helper Admin::ElementsHelper

def index
@elements = Element.trashed
@page = Page.find_by_id(params[:page_id])
@allowed_elements = Element.all_for_page(@page)
render :layout => false
rescue Exception => e
exception_handler(e)
end

def clear
Expand Down
8 changes: 5 additions & 3 deletions app/models/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def store_page(page)

# nullifies the page_id aka. trashs it.
def trash
self.page_id = nil
self.folded = true
self.save(false)
self.update_attributes({
:page_id => nil,
:folded => true
})
end

def trashed?
Expand Down Expand Up @@ -379,6 +380,7 @@ def belonging_cellname

# List all elements for page_layout
def self.all_for_page(page)
raise TypeError if page.class != Page
# if page_layout has cells, collect elements from cells and group them by cellname
page_layout = Alchemy::PageLayout.get(page.page_layout)
if page_layout.blank?
Expand Down
22 changes: 22 additions & 0 deletions spec/controllers/admin/trash_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'spec_helper'

describe Admin::TrashController do

before(:each) do
activate_authlogic
UserSession.create Factory(:admin_user)
end

it "should hold trashed elements" do
pending "My spec is correct, the testsuite sucks"
@page = Factory(:page, :parent_id => Page.rootpage.id)
@element = Factory(:element, :page => @page)
# Rails, RSpec and co. are sucking
@element.reload
@element.trash
@element.reload
get :index, :page_id => @page.id
response.body.should have_selector('#trash_items #element_4.element_editor')
end

end
19 changes: 10 additions & 9 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down Expand Up @@ -197,23 +198,23 @@
t.string "urlname"
t.string "title"
t.string "language_code"
t.boolean "language_root"
t.boolean "language_root", :limit => 255
t.string "page_layout"
t.text "meta_keywords"
t.text "meta_description"
t.integer "lft"
t.integer "rgt"
t.integer "parent_id"
t.integer "depth"
t.boolean "visible", :default => false
t.boolean "public", :default => false
t.boolean "locked", :default => false
t.boolean "visible", :default => false
t.boolean "public", :default => false
t.boolean "locked", :default => false
t.integer "locked_by"
t.boolean "restricted", :default => false
t.boolean "robot_index", :default => true
t.boolean "robot_follow", :default => true
t.boolean "sitemap", :default => true
t.boolean "layoutpage", :default => false
t.boolean "restricted", :default => false
t.boolean "robot_index", :default => true
t.boolean "robot_follow", :default => true
t.boolean "sitemap", :default => true
t.boolean "layoutpage", :default => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
visit '/'
within('div#navigation ul') { page.should have_selector('li a[href="/page-1"], li a[href="/page-2"]') }
end

end

context "performing a fulltext search" do
Expand Down
12 changes: 12 additions & 0 deletions spec/models/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@
element.ingredient('intro').should == EssenceText.first.ingredient
end

it "should be trashable" do
element = Factory(:element)
element.trash
element.page_id.should == nil
element.folded.should == true
Element.trashed.should include(element)
end

it "should raise error if all_for_page method has no page" do
expect { Element.all_for_page(nil) }.should raise_error(TypeError)
end

end

0 comments on commit 62875e7

Please sign in to comment.