Skip to content

Commit

Permalink
Fixed link date update by providing 'link_id' in form.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Apr 6, 2011
1 parent f085739 commit 5151d37
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def find_node
end
else
# bad url
puts "Does not match #{Zena::Use::Urls::ALLOWED_REGEXP}"
#puts "Does not match #{Zena::Use::Urls::ALLOWED_REGEXP}"
raise ActiveRecord::RecordNotFound
end
elsif params[:id]
Expand Down Expand Up @@ -603,7 +603,6 @@ def check_path

if current_url != base_url
# Badly formed url, redirect
puts "(1) #{current_url} != #{base_url}"
redirect_to zen_path(@node, path_params) and return false
end

Expand Down
3 changes: 3 additions & 0 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ def transform_attributes(new_attributes, base_node = nil, change_timezone = true
res["#{key}_id"] = Group.translate_pseudo_id(value, :id) || value
elsif %w{user_id}.include?(key)
res[key] = User.translate_pseudo_id(value, :id) || value
elsif %w{link_id}.include?(key)
# Link id, not translated
res[key] = value
elsif %w{id create_at updated_at}.include?(key)
# ignore (can be present in xml)
elsif %w{log_at event_at v_publish_from}.include?(key) || (is_link && %w{date}.include?(key))
Expand Down
5 changes: 3 additions & 2 deletions app/models/relation_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def attributes_to_update_valid?
elsif link_id = @start.link_id
@other_link = Link.find(link_id)
@attributes_to_update[:id] = @other_link[other_side]
@attributes_to_update[:link_id] = link_id
elsif unique?
if other_id
@attributes_to_update[:id] = other_id
Expand Down Expand Up @@ -309,7 +310,7 @@ def attributes_to_update_valid?
# TODO: this could be optimzed (avoid loading all links...)
other_links.each do |link|
obj_id = link[other_side]
if add_link_ids.include?(obj_id) && (@attributes_to_update[:date].nil? || @attributes_to_update[:date] == link[:date])
if add_link_ids.include?(obj_id) && (@attributes_to_update[:date].nil? || @attributes_to_update[:link_id] || @attributes_to_update[:date] == link[:date])
# ignore existing link
add_link_ids.delete(obj_id)
else
Expand Down Expand Up @@ -337,7 +338,7 @@ def attributes_to_update_valid?
# delete
@del_links = other_links.select {|l| @attributes_to_update[:date] == l[:date]}
else
links = other_links.select {|l| l[other_side] == @attributes_to_update[:id] && (@attributes_to_update[:date].nil? || @attributes_to_update[:date] == l[:date])}
links = other_links.select {|l| l[other_side] == @attributes_to_update[:id] && (@attributes_to_update[:date].nil? || @attributes_to_update[:link_id] || @attributes_to_update[:date] == l[:date])}
if links != []
# update
if (@attributes_to_update.keys & LINK_ATTRIBUTES) != []
Expand Down
5 changes: 3 additions & 2 deletions bricks/zena/zena/migrate/03_zerox1_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def migrate_attachment(version)
atta.save
self.attachment_id = atta.id
else
puts "Missing attachment file for node_id #{version.node_id} (#{version.idx_text_high})"
puts "Missing attachment file for node_id #{version.node_id} (#{version.idx_text_high}): changed to Node"
NodeMig.connection.execute "UPDATE nodes SET kpath = 'N', type = 'Node' WHERE id = #{version.node_id}"
end
end
self.save
Expand Down Expand Up @@ -331,7 +332,7 @@ def self.up
if connection.tables.include?('contact_contents') && ContactContent.first
# Need to migrate data
if $Zerox1SchemaRunning
raise "\n\n=> This is not an error:\n=> Please restart migration: a restart is needed before running Zerox1Data.\n\n"
raise "\n\n=> This is not an error !\n=> Please continue migrations (restart is needed before migrating data)\n=> rake zena:migrate\n\n"
end
else
# Nothing to be done here
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/query_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Compiler < QueryBuilder::Processor
after_process :insert_links_fields
after_process :secure_query

load_custom_queries Bricks.paths_for('queries')
load_custom_queries Bricks.paths_for('zena/queries')

CORE_CONTEXTS = %w{parent project section}

Expand Down
1 change: 0 additions & 1 deletion lib/zena/use/scope_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def update_scope_indices
end

def update_scope_indices_on_destroy
return unless version.status == Zena::Status[:pub]
update_scope_indices_on_prop_change(true)
# How can we handle this ?
# update_scope_indices_on_link_change
Expand Down
33 changes: 33 additions & 0 deletions test/functional/nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,40 @@ class NodesControllerTest < Zena::Controller::TestCase
assert_redirected_to '/foo/bar/baz'
end
end # with a redir param

context 'by changing a link comment' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:opening), :node => {:link_id => links_id(:opening_in_art), :l_comment => 'To be removed'}}
end

should 'update link' do
assert_difference('Link.count', 0) do
assert_difference('Version.count', 0) do
put_subject
end
end
assert_equal 'To be removed', Link.find(links_id(:opening_in_art)).comment
assert_response :redirect
end
end # by changing a link comment


context 'by changing a link date' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:opening), :node => {:link_id => links_id(:opening_in_art), :l_date => '2011-03-29 17:51'}}
end

should 'update link' do
assert_difference('Link.count', 0) do
assert_difference('Version.count', 0) do
put_subject
end
end
assert_equal '2011-03-29 17:51', Link.find(links_id(:opening_in_art)).date.strftime('%Y-%m-%d %H:%M')
assert_response :redirect
end
end # by changing a date

context 'by changing skin' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:people), :node => {:skin_zip => nodes_zip(:wikiSkin), :inherit => 0}}
Expand Down
1 change: 1 addition & 0 deletions test/integration/zafu_compiler/complex_ok.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ it_should_compile_custom_select:
site: complex
ref_date: 2004-09-01
src: "<r:emp_form_dates do='each' join=', '><r:show attr='title'/>(<r:priority/>)</r:emp_form_dates>"
tem: '/var2.attributes\["priority"\]/'
res: 'how to use the winch(10), secure a site(10), dangerous transportations(10), engine maintenance(5), information transmission(5), fiber junction(5), problem formulation(5), how to use the radio(1)'

it_should_group_by_custom_select:
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-28}
s.date = %q{2011-04-06}
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 5151d37

Please sign in to comment.