typus 3.0.11 → 3.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -1
- data/app/helpers/admin/relationships_helper.rb +2 -2
- data/app/views/admin/dashboard/_applications.html.erb +1 -1
- data/app/views/admin/helpers/resources/_errors.html.erb +1 -1
- data/app/views/admin/helpers/sidebar/_sidebar.html.erb +1 -1
- data/app/views/admin/resources/index.html.erb +2 -2
- data/app/views/admin/templates/_has_n.html.erb +1 -1
- data/app/views/admin/templates/_has_one.html.erb +1 -1
- data/config/locales/typus.ca.yml +1 -1
- data/config/locales/typus.de.models.yml +6 -5
- data/config/locales/typus.de.yml +39 -36
- data/config/locales/typus.el.yml +1 -1
- data/config/locales/typus.es.yml +1 -1
- data/config/locales/typus.fr.yml +1 -1
- data/config/locales/typus.hu.yml +1 -1
- data/config/locales/typus.locale.yml.template +1 -1
- data/config/locales/typus.pt-BR.yml +1 -1
- data/config/locales/typus.pt-PT.yml +1 -1
- data/config/locales/typus.ru.yml +1 -1
- data/config/locales/typus.zh-CN.yml +1 -1
- data/lib/typus/version.rb +1 -1
- data/typus.gemspec +7 -4
- metadata +16 -164
- data/test/app/controllers/admin/account_controller_test.rb +0 -106
- data/test/app/controllers/admin/assets_controller_test.rb +0 -156
- data/test/app/controllers/admin/base_controller_test.rb +0 -41
- data/test/app/controllers/admin/birds_controller_test.rb +0 -42
- data/test/app/controllers/admin/cases_controller_test.rb +0 -21
- data/test/app/controllers/admin/categories_controller_test.rb +0 -134
- data/test/app/controllers/admin/comments_controller_test.rb +0 -79
- data/test/app/controllers/admin/dashboard_controller_test.rb +0 -162
- data/test/app/controllers/admin/image_holders_controller_test.rb +0 -75
- data/test/app/controllers/admin/invoices_controller_test.rb +0 -78
- data/test/app/controllers/admin/orders_controller_test.rb +0 -18
- data/test/app/controllers/admin/pages_controller_test.rb +0 -37
- data/test/app/controllers/admin/posts_controller_test.rb +0 -770
- data/test/app/controllers/admin/projects_controller_test.rb +0 -52
- data/test/app/controllers/admin/session_controller_test.rb +0 -92
- data/test/app/controllers/admin/status_controller_test.rb +0 -54
- data/test/app/controllers/admin/typus_users_controller_test.rb +0 -156
- data/test/app/controllers/admin/users_controller_test.rb +0 -106
- data/test/app/controllers/admin/views_controller_test.rb +0 -36
- data/test/app/helpers/admin/base_helper_test.rb +0 -83
- data/test/app/helpers/admin/dashboard_helper_test.rb +0 -32
- data/test/app/helpers/admin/file_preview_helper_test.rb +0 -90
- data/test/app/helpers/admin/filters_helper_test.rb +0 -166
- data/test/app/helpers/admin/form_helper_test.rb +0 -126
- data/test/app/helpers/admin/list_helper_test.rb +0 -76
- data/test/app/helpers/admin/relationships_helper_test.rb +0 -19
- data/test/app/helpers/admin/resources_helper_test.rb +0 -46
- data/test/app/helpers/admin/search_helper_test.rb +0 -60
- data/test/app/helpers/admin/sidebar_helper_test.rb +0 -34
- data/test/app/helpers/admin/table_helper_test.rb +0 -241
- data/test/app/mailers/admin/mailer_test.rb +0 -32
- data/test/app/models/admin_user_test.rb +0 -5
- data/test/app/models/typus_user_roles_test.rb +0 -125
- data/test/app/models/typus_user_test.rb +0 -228
- data/test/config/routes_test.rb +0 -29
- data/test/factories.rb +0 -122
- data/test/fixtures/config/broken/application.yml +0 -68
- data/test/fixtures/config/broken/application_roles.yml +0 -20
- data/test/fixtures/config/broken/empty.yml +0 -0
- data/test/fixtures/config/broken/empty_roles.yml +0 -0
- data/test/fixtures/config/broken/undefined.yml +0 -3
- data/test/fixtures/config/broken/undefined_roles.yml +0 -6
- data/test/fixtures/config/default/typus.yml +0 -13
- data/test/fixtures/config/default/typus_roles.yml +0 -2
- data/test/fixtures/config/empty/empty_01.yml +0 -0
- data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_02.yml +0 -0
- data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
- data/test/fixtures/config/locales/es.yml +0 -10
- data/test/fixtures/config/namespaced/application.yml +0 -5
- data/test/fixtures/config/namespaced/application_roles.yml +0 -2
- data/test/fixtures/config/ordered/001_roles.yml +0 -2
- data/test/fixtures/config/ordered/002_roles.yml +0 -2
- data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
- data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
- data/test/lib/support/active_record_test.rb +0 -174
- data/test/lib/support/fake_user_test.rb +0 -63
- data/test/lib/support/hash_test.rb +0 -29
- data/test/lib/support/object_test.rb +0 -17
- data/test/lib/support/string_test.rb +0 -98
- data/test/lib/typus/configuration_test.rb +0 -46
- data/test/lib/typus/controller/actions_test.rb +0 -141
- data/test/lib/typus/controller/associations_test.rb +0 -7
- data/test/lib/typus/controller/autocomplete_test.rb +0 -7
- data/test/lib/typus/controller/filters_test.rb +0 -73
- data/test/lib/typus/controller/format_test.rb +0 -7
- data/test/lib/typus/i18n_test.rb +0 -9
- data/test/lib/typus/orm/active_record/class_methods_test.rb +0 -390
- data/test/lib/typus/orm/active_record/search_test.rb +0 -330
- data/test/lib/typus/regex_test.rb +0 -53
- data/test/lib/typus/resources_test.rb +0 -41
- data/test/lib/typus_test.rb +0 -142
- data/test/test_helper.rb +0 -15
@@ -1,76 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::ListHelperTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
include Admin::ListHelper
|
6
|
-
|
7
|
-
def render(*args); args; end
|
8
|
-
|
9
|
-
context "resources_actions" do
|
10
|
-
|
11
|
-
should "return a default value which is an empty array" do
|
12
|
-
assert resources_actions.empty?
|
13
|
-
end
|
14
|
-
|
15
|
-
should "return a predefined value" do
|
16
|
-
@resources_actions = "mock"
|
17
|
-
assert_equal "mock", resources_actions
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context "list_actions" do
|
23
|
-
|
24
|
-
should "be empty" do
|
25
|
-
assert list_actions.empty?
|
26
|
-
end
|
27
|
-
|
28
|
-
should "not include actions that a role cannot perform" do
|
29
|
-
@resource = mock
|
30
|
-
@resource.stubs(:name).returns("resource")
|
31
|
-
|
32
|
-
self.stubs(:link_to).returns("some_link")
|
33
|
-
sample_action = ["a body", {:action => :some_action}, {}]
|
34
|
-
self.stubs(:resources_actions).returns([sample_action] * 3)
|
35
|
-
|
36
|
-
admin_user = mock
|
37
|
-
admin_user.stubs(:can?).returns(true, false, true)
|
38
|
-
self.stubs(:admin_user).returns(admin_user)
|
39
|
-
self.stubs(:params).returns({:action => 'some_other_action'})
|
40
|
-
|
41
|
-
results = list_actions.split("/")
|
42
|
-
assert_equal 2, results.size
|
43
|
-
end
|
44
|
-
|
45
|
-
should_eventually "return an array with our custom actions"
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
context "build_list" do
|
50
|
-
|
51
|
-
setup do
|
52
|
-
@model = TypusUser
|
53
|
-
@fields = %w( email role status )
|
54
|
-
@items = TypusUser.all
|
55
|
-
@resource = "typus_users"
|
56
|
-
end
|
57
|
-
|
58
|
-
should "return a table" do
|
59
|
-
expected = [ "admin/typus_users/list", { :items => [] } ]
|
60
|
-
output = build_list(@model, @fields, @items, @resource)
|
61
|
-
assert_equal expected, output
|
62
|
-
end
|
63
|
-
|
64
|
-
should "return a template" do
|
65
|
-
self.stubs(:render).returns("a_template")
|
66
|
-
File.stubs(:exist?).returns(true)
|
67
|
-
|
68
|
-
expected = "a_template"
|
69
|
-
output = build_list(@model, @fields, @items, @resource)
|
70
|
-
|
71
|
-
assert_equal expected, output
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::RelationshipsHelperTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
include Admin::RelationshipsHelper
|
6
|
-
|
7
|
-
should_eventually "test setup_relationship"
|
8
|
-
should_eventually "test typus_form_has_many"
|
9
|
-
should_eventually "test typus_form_has_and_belongs_to_many"
|
10
|
-
should_eventually "test build_pagination"
|
11
|
-
should_eventually "test build_relate_form"
|
12
|
-
should_eventually "test build_relationship_table"
|
13
|
-
should_eventually "test build_add_new"
|
14
|
-
should_eventually "test set_condition"
|
15
|
-
should_eventually "test set_conditions"
|
16
|
-
should_eventually "test typus_form_has_one"
|
17
|
-
should_eventually "test typus_belongs_to_field"
|
18
|
-
|
19
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Admin::ResourcesHelperTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
include Admin::ResourcesHelper
|
6
|
-
|
7
|
-
include ActionView::Helpers::UrlHelper
|
8
|
-
include ActionView::Helpers::TagHelper
|
9
|
-
|
10
|
-
def render(*args); args; end
|
11
|
-
|
12
|
-
context "display_link_to_previous" do
|
13
|
-
|
14
|
-
setup do
|
15
|
-
@resource = Comment
|
16
|
-
end
|
17
|
-
|
18
|
-
should "set an url to new when not resource_id is passed" do
|
19
|
-
params = { :resource => "Post" }
|
20
|
-
|
21
|
-
expected = ["admin/helpers/resources/display_link_to_previous",
|
22
|
-
{:body=>"Cancel adding a new comment?", :url=>{:controller=>"/admin/posts", :action => 'new'}}]
|
23
|
-
|
24
|
-
assert_equal expected, display_link_to_previous(params)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "set an url to edit when resource_id is passed" do
|
28
|
-
@post = Factory(:post)
|
29
|
-
params = { :resource => "Post", :resource_id => @post.id }
|
30
|
-
|
31
|
-
expected = ["admin/helpers/resources/display_link_to_previous",
|
32
|
-
{:body=>"Cancel adding a new comment?", :url=>{:controller=>"/admin/posts", :action => 'edit', :id => @post.id}}]
|
33
|
-
|
34
|
-
assert_equal expected, display_link_to_previous(params)
|
35
|
-
end
|
36
|
-
|
37
|
-
should "return nil if no resource is passed" do
|
38
|
-
params = { :action => "edit" }
|
39
|
-
self.expects(:params).at_least_once.returns(params)
|
40
|
-
|
41
|
-
assert_nil display_link_to_previous
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class Admin::SearchHelperTest < ActiveSupport::TestCase
|
6
|
-
|
7
|
-
include Admin::SearchHelper
|
8
|
-
|
9
|
-
def render(*args); args; end
|
10
|
-
|
11
|
-
context "search" do
|
12
|
-
|
13
|
-
should "reject controller and action params" do
|
14
|
-
parameters = {"controller"=>"admin/posts", "action"=>"index"}
|
15
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
16
|
-
assert_equal expected, search(Entry, parameters)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Why do you need the pagination page for a new search?
|
20
|
-
should "reject the page param" do
|
21
|
-
parameters = {"page"=>"1"}
|
22
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
23
|
-
assert_equal expected, search(Entry, parameters)
|
24
|
-
end
|
25
|
-
|
26
|
-
# TODO: I want to think about it ...
|
27
|
-
should "reject locale params" do
|
28
|
-
parameters = {"locale"=>"jp"}
|
29
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
30
|
-
assert_equal expected, search(Entry, parameters)
|
31
|
-
end
|
32
|
-
|
33
|
-
# TODO: I want to think about it ...
|
34
|
-
should "reject to sort_order and order_by" do
|
35
|
-
parameters = {"sort_order"=>"asc", "order_by"=>"title"}
|
36
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
37
|
-
assert_equal expected, search(Entry, parameters)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "reject the utf8 param because the form already contains it" do
|
41
|
-
parameters = {"utf8"=>"✓"}
|
42
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
43
|
-
assert_equal expected, search(Entry, parameters)
|
44
|
-
end
|
45
|
-
|
46
|
-
should "reject the search param because the form already contains it" do
|
47
|
-
parameters = {"search"=>"Chunky Bacon"}
|
48
|
-
expected = ["admin/helpers/search/search", {:hidden_filters => {}}]
|
49
|
-
assert_equal expected, search(Entry, parameters)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "not reject applied filters" do
|
53
|
-
parameters = {"published"=>"true", "user_id"=>"1"}
|
54
|
-
expected = ["admin/helpers/search/search", {:hidden_filters=>{"published"=>"true", "user_id"=>"1"}}]
|
55
|
-
assert_equal expected, search(Entry, parameters)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
class Admin::SidebarHelperTest < ActiveSupport::TestCase
|
6
|
-
|
7
|
-
include Admin::SidebarHelper
|
8
|
-
|
9
|
-
include ActionView::Helpers::UrlHelper
|
10
|
-
include ActionView::Helpers::TagHelper
|
11
|
-
include ActionView::Helpers::FormTagHelper
|
12
|
-
|
13
|
-
def render(*args); args; end
|
14
|
-
def link_to(*args); args; end
|
15
|
-
|
16
|
-
setup do
|
17
|
-
default_url_options[:host] = 'test.host'
|
18
|
-
end
|
19
|
-
|
20
|
-
context "export" do
|
21
|
-
|
22
|
-
should "return array with expected values" do
|
23
|
-
params = { :controller => '/admin/posts', :action => 'index' }
|
24
|
-
|
25
|
-
output = export(Post , params)
|
26
|
-
expected = [["Export as CSV", { :action => "index", :format => "csv", :controller => "/admin/posts" }],
|
27
|
-
["Export as XML", { :action => "index", :format => "xml", :controller => "/admin/posts" }]]
|
28
|
-
|
29
|
-
assert_equal expected, output
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,241 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class FakeController
|
4
|
-
attr_accessor :request
|
5
|
-
|
6
|
-
def config
|
7
|
-
@config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Admin::TableHelperTest < ActiveSupport::TestCase
|
12
|
-
|
13
|
-
include Admin::TableHelper
|
14
|
-
|
15
|
-
include ActionView::Helpers::UrlHelper
|
16
|
-
include ActionView::Helpers::TagHelper
|
17
|
-
include ActionView::Helpers::TextHelper
|
18
|
-
include ActionView::Helpers::RawOutputHelper
|
19
|
-
|
20
|
-
include ActionView::Context
|
21
|
-
|
22
|
-
include Rails.application.routes.url_helpers
|
23
|
-
|
24
|
-
def render(*args); args; end
|
25
|
-
def params; {} end
|
26
|
-
def admin_user; end
|
27
|
-
|
28
|
-
setup do
|
29
|
-
default_url_options[:host] = "test.host"
|
30
|
-
self.stubs(:controller).returns(FakeController.new)
|
31
|
-
end
|
32
|
-
|
33
|
-
context "table_header" do
|
34
|
-
|
35
|
-
should "work" do
|
36
|
-
params = { :controller => "/admin/typus_users", :action => "index" }
|
37
|
-
fields = TypusUser.typus_fields_for(:list)
|
38
|
-
|
39
|
-
expected = [ %(<a href="/admin/typus_users?order_by=email">Email</a>),
|
40
|
-
%(<a href="/admin/typus_users?order_by=role">Role</a>),
|
41
|
-
%(<a href="/admin/typus_users?order_by=status">Status</a>) ]
|
42
|
-
|
43
|
-
assert_equal expected, table_header(TypusUser, fields, params)
|
44
|
-
end
|
45
|
-
|
46
|
-
should "work with params" do
|
47
|
-
params = { :controller => "/admin/typus_users", :action => "index", :search => "admin" }
|
48
|
-
fields = TypusUser.typus_fields_for(:list)
|
49
|
-
|
50
|
-
expected = [ %(<a href="/admin/typus_users?order_by=email&search=admin">Email</a>),
|
51
|
-
%(<a href="/admin/typus_users?order_by=role&search=admin">Role</a>),
|
52
|
-
%(<a href="/admin/typus_users?order_by=status&search=admin">Status</a>) ]
|
53
|
-
|
54
|
-
assert_equal expected, table_header(TypusUser, fields, params)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
context "table_actions" do
|
60
|
-
setup do
|
61
|
-
admin_user = mock
|
62
|
-
admin_user.stubs(:can?).returns(true)
|
63
|
-
self.stubs(:admin_user).returns(admin_user)
|
64
|
-
self.stubs(:params).returns({:controller => 'admin/comments', :action => 'some_other_action'})
|
65
|
-
end
|
66
|
-
|
67
|
-
should "work" do
|
68
|
-
item = Factory(:comment)
|
69
|
-
@resource_actions = [["Show", {:action => :show}, {}]]
|
70
|
-
expected = %Q(<a href="/admin/comments/show/#{item.id}">Show</a>)
|
71
|
-
|
72
|
-
assert_equal expected, table_actions(Comment, item, nil)
|
73
|
-
end
|
74
|
-
|
75
|
-
should "work with conditions" do
|
76
|
-
item = Factory(:comment, :id => 1)
|
77
|
-
proc1 = Proc.new {|item| item.id != 1}
|
78
|
-
@resource_actions = [["Show", {:action => :show}, {}, proc1], ["Edit", {:action => :edit}, {}]]
|
79
|
-
expected = %Q(<a href="/admin/comments/edit/#{item.id}">Edit</a>)
|
80
|
-
|
81
|
-
assert_equal expected, table_actions(Comment, item, nil)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "resource_actions" do
|
86
|
-
|
87
|
-
should "return a default value which is an empty array" do
|
88
|
-
assert resource_actions.empty?
|
89
|
-
end
|
90
|
-
|
91
|
-
should "return a predefined value" do
|
92
|
-
@resource_actions = "mock"
|
93
|
-
assert_equal "mock", resource_actions
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
context "table_belongs_to_field" do
|
99
|
-
|
100
|
-
should "work without associated model" do
|
101
|
-
comment = Factory(:comment, :post => nil)
|
102
|
-
assert_equal "—", table_belongs_to_field("post", comment)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "work with associated model when user has access" do
|
106
|
-
admin_user.expects(:can?).returns(true)
|
107
|
-
comment = Factory(:comment)
|
108
|
-
post = comment.post
|
109
|
-
assert_equal %(<a href="/admin/posts/edit/#{post.id}">#{post.to_label}</a>), table_belongs_to_field("post", comment)
|
110
|
-
end
|
111
|
-
|
112
|
-
should "work with associated model when user does not have access" do
|
113
|
-
admin_user.expects(:can?).returns(false)
|
114
|
-
comment = Factory(:comment)
|
115
|
-
post = comment.post
|
116
|
-
assert_equal post.to_label, table_belongs_to_field("post", comment)
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
should "test_table_has_and_belongs_to_many_field" do
|
122
|
-
post = Factory(:post)
|
123
|
-
post.comments << Factory(:comment, :name => "John")
|
124
|
-
post.comments << Factory(:comment, :name => "Jack")
|
125
|
-
assert_equal "John, Jack", table_has_and_belongs_to_many_field("comments", post)
|
126
|
-
end
|
127
|
-
|
128
|
-
context "table_string_field" do
|
129
|
-
|
130
|
-
should "work" do
|
131
|
-
post = Factory(:post)
|
132
|
-
assert_equal post.title, table_string_field(:title, post)
|
133
|
-
end
|
134
|
-
|
135
|
-
should "work when attribute is empty" do
|
136
|
-
post = Factory(:post)
|
137
|
-
post.title = ""
|
138
|
-
assert_equal "—", table_string_field(:title, post)
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
context "table_integer_field" do
|
144
|
-
|
145
|
-
should "work" do
|
146
|
-
post = Factory(:post)
|
147
|
-
assert_equal post.id, table_integer_field(:id, post)
|
148
|
-
end
|
149
|
-
|
150
|
-
should "work when attribute is empty" do
|
151
|
-
post = Factory(:post)
|
152
|
-
post.id = nil
|
153
|
-
assert_equal "—", table_integer_field(:id, post)
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
context "table_tree_field" do
|
159
|
-
|
160
|
-
should "work when no parent" do
|
161
|
-
page = Factory(:page)
|
162
|
-
assert_equal "—", table_tree_field("title", page)
|
163
|
-
end
|
164
|
-
|
165
|
-
should "work when parent" do
|
166
|
-
parent = Factory(:page)
|
167
|
-
page = Factory(:page, :parent => parent)
|
168
|
-
assert_equal parent.to_label, table_tree_field("title", page)
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
should "test_table_datetime_field" do
|
174
|
-
post = Factory(:post)
|
175
|
-
assert_equal post.created_at.strftime("%d %b %H:%M"), table_datetime_field(:created_at, post)
|
176
|
-
end
|
177
|
-
|
178
|
-
context "table_boolean_field" do
|
179
|
-
|
180
|
-
should "work when default status is true" do
|
181
|
-
post = Factory(:typus_user)
|
182
|
-
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Active</a>)
|
183
|
-
assert_equal expected, table_boolean_field("status", post)
|
184
|
-
end
|
185
|
-
|
186
|
-
should "work when default status is false" do
|
187
|
-
post = Factory(:typus_user, :status => false)
|
188
|
-
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Inactive</a>)
|
189
|
-
assert_equal expected, table_boolean_field("status", post)
|
190
|
-
end
|
191
|
-
|
192
|
-
should "work when default status is nil" do
|
193
|
-
post = Factory(:typus_user, :status => nil)
|
194
|
-
assert post.status.nil?
|
195
|
-
expected = %(<a href="/admin/typus_users/toggle/#{post.id}?field=status" data-confirm="Change status?">Inactive</a>)
|
196
|
-
assert_equal expected, table_boolean_field("status", post)
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
context "table_transversal_field" do
|
202
|
-
|
203
|
-
should "work" do
|
204
|
-
comment = Factory(:comment)
|
205
|
-
output = table_transversal_field("post.title", comment)
|
206
|
-
expected = comment.post.title
|
207
|
-
assert_equal expected, output
|
208
|
-
end
|
209
|
-
|
210
|
-
should "return a dash if the association does not exist" do
|
211
|
-
comment = Factory(:comment, :post => nil)
|
212
|
-
assert_equal "—", table_transversal_field("post.title", comment)
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
should "test_table_position_field" do
|
218
|
-
first_category = Factory(:category, :position => 0)
|
219
|
-
second_category = Factory(:category, :position => 1)
|
220
|
-
last_category = Factory(:category, :position => 2)
|
221
|
-
|
222
|
-
output = table_position_field(nil, first_category)
|
223
|
-
expected = <<-HTML
|
224
|
-
1<br/><br/><a href="/admin/categories/position/#{first_category.id}?go=move_lower">Down</a> / <a href="/admin/categories/position/#{first_category.id}?go=move_to_bottom">Bottom</a>
|
225
|
-
HTML
|
226
|
-
assert_equal expected.strip, output
|
227
|
-
|
228
|
-
output = table_position_field(nil, second_category)
|
229
|
-
expected = <<-HTML
|
230
|
-
2<br/><br/><a href="/admin/categories/position/#{second_category.id}?go=move_to_top">Top</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_higher">Up</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_lower">Down</a> / <a href="/admin/categories/position/#{second_category.id}?go=move_to_bottom">Bottom</a>
|
231
|
-
HTML
|
232
|
-
assert_equal expected.strip, output
|
233
|
-
|
234
|
-
output = table_position_field(nil, last_category)
|
235
|
-
expected = <<-HTML
|
236
|
-
3<br/><br/><a href="/admin/categories/position/#{last_category.id}?go=move_to_top">Top</a> / <a href="/admin/categories/position/#{last_category.id}?go=move_higher">Up</a>
|
237
|
-
HTML
|
238
|
-
assert_equal expected.strip, output
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|