diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
| commit | 9a19a0494ef51cdac9a78e24d517ca48ba44c453 (patch) | |
| tree | 8eaae12d8047a40e29d3ea7ff3116b5c869e04bd /test/functional | |
| parent | 85a01e35274b8d4d4165a7b26bd7986e211246bb (diff) | |
| parent | 1853082fcd8c067390c246f9daa01a9b47387497 (diff) | |
Migration from Rails 2.3.5 to Rails 8.1 successful.
Merging dev branch.
Diffstat (limited to 'test/functional')
| -rw-r--r-- | test/functional/admin_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/functional/assets_controller_test.rb | 4 | ||||
| -rw-r--r-- | test/functional/content_controller_test.rb | 114 | ||||
| -rw-r--r-- | test/functional/events_controller_test.rb | 45 | ||||
| -rw-r--r-- | test/functional/menu_items_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 350 | ||||
| -rw-r--r-- | test/functional/occurrences_controller_test.rb | 45 | ||||
| -rw-r--r-- | test/functional/pages_controller_test.rb | 5 | ||||
| -rw-r--r-- | test/functional/revisions_controller_test.rb | 61 | ||||
| -rw-r--r-- | test/functional/rss_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/functional/search_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/functional/sessions_controller_test.rb | 32 | ||||
| -rw-r--r-- | test/functional/tags_controller_test.rb | 8 | ||||
| -rw-r--r-- | test/functional/users_controller_test.rb | 180 |
14 files changed, 0 insertions, 876 deletions
diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb deleted file mode 100644 index 9bbf29b..0000000 --- a/test/functional/admin_controller_test.rb +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class AdminControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/functional/assets_controller_test.rb b/test/functional/assets_controller_test.rb deleted file mode 100644 index d003d25..0000000 --- a/test/functional/assets_controller_test.rb +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class AssetsControllerTest < ActionController::TestCase | ||
| 4 | end | ||
diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb deleted file mode 100644 index 4fb3035..0000000 --- a/test/functional/content_controller_test.rb +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class ContentControllerTest < ActionController::TestCase | ||
| 4 | |||
| 5 | def setup | ||
| 6 | @root = Node.find(1) | ||
| 7 | @first_child = Node.find(2) | ||
| 8 | @second_child = Node.find(3) | ||
| 9 | |||
| 10 | @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | ||
| 11 | @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' | ||
| 12 | end | ||
| 13 | |||
| 14 | def test_custom_page_route | ||
| 15 | assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'de', :page_path => ['foo', 'bar'] }, '/de/foo/bar') | ||
| 16 | assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'en', :page_path => ['home'] }, '/en/home') | ||
| 17 | end | ||
| 18 | |||
| 19 | def test_render_404_when_no_page_was_found | ||
| 20 | get :render_page, :language => 'de', :page_path => ["wrong_path"] | ||
| 21 | assert_response 404 | ||
| 22 | end | ||
| 23 | |||
| 24 | def test_rendering_a_page | ||
| 25 | assert Node.valid? | ||
| 26 | assert_not_nil first_child = Node.find_by_slug("first_child") | ||
| 27 | page = first_child.pages.create :title => "First Child" | ||
| 28 | first_child.head = page | ||
| 29 | first_child.save! | ||
| 30 | |||
| 31 | get :render_page, :language => 'de', :page_path => ["first_child"] | ||
| 32 | assert_response :success | ||
| 33 | assert_equal "layouts/application", @response.layout | ||
| 34 | end | ||
| 35 | |||
| 36 | def test_page_containing_aggregator | ||
| 37 | assert_not_nil Node.root | ||
| 38 | |||
| 39 | fill_pages_with_content | ||
| 40 | |||
| 41 | new_node = create_node_under_root "fnord" | ||
| 42 | draft = new_node.find_or_create_draft @user1 | ||
| 43 | draft.body = '<aggregate tags="update" limit="20" />' | ||
| 44 | draft.save | ||
| 45 | new_node.publish_draft! | ||
| 46 | |||
| 47 | get :render_page, :locale => 'de', :page_path => ["fnord"] | ||
| 48 | assert_response :success | ||
| 49 | |||
| 50 | assert_select("h2", "one") | ||
| 51 | assert_select("h2", "two") | ||
| 52 | end | ||
| 53 | |||
| 54 | def test_page_containing_aggregator_with_custom_template | ||
| 55 | fill_pages_with_content | ||
| 56 | |||
| 57 | new_node = create_node_under_root "fnord" | ||
| 58 | draft = new_node.find_or_create_draft @user1 | ||
| 59 | draft.body = '<aggregate tags="update" limit="20" partial="sidebar_title_only" />' | ||
| 60 | draft.save | ||
| 61 | new_node.publish_draft! | ||
| 62 | |||
| 63 | get :render_page, :locale => 'de', :page_path => ["fnord"] | ||
| 64 | assert_response :success | ||
| 65 | |||
| 66 | assert_select(".sidebar_headline", "one") | ||
| 67 | assert_select(".sidebar_headline", "two") | ||
| 68 | end | ||
| 69 | |||
| 70 | def test_nonexistant_custom_template_defaults_to_standard_template | ||
| 71 | new_node = create_node_under_root "fnord" | ||
| 72 | draft = new_node.find_or_create_draft @user1 | ||
| 73 | draft.template_name = "huchibu" | ||
| 74 | draft.save | ||
| 75 | new_node.publish_draft! | ||
| 76 | |||
| 77 | get :render_page, :locale => 'de', :page_path => ["fnord"] | ||
| 78 | assert_response :success | ||
| 79 | assert_template "custom/page_templates/public/standard_template.html.erb" | ||
| 80 | end | ||
| 81 | |||
| 82 | def test_custom_template_no_date_and_author | ||
| 83 | new_node = create_node_under_root "fnord" | ||
| 84 | draft = new_node.find_or_create_draft @user1 | ||
| 85 | draft.template_name = "no_date_and_author" | ||
| 86 | draft.save | ||
| 87 | new_node.publish_draft! | ||
| 88 | |||
| 89 | get :render_page, :locale => 'de', :page_path => ["fnord"] | ||
| 90 | assert_response :success | ||
| 91 | assert_template "custom/page_templates/public/no_date_and_author.html.erb" | ||
| 92 | end | ||
| 93 | |||
| 94 | protected | ||
| 95 | |||
| 96 | def create_node_under_root slug | ||
| 97 | node = Node.root.children.create! :slug => slug | ||
| 98 | node | ||
| 99 | end | ||
| 100 | |||
| 101 | def fill_pages_with_content | ||
| 102 | d1 = @first_child.find_or_create_draft @user1 | ||
| 103 | d1.title = "one" | ||
| 104 | d1.tag_list = "update" | ||
| 105 | d1.save | ||
| 106 | @first_child.publish_draft! | ||
| 107 | |||
| 108 | d2 = @second_child.find_or_create_draft @user1 | ||
| 109 | d2.title = "two" | ||
| 110 | d2.tag_list = "update" | ||
| 111 | d2.save | ||
| 112 | @second_child.publish_draft! | ||
| 113 | end | ||
| 114 | end | ||
diff --git a/test/functional/events_controller_test.rb b/test/functional/events_controller_test.rb deleted file mode 100644 index 5698c7b..0000000 --- a/test/functional/events_controller_test.rb +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class EventsControllerTest < ActionController::TestCase | ||
| 4 | # test "should get index" do | ||
| 5 | # get :index | ||
| 6 | # assert_response :success | ||
| 7 | # assert_not_nil assigns(:events) | ||
| 8 | # end | ||
| 9 | # | ||
| 10 | # test "should get new" do | ||
| 11 | # get :new | ||
| 12 | # assert_response :success | ||
| 13 | # end | ||
| 14 | # | ||
| 15 | # test "should create event" do | ||
| 16 | # assert_difference('Event.count') do | ||
| 17 | # post :create, :event => { } | ||
| 18 | # end | ||
| 19 | # | ||
| 20 | # assert_redirected_to event_path(assigns(:event)) | ||
| 21 | # end | ||
| 22 | # | ||
| 23 | # test "should show event" do | ||
| 24 | # get :show, :id => events(:one).to_param | ||
| 25 | # assert_response :success | ||
| 26 | # end | ||
| 27 | # | ||
| 28 | # test "should get edit" do | ||
| 29 | # get :edit, :id => events(:one).to_param | ||
| 30 | # assert_response :success | ||
| 31 | # end | ||
| 32 | # | ||
| 33 | # test "should update event" do | ||
| 34 | # put :update, :id => events(:one).to_param, :event => { } | ||
| 35 | # assert_redirected_to event_path(assigns(:event)) | ||
| 36 | # end | ||
| 37 | # | ||
| 38 | # test "should destroy event" do | ||
| 39 | # assert_difference('Event.count', -1) do | ||
| 40 | # delete :destroy, :id => events(:one).to_param | ||
| 41 | # end | ||
| 42 | # | ||
| 43 | # assert_redirected_to events_path | ||
| 44 | # end | ||
| 45 | end | ||
diff --git a/test/functional/menu_items_controller_test.rb b/test/functional/menu_items_controller_test.rb deleted file mode 100644 index c47467a..0000000 --- a/test/functional/menu_items_controller_test.rb +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class MenuItemsControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb deleted file mode 100644 index 113697a..0000000 --- a/test/functional/nodes_controller_test.rb +++ /dev/null | |||
| @@ -1,350 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class NodesControllerTest < ActionController::TestCase | ||
| 4 | |||
| 5 | def test_get_index | ||
| 6 | Node.root.descendants.delete_all | ||
| 7 | test_node = Node.root.children.create :slug => "foo" | ||
| 8 | login_as :quentin | ||
| 9 | get :index | ||
| 10 | assert_response :success | ||
| 11 | end | ||
| 12 | |||
| 13 | def test_new | ||
| 14 | login_as :quentin | ||
| 15 | get :new | ||
| 16 | assert_response :success | ||
| 17 | end | ||
| 18 | |||
| 19 | test "create generic node with parent_id provided" do | ||
| 20 | login_as :quentin | ||
| 21 | assert_difference "Node.count", +1 do | ||
| 22 | post( | ||
| 23 | :create, | ||
| 24 | :kind => "generic", | ||
| 25 | :parent_id => Node.root.id, | ||
| 26 | :title => "Hello Spaceboy" | ||
| 27 | ) | ||
| 28 | end | ||
| 29 | |||
| 30 | assert_response :redirect | ||
| 31 | assert_equal "hello-spaceboy", Node.last.slug | ||
| 32 | assert_equal Node.last.parent_id, Node.root.id | ||
| 33 | assert_equal 1, Node.last.level | ||
| 34 | end | ||
| 35 | |||
| 36 | test "create update node" do | ||
| 37 | login_as :quentin | ||
| 38 | #difference of three because "updates" and "2009" node get created as well | ||
| 39 | assert_difference "Node.count", +3 do | ||
| 40 | post( | ||
| 41 | :create, | ||
| 42 | :kind => "update", | ||
| 43 | :title => "Hello Spaceboy" | ||
| 44 | ) | ||
| 45 | end | ||
| 46 | |||
| 47 | assert_response :redirect | ||
| 48 | expected = "updates/#{Time.now.year.to_s}/hello-spaceboy" | ||
| 49 | assert_equal expected, Node.last.unique_name | ||
| 50 | assert_equal 3, Node.last.level | ||
| 51 | end | ||
| 52 | |||
| 53 | test "create top level node" do | ||
| 54 | login_as :quentin | ||
| 55 | |||
| 56 | assert_difference "Node.count", +1 do | ||
| 57 | post( | ||
| 58 | :create, | ||
| 59 | :kind => "top_level", | ||
| 60 | :title => "Hello My Spaceboy" | ||
| 61 | ) | ||
| 62 | end | ||
| 63 | |||
| 64 | assert_response :redirect | ||
| 65 | expected = "hello-my-spaceboy" | ||
| 66 | assert_equal expected, Node.last.unique_name | ||
| 67 | assert_equal 1, Node.last.level | ||
| 68 | end | ||
| 69 | |||
| 70 | test "creating a top_level node without a title should not work" do | ||
| 71 | login_as :quentin | ||
| 72 | |||
| 73 | assert_no_difference "Node.count" do | ||
| 74 | post(:create, :kind => "top_level") | ||
| 75 | end | ||
| 76 | end | ||
| 77 | |||
| 78 | test "creating a generic node without a parent_id should not work" do | ||
| 79 | login_as :quentin | ||
| 80 | |||
| 81 | assert_no_difference "Node.count" do | ||
| 82 | post(:create, :kind => "generic") | ||
| 83 | end | ||
| 84 | end | ||
| 85 | |||
| 86 | test "editing a node" do | ||
| 87 | login_as :quentin | ||
| 88 | |||
| 89 | node = Node.find_by_unique_name("fourth_child") | ||
| 90 | node.pages.create | ||
| 91 | node.draft = node.pages.last | ||
| 92 | node.save | ||
| 93 | |||
| 94 | assert_equal 1, node.pages.length | ||
| 95 | |||
| 96 | draft = node.find_or_create_draft( User.first ) | ||
| 97 | draft.title = "Hello" | ||
| 98 | draft.body = "World" | ||
| 99 | draft.save | ||
| 100 | node.publish_draft! | ||
| 101 | |||
| 102 | get :edit, :id => node.id | ||
| 103 | assert_response :success | ||
| 104 | assert_select("#page_title[value=Hello]") | ||
| 105 | assert_select("#page_body", "World") | ||
| 106 | |||
| 107 | node.reload | ||
| 108 | assert_equal 2, node.pages.length | ||
| 109 | assert_equal "Hello", node.find_or_create_draft( User.first ).title | ||
| 110 | assert_equal "World", node.find_or_create_draft( User.first ).body | ||
| 111 | end | ||
| 112 | |||
| 113 | test "editing a locked node raises LockedByAnotherUser Exception" do | ||
| 114 | login_as :quentin | ||
| 115 | |||
| 116 | node = create_node_with_draft | ||
| 117 | node.lock_owner = User.last | ||
| 118 | node.save | ||
| 119 | |||
| 120 | assert node.locked? | ||
| 121 | |||
| 122 | get :edit, :id => node.id | ||
| 123 | assert_response :redirect | ||
| 124 | assert @response.flash[:error] =~ /Page is locked by another user/ | ||
| 125 | end | ||
| 126 | |||
| 127 | def test_update_a_draft | ||
| 128 | test_node = Node.root.children.create! :slug => "test_node" | ||
| 129 | |||
| 130 | login_as :quentin | ||
| 131 | put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"} | ||
| 132 | |||
| 133 | assert_equal "Hello", test_node.draft.title | ||
| 134 | assert_equal "There", test_node.draft.body | ||
| 135 | end | ||
| 136 | |||
| 137 | def test_update_a_draft_with_changing_the_template | ||
| 138 | test_node = Node.root.children.create! :slug => "test_node" | ||
| 139 | |||
| 140 | login_as :quentin | ||
| 141 | put :update, { | ||
| 142 | :id => test_node.id, | ||
| 143 | :page => { | ||
| 144 | :title => "Hello", | ||
| 145 | :body => "There", | ||
| 146 | :template_name => "Foobar" | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | test_node.reload | ||
| 151 | assert_equal "Hello", test_node.draft.title | ||
| 152 | assert_equal "There", test_node.draft.body | ||
| 153 | assert_equal "Foobar", test_node.draft.template_name | ||
| 154 | end | ||
| 155 | |||
| 156 | |||
| 157 | test "publish draft with staged_slug unqueal slug" do | ||
| 158 | login_as :quentin | ||
| 159 | |||
| 160 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" | ||
| 161 | |||
| 162 | put :publish, :id => test_node.id | ||
| 163 | |||
| 164 | test_node.reload | ||
| 165 | assert_equal "peter_pan", test_node.slug | ||
| 166 | assert_equal "peter_pan", test_node.unique_name | ||
| 167 | end | ||
| 168 | |||
| 169 | test "publish draft with staged_slug with more levels of nodes" do | ||
| 170 | login_as :quentin | ||
| 171 | |||
| 172 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" | ||
| 173 | test_node2 = test_node.children.create! :slug => "test_node2" | ||
| 174 | |||
| 175 | put :publish, :id => test_node.id | ||
| 176 | |||
| 177 | test_node.reload; test_node2.reload | ||
| 178 | assert_equal "peter_pan/test_node2", test_node2.unique_name | ||
| 179 | assert_equal "peter_pan", test_node.unique_name | ||
| 180 | end | ||
| 181 | |||
| 182 | test "publish draft with staged_parent_id" do | ||
| 183 | login_as :quentin | ||
| 184 | |||
| 185 | parent = Node.root.children.create! :slug => "parent" | ||
| 186 | test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id | ||
| 187 | test_node2 = test_node.children.create! :slug => "test_node2" | ||
| 188 | |||
| 189 | put :publish, :id => test_node.id | ||
| 190 | |||
| 191 | test_node.reload; test_node2.reload | ||
| 192 | assert_equal "parent/test_node", test_node.unique_name | ||
| 193 | assert_equal "parent/test_node/test_node2", test_node2.unique_name | ||
| 194 | end | ||
| 195 | |||
| 196 | test "publish draft with staged_parent_id and staged_slug" do | ||
| 197 | login_as :quentin | ||
| 198 | |||
| 199 | parent = Node.root.children.create! :slug => "parent" | ||
| 200 | |||
| 201 | test_node = Node.root.children.create!( | ||
| 202 | :slug => "test_node", | ||
| 203 | :staged_parent_id => parent.id, | ||
| 204 | :staged_slug => "peter_pan" | ||
| 205 | ) | ||
| 206 | |||
| 207 | test_node2 = test_node.children.create! :slug => "test_node2" | ||
| 208 | |||
| 209 | put :publish, :id => test_node.id | ||
| 210 | |||
| 211 | test_node.reload; test_node2.reload | ||
| 212 | assert_equal "parent/peter_pan", test_node.unique_name | ||
| 213 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name | ||
| 214 | end | ||
| 215 | |||
| 216 | test "show node with empty draft" do | ||
| 217 | login_as :quentin | ||
| 218 | assert_not_nil node = create_node_with_draft | ||
| 219 | get :show, :id => node.id | ||
| 220 | assert_response :success | ||
| 221 | end | ||
| 222 | |||
| 223 | test "show node with published draft" do | ||
| 224 | login_as :quentin | ||
| 225 | node = create_node_with_published_page | ||
| 226 | get :show, :id => node.id | ||
| 227 | assert_response :success | ||
| 228 | assert_select "td", :text => "Test", :count => 3 | ||
| 229 | end | ||
| 230 | |||
| 231 | test "unlocking a locked node" do | ||
| 232 | login_as :quentin | ||
| 233 | node = create_node_with_published_page | ||
| 234 | node.find_or_create_draft User.first | ||
| 235 | |||
| 236 | assert node.locked? | ||
| 237 | |||
| 238 | get :unlock, :id => node.id | ||
| 239 | assert_response :redirect | ||
| 240 | assert !node.reload.locked? | ||
| 241 | end | ||
| 242 | |||
| 243 | test "unlocking an already unlocked node" do | ||
| 244 | login_as :quentin | ||
| 245 | node = create_node_with_published_page | ||
| 246 | |||
| 247 | get :unlock, :id => node.id | ||
| 248 | assert_response :redirect | ||
| 249 | assert_equal "Already unlocked", @response.flash[:notice] | ||
| 250 | end | ||
| 251 | |||
| 252 | test "updating a node by changing its parent" do | ||
| 253 | Node.root.descendants.destroy_all | ||
| 254 | login_as :quentin | ||
| 255 | node = create_node_with_published_page | ||
| 256 | node.find_or_create_draft User.first | ||
| 257 | |||
| 258 | other_node = Node.root.children.create( :slug => "other" ) | ||
| 259 | |||
| 260 | node.staged_parent_id = other_node.id | ||
| 261 | node.publish_draft! | ||
| 262 | |||
| 263 | assert Node.valid? | ||
| 264 | end | ||
| 265 | |||
| 266 | test "editing the initial draft sets the author to current_user" do | ||
| 267 | login_as :quentin | ||
| 268 | Node.root.descendants.destroy_all | ||
| 269 | node = create_node_with_draft | ||
| 270 | get :edit, :id => node.id | ||
| 271 | assert_equal "quentin", node.draft.user.login | ||
| 272 | end | ||
| 273 | |||
| 274 | test "updating the author of a node with existing head" do | ||
| 275 | login_as :quentin | ||
| 276 | Node.root.descendants.destroy_all | ||
| 277 | node = create_node_with_published_page | ||
| 278 | assert_equal "quentin", node.head.user.login | ||
| 279 | node.find_or_create_draft users(:quentin) | ||
| 280 | assert node.draft.valid? | ||
| 281 | assert node.valid? | ||
| 282 | |||
| 283 | put :update, :id => node.id, :page => {:user_id => users(:aaron).id} | ||
| 284 | assert_response :redirect | ||
| 285 | assert_equal "aaron", node.reload.draft.user.login | ||
| 286 | end | ||
| 287 | |||
| 288 | test "updating an existing page should not modify published_at" do | ||
| 289 | login_as :quentin | ||
| 290 | Node.root.descendants.destroy_all | ||
| 291 | node = create_node_with_published_page | ||
| 292 | |||
| 293 | get :edit, :id => node.id | ||
| 294 | assert_response :success | ||
| 295 | |||
| 296 | put :publish, :id => node.id | ||
| 297 | |||
| 298 | node.reload | ||
| 299 | assert_equal node.pages[0].published_at, node.pages[1].published_at | ||
| 300 | end | ||
| 301 | |||
| 302 | test "updating an exisiting page should not alter the author" do | ||
| 303 | login_as :aaron | ||
| 304 | Node.root.descendants.destroy_all | ||
| 305 | node = create_node_with_published_page | ||
| 306 | get :edit, :id => node.id | ||
| 307 | |||
| 308 | put :publish, :id => node.id | ||
| 309 | |||
| 310 | node.reload | ||
| 311 | assert_equal node.pages[0].user, node.pages[1].user | ||
| 312 | end | ||
| 313 | |||
| 314 | test "editor and author are the same on a new node" do | ||
| 315 | login_as :quentin | ||
| 316 | node = create_node_with_draft | ||
| 317 | get :edit, :id => node.id | ||
| 318 | |||
| 319 | node.reload | ||
| 320 | assert_equal "quentin", node.draft.user.login | ||
| 321 | assert_equal "quentin", node.draft.editor.login | ||
| 322 | end | ||
| 323 | |||
| 324 | test "creating new draft alters the editor but keeps the author" do | ||
| 325 | node = create_node_with_published_page | ||
| 326 | assert_equal "quentin", node.head.user.login | ||
| 327 | |||
| 328 | login_as :aaron | ||
| 329 | get :edit, :id => node.id | ||
| 330 | |||
| 331 | node.reload | ||
| 332 | assert_equal "quentin", node.head.user.login | ||
| 333 | assert_equal "aaron", node.draft.editor.login | ||
| 334 | end | ||
| 335 | |||
| 336 | test "unlocking and relocking changes editor if done by another user" do | ||
| 337 | node = create_node_with_published_page | ||
| 338 | draft = node.find_or_create_draft users(:quentin) | ||
| 339 | assert_equal draft.user.login, draft.editor.login | ||
| 340 | assert node.locked? | ||
| 341 | node.unlock! | ||
| 342 | |||
| 343 | login_as :aaron | ||
| 344 | get :edit, :id => node.id | ||
| 345 | |||
| 346 | node.reload | ||
| 347 | assert_equal "quentin", node.draft.user.login | ||
| 348 | assert_equal "aaron", node.draft.editor.login | ||
| 349 | end | ||
| 350 | end | ||
diff --git a/test/functional/occurrences_controller_test.rb b/test/functional/occurrences_controller_test.rb deleted file mode 100644 index 0b00e0e..0000000 --- a/test/functional/occurrences_controller_test.rb +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class OccurrencesControllerTest < ActionController::TestCase | ||
| 4 | # test "should get index" do | ||
| 5 | # get :index | ||
| 6 | # assert_response :success | ||
| 7 | # assert_not_nil assigns(:occurrences) | ||
| 8 | # end | ||
| 9 | # | ||
| 10 | # test "should get new" do | ||
| 11 | # get :new | ||
| 12 | # assert_response :success | ||
| 13 | # end | ||
| 14 | # | ||
| 15 | # test "should create occurrence" do | ||
| 16 | # assert_difference('Occurrence.count') do | ||
| 17 | # post :create, :occurrence => { } | ||
| 18 | # end | ||
| 19 | # | ||
| 20 | # assert_redirected_to occurrence_path(assigns(:occurrence)) | ||
| 21 | # end | ||
| 22 | # | ||
| 23 | # test "should show occurrence" do | ||
| 24 | # get :show, :id => occurrences(:one).to_param | ||
| 25 | # assert_response :success | ||
| 26 | # end | ||
| 27 | # | ||
| 28 | # test "should get edit" do | ||
| 29 | # get :edit, :id => occurrences(:one).to_param | ||
| 30 | # assert_response :success | ||
| 31 | # end | ||
| 32 | # | ||
| 33 | # test "should update occurrence" do | ||
| 34 | # put :update, :id => occurrences(:one).to_param, :occurrence => { } | ||
| 35 | # assert_redirected_to occurrence_path(assigns(:occurrence)) | ||
| 36 | # end | ||
| 37 | # | ||
| 38 | # test "should destroy occurrence" do | ||
| 39 | # assert_difference('Occurrence.count', -1) do | ||
| 40 | # delete :destroy, :id => occurrences(:one).to_param | ||
| 41 | # end | ||
| 42 | # | ||
| 43 | # assert_redirected_to occurrences_path | ||
| 44 | # end | ||
| 45 | end | ||
diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb deleted file mode 100644 index 3879014..0000000 --- a/test/functional/pages_controller_test.rb +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class PagesControllerTest < ActionController::TestCase | ||
| 4 | # will be removed anyway | ||
| 5 | end | ||
diff --git a/test/functional/revisions_controller_test.rb b/test/functional/revisions_controller_test.rb deleted file mode 100644 index 43001df..0000000 --- a/test/functional/revisions_controller_test.rb +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class RevisionsControllerTest < ActionController::TestCase | ||
| 4 | |||
| 5 | def setup | ||
| 6 | Node.root.descendants.destroy_all | ||
| 7 | @user = User.find_by_login("aaron") | ||
| 8 | @node = Node.root.children.create!( :slug => "version_me" ) | ||
| 9 | |||
| 10 | draft = @node.draft | ||
| 11 | draft.body = "first" | ||
| 12 | @node.publish_draft! | ||
| 13 | @node.find_or_create_draft @user | ||
| 14 | draft = @node.draft | ||
| 15 | draft.update_attributes(:body => "second") | ||
| 16 | @node.publish_draft! | ||
| 17 | end | ||
| 18 | |||
| 19 | test "setup" do | ||
| 20 | assert_equal 2, Node.count | ||
| 21 | assert_equal 2, @node.pages.count | ||
| 22 | assert_equal ["first", "second"], @node.pages.map {|p| p.body} | ||
| 23 | end | ||
| 24 | |||
| 25 | test "get list of revisions for a given node" do | ||
| 26 | login_as :quentin | ||
| 27 | get :index, :node_id => @node.id | ||
| 28 | assert_response :success | ||
| 29 | assert_select ".revision", 2 | ||
| 30 | end | ||
| 31 | |||
| 32 | test "showing one revision" do | ||
| 33 | login_as :quentin | ||
| 34 | get :show, :node_id => @node.id, :id => @node.pages.last.id | ||
| 35 | assert_response :success | ||
| 36 | assert_select "strong", "Body" | ||
| 37 | assert_select "td", {:count => 1, :text => "second"} | ||
| 38 | end | ||
| 39 | |||
| 40 | test "diffing two revisions" do | ||
| 41 | login_as :quentin | ||
| 42 | post( | ||
| 43 | :diff, | ||
| 44 | :node_id => @node.id, | ||
| 45 | :start_revision => @node.pages.first.revision, | ||
| 46 | :end_revision => @node.pages.last.revision | ||
| 47 | ) | ||
| 48 | assert_response :success | ||
| 49 | end | ||
| 50 | |||
| 51 | test "restoring a revision" do | ||
| 52 | assert_equal "second", @node.head.body | ||
| 53 | |||
| 54 | login_as :aaron | ||
| 55 | put( :restore, :node_id => @node.id, :id => @node.pages.first.id ) | ||
| 56 | |||
| 57 | @node.reload | ||
| 58 | assert_equal @node.head, @node.pages.first | ||
| 59 | assert_equal "first", @node.head.reload.body | ||
| 60 | end | ||
| 61 | end | ||
diff --git a/test/functional/rss_controller_test.rb b/test/functional/rss_controller_test.rb deleted file mode 100644 index 161dbd7..0000000 --- a/test/functional/rss_controller_test.rb +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class RssControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb deleted file mode 100644 index 49bb14f..0000000 --- a/test/functional/search_controller_test.rb +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class SearchControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb deleted file mode 100644 index 6baff5c..0000000 --- a/test/functional/sessions_controller_test.rb +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | require 'sessions_controller' | ||
| 3 | |||
| 4 | # Re-raise errors caught by the controller. | ||
| 5 | class SessionsController; def rescue_action(e) raise e end; end | ||
| 6 | |||
| 7 | class SessionsControllerTest < ActionController::TestCase | ||
| 8 | # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead | ||
| 9 | # Then, you can remove it from this and the units test. | ||
| 10 | include AuthenticatedTestHelper | ||
| 11 | |||
| 12 | fixtures :users | ||
| 13 | |||
| 14 | def test_should_login_and_redirect | ||
| 15 | post :create, :login => 'quentin', :password => 'monkey' | ||
| 16 | assert session[:user_id] | ||
| 17 | assert_response :redirect | ||
| 18 | end | ||
| 19 | |||
| 20 | def test_should_fail_login_and_not_redirect | ||
| 21 | post :create, :login => 'quentin', :password => 'bad password' | ||
| 22 | assert_nil session[:user_id] | ||
| 23 | assert_response :success | ||
| 24 | end | ||
| 25 | |||
| 26 | def test_should_logout | ||
| 27 | login_as :quentin | ||
| 28 | get :destroy | ||
| 29 | assert_nil session[:user_id] | ||
| 30 | assert_response :redirect | ||
| 31 | end | ||
| 32 | end | ||
diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb deleted file mode 100644 index dcf6b7e..0000000 --- a/test/functional/tags_controller_test.rb +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class TagsControllerTest < ActionController::TestCase | ||
| 4 | # Replace this with your real tests. | ||
| 5 | test "the truth" do | ||
| 6 | assert true | ||
| 7 | end | ||
| 8 | end | ||
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb deleted file mode 100644 index 89c6dc2..0000000 --- a/test/functional/users_controller_test.rb +++ /dev/null | |||
| @@ -1,180 +0,0 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class UsersControllerTest < ActionController::TestCase | ||
| 4 | |||
| 5 | test "get index as regular user renders stripped partial" do | ||
| 6 | login_as :quentin | ||
| 7 | get :index | ||
| 8 | assert_response :success | ||
| 9 | assert_select "a", { :count => 0, :text => "Destroy" } | ||
| 10 | end | ||
| 11 | |||
| 12 | test "get index as admin user renders admin partial" do | ||
| 13 | login_as :aaron | ||
| 14 | get :index | ||
| 15 | assert_response :success | ||
| 16 | assert_select "a", "destroy" | ||
| 17 | assert_select "a", "show", "Show Link is missing" | ||
| 18 | end | ||
| 19 | |||
| 20 | test "get new when logged in as admin" do | ||
| 21 | login_as :aaron | ||
| 22 | get :new | ||
| 23 | assert_response :success | ||
| 24 | end | ||
| 25 | |||
| 26 | test "get new without being logged in as admin redirects back to index" do | ||
| 27 | login_as :quentin | ||
| 28 | get :new | ||
| 29 | assert_response :redirect | ||
| 30 | assert_redirected_to users_path | ||
| 31 | assert_equal( | ||
| 32 | "Sorry, you need to be an admin for this action", | ||
| 33 | @response.flash[:notice] | ||
| 34 | ) | ||
| 35 | end | ||
| 36 | |||
| 37 | test "creating new users being logged in as admin" do | ||
| 38 | login_as :aaron | ||
| 39 | assert_difference "User.count", +1 do | ||
| 40 | post :create, :user => { | ||
| 41 | :login => "peter", | ||
| 42 | :email => "foo@bar.com", | ||
| 43 | :password => "xxxzzz", | ||
| 44 | :password_confirmation => "xxxzzz" | ||
| 45 | } | ||
| 46 | end | ||
| 47 | |||
| 48 | assert_redirected_to user_path(User.last) | ||
| 49 | assert !User.last.admin | ||
| 50 | end | ||
| 51 | |||
| 52 | test "creating new admin users being logged in as admin" do | ||
| 53 | login_as :aaron | ||
| 54 | assert_difference "User.count", +1 do | ||
| 55 | post :create, :user => { | ||
| 56 | :login => "peter", | ||
| 57 | :email => "foo@bar.com", | ||
| 58 | :password => "xxxzzz", | ||
| 59 | :password_confirmation => "xxxzzz", | ||
| 60 | :admin => true | ||
| 61 | } | ||
| 62 | end | ||
| 63 | |||
| 64 | assert_redirected_to user_path(User.last) | ||
| 65 | assert User.last.admin | ||
| 66 | end | ||
| 67 | |||
| 68 | test "creating new users not being logged as regular user wont work" do | ||
| 69 | login_as :quentin | ||
| 70 | assert_no_difference "User.count" do | ||
| 71 | post :create, :user => { | ||
| 72 | :login => "peter", | ||
| 73 | :email => "foo@bar.com", | ||
| 74 | :password => "xxxzzz", | ||
| 75 | :password_confirmation => "xxxzzz" | ||
| 76 | } | ||
| 77 | end | ||
| 78 | |||
| 79 | assert_redirected_to users_path | ||
| 80 | assert_equal( | ||
| 81 | "Sorry, you need to be an admin for this action", | ||
| 82 | @response.flash[:notice] | ||
| 83 | ) | ||
| 84 | end | ||
| 85 | |||
| 86 | test "get edit of another user being logged in as regular user wont work" do | ||
| 87 | login_as :quentin | ||
| 88 | get :edit, :id => User.find_by_login("aaron").id | ||
| 89 | assert_redirected_to users_path | ||
| 90 | assert_equal( | ||
| 91 | "Sorry, you need to be an admin for this action", | ||
| 92 | @response.flash[:notice] | ||
| 93 | ) | ||
| 94 | end | ||
| 95 | |||
| 96 | test "get edit of another user being logged in as admin user" do | ||
| 97 | login_as :aaron | ||
| 98 | get :edit, :id => User.find_by_login("quentin").id | ||
| 99 | assert_response :success | ||
| 100 | end | ||
| 101 | |||
| 102 | test "editing own user details is allowed" do | ||
| 103 | login_as :quentin | ||
| 104 | get :edit, :id => User.find_by_login("quentin").id | ||
| 105 | assert_response :success | ||
| 106 | end | ||
| 107 | |||
| 108 | test "updating an user when being logged in as regular user wont work" do | ||
| 109 | user = User.find_by_login("aaron") | ||
| 110 | login_as :quentin | ||
| 111 | put :update, :id => user.id, :user => {:login => "random"} | ||
| 112 | assert_redirected_to users_path | ||
| 113 | assert_equal( | ||
| 114 | "Sorry, you need to be an admin for this action", | ||
| 115 | @response.flash[:notice] | ||
| 116 | ) | ||
| 117 | end | ||
| 118 | |||
| 119 | test "updating an user when being login in as admin user" do | ||
| 120 | user = User.find_by_login("quentin") | ||
| 121 | login_as :aaron | ||
| 122 | put :update, :id => user.id, :user => {:login => "random"} | ||
| 123 | assert_redirected_to user_path(user) | ||
| 124 | assert_equal "random", user.reload.login | ||
| 125 | end | ||
| 126 | |||
| 127 | test "updating own user details is allowd" do | ||
| 128 | user = User.find_by_login("quentin") | ||
| 129 | login_as :quentin | ||
| 130 | put :update, :id => user.id, :user => {:login => "random"} | ||
| 131 | assert_redirected_to user_path(user) | ||
| 132 | assert_equal "random", user.reload.login | ||
| 133 | end | ||
| 134 | |||
| 135 | test "showing a user" do | ||
| 136 | login_as :quentin | ||
| 137 | get :show, :id => User.find_by_login("aaron").id | ||
| 138 | assert_response :success | ||
| 139 | end | ||
| 140 | |||
| 141 | test "destroying an user being logged in as regular user wont work" do | ||
| 142 | login_as :quentin | ||
| 143 | assert_no_difference "User.count" do | ||
| 144 | delete :destroy, :id => User.find_by_login("aaron").id | ||
| 145 | end | ||
| 146 | assert_redirected_to users_path | ||
| 147 | assert_equal( | ||
| 148 | "Sorry, you need to be an admin for this action", | ||
| 149 | @response.flash[:notice] | ||
| 150 | ) | ||
| 151 | end | ||
| 152 | |||
| 153 | test "destroying an user being logged in as admin user" do | ||
| 154 | login_as :aaron | ||
| 155 | assert_difference "User.count", -1 do | ||
| 156 | delete :destroy, :id => User.find_by_login("quentin").id | ||
| 157 | end | ||
| 158 | assert_redirected_to users_path | ||
| 159 | end | ||
| 160 | |||
| 161 | test "admin user can promote regular users to admins" do | ||
| 162 | login_as :aaron | ||
| 163 | user = users(:quentin) | ||
| 164 | put :update, :id => user.id, :user => {:admin => true} | ||
| 165 | |||
| 166 | user.reload | ||
| 167 | assert_equal true, user.is_admin? | ||
| 168 | end | ||
| 169 | |||
| 170 | test "regular users cannot promote themselves to admins" do | ||
| 171 | login_as :quentin | ||
| 172 | user = users(:quentin) | ||
| 173 | put :update, :id => user.id, :user => {:admin => true} | ||
| 174 | |||
| 175 | user.reload | ||
| 176 | assert_equal false, user.is_admin? | ||
| 177 | end | ||
| 178 | |||
| 179 | |||
| 180 | end | ||
