Commit 793f7219d5a529771720214beb33d225779891e2
1 parent
156ae506
Exists in
master
and in
22 other branches
display_content: fix tests
Showing
3 changed files
with
44 additions
and
34 deletions
Show diff stats
plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb
@@ -40,7 +40,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | @@ -40,7 +40,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
40 | Article.delete_all | 40 | Article.delete_all |
41 | get :index, :block_id => block.id | 41 | get :index, :block_id => block.id |
42 | json_response = ActiveSupport::JSON.decode(@response.body) | 42 | json_response = ActiveSupport::JSON.decode(@response.body) |
43 | - assert_equivalent [], json_response | 43 | + assert_equal [], json_response |
44 | end | 44 | end |
45 | 45 | ||
46 | should 'index action returns an json with node content' do | 46 | should 'index action returns an json with node content' do |
@@ -52,7 +52,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | @@ -52,7 +52,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
52 | expected_json = {'data' => article.title} | 52 | expected_json = {'data' => article.title} |
53 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | 53 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} |
54 | 54 | ||
55 | - assert_equivalent [expected_json], json_response | 55 | + assert_hash_equivalent [expected_json], json_response |
56 | end | 56 | end |
57 | 57 | ||
58 | should 'index action returns an json with node checked if the node is in the nodes list' do | 58 | 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 | @@ -67,7 +67,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
67 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | 67 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} |
68 | expected_json['attr'].merge!({'class' => 'jstree-checked'}) | 68 | expected_json['attr'].merge!({'class' => 'jstree-checked'}) |
69 | 69 | ||
70 | - assert_equivalent [expected_json], json_response | 70 | + assert_hash_equivalent [expected_json], json_response |
71 | end | 71 | end |
72 | 72 | ||
73 | should 'index action returns an json with node undetermined if the node is in the parent nodes list' do | 73 | 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 | @@ -95,7 +95,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
95 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | 95 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} |
96 | expected_json['state'] = 'closed' | 96 | expected_json['state'] = 'closed' |
97 | 97 | ||
98 | - assert_equivalent [expected_json], json_response | 98 | + assert_hash_equivalent [expected_json], json_response |
99 | end | 99 | end |
100 | 100 | ||
101 | should 'index action returns an json with all the children nodes if some parent is in the parents list' do | 101 | 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 | @@ -118,7 +118,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
118 | expected_json['children'] = children | 118 | expected_json['children'] = children |
119 | expected_json['state'] = 'closed' | 119 | expected_json['state'] = 'closed' |
120 | 120 | ||
121 | - assert_equivalent [expected_json], json_response | 121 | + assert_hash_equivalent [expected_json], json_response |
122 | end | 122 | end |
123 | 123 | ||
124 | 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 | 124 | 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 | @@ -148,7 +148,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
148 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id, "class" => "jstree-checked"} | 148 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id, "class" => "jstree-checked"} |
149 | expected_json.push(value) | 149 | expected_json.push(value) |
150 | 150 | ||
151 | - assert_equivalent expected_json, json_response | 151 | + assert_hash_equivalent expected_json, json_response |
152 | end | 152 | end |
153 | 153 | ||
154 | should 'index action returns an json without children nodes if the parent is not in the parents list' do | 154 | 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 | @@ -170,7 +170,7 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
170 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | 170 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} |
171 | expected_json.push(value) | 171 | expected_json.push(value) |
172 | 172 | ||
173 | - assert_equivalent expected_json, json_response | 173 | + assert_hash_equivalent expected_json, json_response |
174 | end | 174 | end |
175 | 175 | ||
176 | end | 176 | end |
plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb
@@ -41,7 +41,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | @@ -41,7 +41,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
41 | Article.delete_all | 41 | Article.delete_all |
42 | get :index, :block_id => block.id, :profile => profile.identifier | 42 | get :index, :block_id => block.id, :profile => profile.identifier |
43 | json_response = ActiveSupport::JSON.decode(@response.body) | 43 | json_response = ActiveSupport::JSON.decode(@response.body) |
44 | - assert_equivalent [], json_response | 44 | + assert_equal [], json_response |
45 | end | 45 | end |
46 | 46 | ||
47 | should 'index action returns an json with node content' do | 47 | should 'index action returns an json with node content' do |
@@ -53,7 +53,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | @@ -53,7 +53,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
53 | expected_json = {'data' => article.title} | 53 | expected_json = {'data' => article.title} |
54 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | 54 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} |
55 | 55 | ||
56 | - assert_equivalent [expected_json], json_response | 56 | + assert_hash_equivalent [expected_json], json_response |
57 | end | 57 | end |
58 | 58 | ||
59 | should 'index action returns an json with node checked if the node is in the nodes list' do | 59 | 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 | @@ -68,7 +68,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
68 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | 68 | expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} |
69 | expected_json['attr'].merge!({'class' => 'jstree-checked'}) | 69 | expected_json['attr'].merge!({'class' => 'jstree-checked'}) |
70 | 70 | ||
71 | - assert_equivalent [expected_json], json_response | 71 | + assert_hash_equivalent [expected_json], json_response |
72 | end | 72 | end |
73 | 73 | ||
74 | should 'index action returns an json with node undetermined if the node is in the parent nodes list' do | 74 | 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 | @@ -97,7 +97,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
97 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | 97 | expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} |
98 | expected_json['state'] = 'closed' | 98 | expected_json['state'] = 'closed' |
99 | 99 | ||
100 | - assert_equivalent [expected_json], json_response | 100 | + assert_hash_equivalent [expected_json], json_response |
101 | end | 101 | end |
102 | 102 | ||
103 | should 'index action returns an json with all the children nodes if some parent is in the parents list' do | 103 | 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 | @@ -120,26 +120,26 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
120 | expected_json['children'] = children | 120 | expected_json['children'] = children |
121 | expected_json['state'] = 'closed' | 121 | expected_json['state'] = 'closed' |
122 | 122 | ||
123 | - assert_equivalent [expected_json], json_response | ||
124 | - end | ||
125 | - | ||
126 | - 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 | ||
127 | - Article.delete_all | ||
128 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | ||
129 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | ||
130 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | ||
131 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | ||
132 | - block.checked_nodes = {a1.id => true} | ||
133 | - block.save! | ||
134 | - | ||
135 | - get :index, :block_id => block.id, :profile => profile.identifier | ||
136 | - json_response = ActiveSupport::JSON.decode(@response.body) | ||
137 | - expected_json = [] | ||
138 | - value = {'data' => f.title} | ||
139 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | ||
140 | - children = [ | ||
141 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, | ||
142 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | 123 | + assert_hash_equivalent [expected_json], json_response |
124 | + end | ||
125 | + | ||
126 | + 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 | ||
127 | + Article.delete_all | ||
128 | + f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | ||
129 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | ||
130 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | ||
131 | + a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | ||
132 | + block.checked_nodes = {a1.id => true} | ||
133 | + block.save! | ||
134 | + | ||
135 | + get :index, :block_id => block.id, :profile => profile.identifier | ||
136 | + json_response = ActiveSupport::JSON.decode(@response.body) | ||
137 | + expected_json = [] | ||
138 | + value = {'data' => f.title} | ||
139 | + value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | ||
140 | + children = [ | ||
141 | + {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id, "class" => "jstree-checked"}}, | ||
142 | + {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | ||
143 | ] | 143 | ] |
144 | value['attr'].merge!({'class' => 'jstree-undetermined'}) | 144 | value['attr'].merge!({'class' => 'jstree-undetermined'}) |
145 | value['children'] = children | 145 | value['children'] = children |
@@ -150,7 +150,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | @@ -150,7 +150,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
150 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | 150 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} |
151 | expected_json.push(value) | 151 | expected_json.push(value) |
152 | 152 | ||
153 | - assert_equivalent expected_json, json_response | 153 | + assert_hash_equivalent expected_json, json_response |
154 | end | 154 | end |
155 | 155 | ||
156 | should 'index action returns an json without children nodes if the parent is not in the parents list' do | 156 | 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 | @@ -172,7 +172,7 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
172 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | 172 | value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} |
173 | expected_json.push(value) | 173 | expected_json.push(value) |
174 | 174 | ||
175 | - assert_equivalent expected_json, json_response | 175 | + assert_hash_equivalent expected_json, json_response |
176 | end | 176 | end |
177 | 177 | ||
178 | end | 178 | end |
plugins/display_content/test/test_helper.rb
1 | -require File.dirname(__FILE__) + '/../../../test/test_helper' | 1 | +require_relative "../../../test/test_helper" |
2 | + | ||
3 | +def sort_by_data(array) | ||
4 | + return if array.blank? | ||
5 | + array.each {|el| el['children'] = sort_by_data(el['children']) } | ||
6 | + array.sort_by {|el| el['data']} | ||
7 | +end | ||
8 | + | ||
9 | +def assert_hash_equivalent(expected, response) | ||
10 | + assert_equal sort_by_data(expected), sort_by_data(response) | ||
11 | +end |