summaryrefslogtreecommitdiff
path: root/test/unit/page_test.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
committererdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
commit0818a3057b0a91e422158d828026c941b4e10622 (patch)
tree9ed98d52bd577d3f36dd7a1ce8048d280a36062e /test/unit/page_test.rb
parent26030c71c7b300c30367222f263d74b8d2142ecf (diff)
Rails 5.2 test updates
- Rename test/functional → test/controllers, test/unit → test/models - Remove test/performance/browsing_test.rb (performance_test_help removed) - Fix use_transactional_fixtures → use_transactional_tests - Remove use_instantiated_fixtures (removed in Rails 5) - Fix ActiveRecord::Fixtures → FixtureSet - Fix controller test params syntax: add params: {} wrapper throughout - Fix assert_select targets for aggregator test - Fix test_update_a_draft_with_changing_the_template: draft → head - Add test_node.reload after children.create! (awesome_nested_set bug) - Add before/after count pattern for create tests (transactional isolation) - Known failures: 5 tests affected by Rails 5 transactional test isolation
Diffstat (limited to 'test/unit/page_test.rb')
-rw-r--r--test/unit/page_test.rb146
1 files changed, 0 insertions, 146 deletions
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb
deleted file mode 100644
index 401d777..0000000
--- a/test/unit/page_test.rb
+++ /dev/null
@@ -1,146 +0,0 @@
1require 'test_helper'
2
3class PageTest < ActiveSupport::TestCase
4
5 def setup
6 @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
7 @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
8 end
9
10 def test_aggregation
11 # Create two nodes and move them beneath the root node
12 n1 = Node.root.children.create! :slug => "one"
13 n2 = Node.root.children.create! :slug => "two"
14
15 # get the drafts and assign a user to it
16 assert_not_nil d1 = n1.find_or_create_draft( @user1 )
17 assert_not_nil d3 = n2.find_or_create_draft( @user1 )
18
19 # tag and double publish so we have 4 pages tagged with "update"
20 d1.tag_list = "update"
21 d1.save
22 n1.publish_draft!
23
24 d2 = n1.find_or_create_draft @user1
25 n1.publish_draft!
26
27
28 d3.tag_list = "update, pressemitteilung"
29 d3.save
30 n2.publish_draft!
31
32 d4 = n2.find_or_create_draft @user1
33 n2.publish_draft!
34
35 # Set up two options hashes for the assertions
36 options1 = {
37 :tags => "update"
38 }
39
40 options2 = {
41 :tags => "update, pressemitteilung"
42 }
43
44 assert_equal 2, Page.aggregate( options1 ).length
45 assert_equal 1, Page.aggregate( options2 ).length
46 assert_equal 4, Page.find_tagged_with( "update" ).length
47 assert_equal [d2.id, d4.id], Page.aggregate( options1 ).map {|x| x.id}
48 end
49
50 def test_before_save_rewrite_links_in_body
51 n = Node.root.children.create :slug => "link_test"
52 d = n.find_or_create_draft @user1
53
54 before = "<h1>Hello World</h1>\n" \
55 "<a href=\"/club\" target=\"_blank\">Linkme</a>"
56
57 after = "<h1>Hello World</h1>\n" \
58 "<a href=\"/de/club\" target=\"_blank\">Linkme</a>"
59
60 I18n.locale = :de
61
62 d.body = before
63 d.save!
64
65 assert_equal after, d.body
66 end
67
68 def test_before_save_rewrite_links_in_body_if_no_locale_prefix_present
69 n = Node.root.children.create :slug => "link_test"
70 d = n.find_or_create_draft @user1
71
72 before = "<h1>Hello World</h1>\n" \
73 "<a href=\"/de/club\" target=\"_blank\">Linkme</a>"
74
75 after = "<h1>Hello World</h1>\n" \
76 "<a href=\"/de/club\" target=\"_blank\">Linkme</a>"
77
78 I18n.locale = :de
79
80 d.body = before
81 d.save
82
83 assert_equal after, d.body
84 end
85
86 def test_before_save_rewrite_links_skips_on_external_links
87 n = Node.root.children.create :slug => "link_test"
88 d = n.find_or_create_draft @user1
89
90 before = "<h1>Hello World</h1>\n" \
91 "<a href=\"http://www.ccc.de/club\" target=\"_blank\">Linkme</a>"
92
93 after = "<h1>Hello World</h1>\n" \
94 "<a href=\"http://www.ccc.de/club\" target=\"_blank\">Linkme</a>"
95
96 I18n.locale = :de
97
98 d.body = before
99 d.save
100
101 assert_equal after, d.body
102 end
103
104 def test_find_with_outdated_translations
105 Node.delete_all
106 Page.delete_all
107 I18n.locale = :de
108
109 assert_not_nil page = Page.create!( :title => "Hallo" )
110 page.reload
111 assert_equal 1, page.translations.size
112 assert_equal [], Page.find_with_outdated_translations
113
114 I18n.locale = :en
115 page.title = "Hello"
116 page.save
117
118 assert_equal 2, page.translations.size
119 assert_equal 0, Page.find_with_outdated_translations.size
120
121 english = page.translations.select {|x| x.locale == :en}.first
122 Page::Translation.record_timestamps = false
123 english.update_attributes(:updated_at => (Time.now+25.hours))
124 Page::Translation.record_timestamps = true
125 assert_equal 1, Page.find_with_outdated_translations.count
126
127 I18n.locale = :de
128 page2 = Page.create!( :title => "Hallo2" )
129 I18n.locale = :en
130 page2.title = "Hello2"
131 page2.save!
132
133 assert_equal 0, Page.find_with_outdated_translations(:delta_time => 23.days).count
134 assert_equal 1, Page.find_with_outdated_translations(:delta_time => 23.minutes).count
135 assert_equal 2, Page.count
136 end
137
138 test "pages under /updates node get the update template assigned" do
139 Node.root.descendants.delete_all
140 updates = Node.root.children.create!( :slug => "updates" )
141 updates2009 = updates.children.create!( :slug => "2009" )
142 update = updates2009.children.create!( :slug => "my-first-update" )
143 assert_equal "update", update.draft.template_name
144 end
145
146end