diff --git a/plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb b/plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb index 711dcec..ce35191 100644 --- a/plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb +++ b/plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb @@ -40,7 +40,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase Article.delete_all get :index, :block_id => block.id json_response = ActiveSupport::JSON.decode(@response.body) - assert_equivalent [], json_response + assert_equal [], json_response end should 'index action returns an json with node content' do @@ -52,7 +52,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase expected_json = {'data' => article.title} expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with node checked if the node is in the nodes list' do @@ -67,7 +67,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} expected_json['attr'].merge!({'class' => 'jstree-checked'}) - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with node undetermined if the node is in the parent nodes list' do @@ -95,7 +95,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} expected_json['state'] = 'closed' - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with all the children nodes if some parent is in the parents list' do @@ -118,7 +118,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase expected_json['children'] = children expected_json['state'] = 'closed' - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do @@ -148,7 +148,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id, "class" => "jstree-checked"} expected_json.push(value) - assert_equivalent expected_json, json_response + assert_hash_equivalent expected_json, json_response end should 'index action returns an json without children nodes if the parent is not in the parents list' do @@ -170,7 +170,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} expected_json.push(value) - assert_equivalent expected_json, json_response + assert_hash_equivalent expected_json, json_response end end diff --git a/plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb b/plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb index 67d30a3..331158a 100644 --- a/plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb +++ b/plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb @@ -41,7 +41,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase Article.delete_all get :index, :block_id => block.id, :profile => profile.identifier json_response = ActiveSupport::JSON.decode(@response.body) - assert_equivalent [], json_response + assert_equal [], json_response end should 'index action returns an json with node content' do @@ -53,7 +53,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase expected_json = {'data' => article.title} expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with node checked if the node is in the nodes list' do @@ -68,7 +68,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} expected_json['attr'].merge!({'class' => 'jstree-checked'}) - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with node undetermined if the node is in the parent nodes list' do @@ -97,7 +97,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} expected_json['state'] = 'closed' - assert_equivalent [expected_json], json_response + assert_hash_equivalent [expected_json], json_response end should 'index action returns an json with all the children nodes if some parent is in the parents list' do @@ -120,26 +120,26 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase expected_json['children'] = children expected_json['state'] = 'closed' - assert_equivalent [expected_json], json_response - end - - should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do - Article.delete_all - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) - block.checked_nodes = {a1.id => true} - block.save! - - get :index, :block_id => block.id, :profile => profile.identifier - json_response = ActiveSupport::JSON.decode(@response.body) - expected_json = [] - value = {'data' => f.title} - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} - children = [ - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} + assert_hash_equivalent [expected_json], json_response + end + + should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do + Article.delete_all + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) + block.checked_nodes = {a1.id => true} + block.save! + + get :index, :block_id => block.id, :profile => profile.identifier + json_response = ActiveSupport::JSON.decode(@response.body) + expected_json = [] + value = {'data' => f.title} + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} + children = [ + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} ] value['attr'].merge!({'class' => 'jstree-undetermined'}) value['children'] = children @@ -150,7 +150,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} expected_json.push(value) - assert_equivalent expected_json, json_response + assert_hash_equivalent expected_json, json_response end should 'index action returns an json without children nodes if the parent is not in the parents list' do @@ -172,7 +172,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} expected_json.push(value) - assert_equivalent expected_json, json_response + assert_hash_equivalent expected_json, json_response end end diff --git a/plugins/display_content/test/test_helper.rb b/plugins/display_content/test/test_helper.rb index cca1fd3..7de1c0f 100644 --- a/plugins/display_content/test/test_helper.rb +++ b/plugins/display_content/test/test_helper.rb @@ -1 +1,11 @@ -require File.dirname(__FILE__) + '/../../../test/test_helper' +require_relative "../../../test/test_helper" + +def sort_by_data(array) + return if array.blank? + array.each {|el| el['children'] = sort_by_data(el['children']) } + array.sort_by {|el| el['data']} +end + +def assert_hash_equivalent(expected, response) + assert_equal sort_by_data(expected), sort_by_data(response) +end -- libgit2 0.21.2