# -*- encoding : utf-8 -*- require 'test_helper' class Admin::Odania::MenuItemsControllerTest < ActionController::TestCase def setup site = create(:default_site) @request.host = site.host @content = create(:content, site: site) @menu = create(:menu_with_items, site: site, amount: 4, language: site.default_language) end test 'test should get index' do get :index, {menu_id: @menu.id.to_s} assert_response :success assert_not_nil assigns(:odania_menu_items) end test 'test should show content' do get :show, {id: @menu.menu_items.first.id.to_s, menu_id: @menu.id.to_s} assert_response :success assert_not_nil assigns(:odania_menu_item) end test 'test should redirect on invalid id' do get :show, {id: 'asd65dsadsatest-test', menu_id: @menu.id.to_s} assert_response :redirect assert_redirected_to admin_odania_menu_odania_menu_items_path(menu_id: @menu.id.to_s) end test 'should render new content' do get :new, {menu_id: @menu.id.to_s} assert_response :success assert_not_nil assigns(:odania_menu_item) end test 'should render edit content' do get :edit, {id: @menu.menu_items.first.id.to_s, menu_id: @menu.id.to_s} assert_response :success assert_not_nil assigns(:odania_menu_item) end test 'should create content' do content = create(:content) data = {title: 'Test Title', published: true, target_type: 'CONTENT'} assert_difference 'Odania::MenuItem.count' do post :create, {odania_menu_item: data, target_data: {id: content.id}, menu_id: @menu.id.to_s} end assert_response :redirect assert_redirected_to admin_odania_menu_odania_menu_items_path(menu_id: @menu.id.to_s) end test 'should update content' do data = {title: 'Test Title', published: true, target_type: 'URL'} menu_item = @menu.menu_items.first target_data = {'url' => 'http://www.perfect-reach.com'} post :update, {id: menu_item.id.to_s, odania_menu_item: data, menu_id: @menu.id.to_s, target_data: target_data} assert_response :redirect assert_redirected_to admin_odania_menu_odania_menu_items_path(menu_id: @menu.id.to_s) menu_item.reload assert_equal target_data, menu_item.target_data assert_equal data[:title], menu_item.title assert_equal data[:published], menu_item.published assert_equal data[:target_type], menu_item.target_type end test 'should destroy content' do assert_difference 'Odania::MenuItem.count', -1 do delete :destroy, {id: @menu.menu_items.first.id.to_s, menu_id: @menu.id.to_s} end assert_response :redirect assert_redirected_to admin_odania_menu_odania_menu_items_path(menu_id: @menu.id.to_s) end end