Skip to content

Commit

Permalink
Fixed SQLiss queries in list context.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Mar 28, 2011
1 parent a2ba716 commit a064e71
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,11 @@ def find_node
# TEMPORARY HACK until we use the new urls with Rails 3
# If you change this, make sure to test with an image data (cachestamp)
# in a custom_base path.
path = params[:path] = request.env['REQUEST_PATH'].split('/')[2..-1]
if request.env['REQUEST_PATH']
# request.env['REQUEST_PATH'] is not set during testing (but this is
# a temporary hack anyway)
path = params[:path] = request.env['REQUEST_PATH'].split('/')[2..-1]
end
if path.last =~ Zena::Use::Urls::ALLOWED_REGEXP
zip = $3
name = $4
Expand Down
13 changes: 9 additions & 4 deletions lib/zena/use/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_type_for_count(string)

# Resolve unknown methods by trying to build a pseudo-sql query with QueryBuilder.
def querybuilder_eval(method = @method)
return nil if node.klass.kind_of?(Array) # list context
node = single_node

if method =~ /^\d+$/
finder = {:method => "find_node_by_zip(#{method})", :class => Node, :nil => true}
Expand Down Expand Up @@ -271,18 +271,23 @@ def node_context_vars(finder)
end

private
# Build a Query object from SQLiss.
def build_query(count, pseudo_sql, raw_filters = [])
def single_node
node = self.node
while node.list_context?
node = node.up
if !node
raise ::QueryBuilder::Error.new("Could not access node context query builder from list #{self.node.class_name}")
end
end
node
end

# Build a Query object from SQLiss.
def build_query(count, pseudo_sql, raw_filters = [])
node = single_node

if !node.klass.respond_to?(:build_query)
raise ::QueryBuilder::Error.new("No query builder for class #{klass}")
raise ::QueryBuilder::Error.new("No query builder for class #{node.klass}")
end

query_opts = {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/zafu_compiler/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,8 @@ count:

query_in_array:
src: "<div do='posts' do='find(\"posts in site\")'/>"
tem: "/Node\.do_find.*Node\.do_find"

query_in_array_without_find:
src: "<div do='posts' do='posts in site'/>"
tem: "/Node\.do_find.*Node\.do_find"
11 changes: 9 additions & 2 deletions test/unit/zena/use/urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ def test_zen_path
assert_equal '/en/projects-list/Clean-Water-project/page22_test.html', zen_path(node, :mode=>'test')
end

# Test is in NodesController (to make sure url parsing works)
# test_zen_path_custom_base_with_accents
def test_zen_path_custom_base_with_accents
# See also test in NodesController
login(:lion)
node = secure!(Node) { nodes(:cleanWater) }
node.update_attributes(:title => 'Lignes aériennes')
assert_equal '/oo/projects-list/Lignes-a%C3%A9riennes', zen_path(node)
# Make sure this is parsed back correctly
assert_match Zena::Use::Urls::ALLOWED_REGEXP, zen_path(node).split('/').last
end

def test_zen_path_query_params
login(:anon)
Expand Down
2 changes: 1 addition & 1 deletion zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2011-03-25}
s.date = %q{2011-03-28}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down

0 comments on commit a064e71

Please sign in to comment.