Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
  • Loading branch information
distler committed Oct 22, 2009
2 parents dc26bbd + 761f8bb commit 3a4f66d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
27 changes: 13 additions & 14 deletions lib/url_generator.rb
Expand Up @@ -98,31 +98,21 @@ def page_link(mode, name, text, web_address, known_page)
end
when :publish
if known_page
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'published',
:id => name, :only_path => true
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
wikilink_for(mode, name, text, web_address)
else
%{<span class="newWikiWord">#{text}</span>}
end
when :show
if known_page
web = Web.find_by_address(web_address)
action = web.published? && web != @web ? 'published' : 'show'
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
:id => name, :only_path => true
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
wikilink_for(mode, name, text, web_address)
else
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
:id => name, :only_path => true
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
end
else
if known_page
web = Web.find_by_address(web_address)
action = web.published? ? 'published' : 'show'
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
:id => name, :only_path => true
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
wikilink_for(mode, name, text, web_address)
else
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new',
:id => name, :only_path => true
Expand Down Expand Up @@ -190,5 +180,14 @@ def delete_link(mode, name, web_address, known_file)
%{<span class="deleteWikiWord">[[#{name}:delete]]</span>}
end
end


private

def wikilink_for(mode, name, text, web_address)
web = Web.find_by_address(web_address)
action = web.published? && !(web == @web && mode != :publish) ? 'published' : 'show'
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action,
:id => name, :only_path => true
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
end
end
4 changes: 2 additions & 2 deletions test/fixtures/revisions.yml
Expand Up @@ -88,6 +88,6 @@ liquor_first_revision:
updated_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
revised_at: <%= 40.minutes.ago.to_formatted_s(:db) %>
page_id: 9
content: "[[!redirects booze]]\n Drinky-poo."
content: "[[!redirects booze]]\n Drinky-poo. [[Instiki:HomePage|go there]]"
author: Guest
ip: 127.0.0.2
ip: 127.0.0.2
46 changes: 46 additions & 0 deletions test/functional/wiki_controller_test.rb
Expand Up @@ -329,6 +329,52 @@ def test_published
assert_response(:success)
assert_equal @home, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/wiki1\/show\/ThatWay'>That Way<\/a>/, r.body

r = process 'save', 'web' => 'instiki', 'id' => 'HomePage', 'content' => 'Contents of a new page',
'author' => 'AuthorOfNewPage'
assert_equal Web.find_by_address('instiki').has_page?('HomePage'), true

r = process('published', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body

r = process('show', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body

Web.find_by_address('instiki').update_attribute(:published, true)

r = process('published', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body

r = process('show', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body

set_web_property :published, false

r = process('show', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/published\/HomePage'>go there<\/a>/, r.body

Web.find_by_address('instiki').update_attribute(:published, false)

r = process('show', 'web' => 'wiki1', 'id' => 'liquor')

assert_response(:success)
assert_equal @liquor, r.template_objects['page']
assert_match /<a class='existingWikiWord' href='\/instiki\/show\/HomePage'>go there<\/a>/, r.body
end


Expand Down

0 comments on commit 3a4f66d

Please sign in to comment.