typus 3.0.11 → 3.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/README.md +4 -1
  2. data/app/helpers/admin/relationships_helper.rb +2 -2
  3. data/app/views/admin/dashboard/_applications.html.erb +1 -1
  4. data/app/views/admin/helpers/resources/_errors.html.erb +1 -1
  5. data/app/views/admin/helpers/sidebar/_sidebar.html.erb +1 -1
  6. data/app/views/admin/resources/index.html.erb +2 -2
  7. data/app/views/admin/templates/_has_n.html.erb +1 -1
  8. data/app/views/admin/templates/_has_one.html.erb +1 -1
  9. data/config/locales/typus.ca.yml +1 -1
  10. data/config/locales/typus.de.models.yml +6 -5
  11. data/config/locales/typus.de.yml +39 -36
  12. data/config/locales/typus.el.yml +1 -1
  13. data/config/locales/typus.es.yml +1 -1
  14. data/config/locales/typus.fr.yml +1 -1
  15. data/config/locales/typus.hu.yml +1 -1
  16. data/config/locales/typus.locale.yml.template +1 -1
  17. data/config/locales/typus.pt-BR.yml +1 -1
  18. data/config/locales/typus.pt-PT.yml +1 -1
  19. data/config/locales/typus.ru.yml +1 -1
  20. data/config/locales/typus.zh-CN.yml +1 -1
  21. data/lib/typus/version.rb +1 -1
  22. data/typus.gemspec +7 -4
  23. metadata +16 -164
  24. data/test/app/controllers/admin/account_controller_test.rb +0 -106
  25. data/test/app/controllers/admin/assets_controller_test.rb +0 -156
  26. data/test/app/controllers/admin/base_controller_test.rb +0 -41
  27. data/test/app/controllers/admin/birds_controller_test.rb +0 -42
  28. data/test/app/controllers/admin/cases_controller_test.rb +0 -21
  29. data/test/app/controllers/admin/categories_controller_test.rb +0 -134
  30. data/test/app/controllers/admin/comments_controller_test.rb +0 -79
  31. data/test/app/controllers/admin/dashboard_controller_test.rb +0 -162
  32. data/test/app/controllers/admin/image_holders_controller_test.rb +0 -75
  33. data/test/app/controllers/admin/invoices_controller_test.rb +0 -78
  34. data/test/app/controllers/admin/orders_controller_test.rb +0 -18
  35. data/test/app/controllers/admin/pages_controller_test.rb +0 -37
  36. data/test/app/controllers/admin/posts_controller_test.rb +0 -770
  37. data/test/app/controllers/admin/projects_controller_test.rb +0 -52
  38. data/test/app/controllers/admin/session_controller_test.rb +0 -92
  39. data/test/app/controllers/admin/status_controller_test.rb +0 -54
  40. data/test/app/controllers/admin/typus_users_controller_test.rb +0 -156
  41. data/test/app/controllers/admin/users_controller_test.rb +0 -106
  42. data/test/app/controllers/admin/views_controller_test.rb +0 -36
  43. data/test/app/helpers/admin/base_helper_test.rb +0 -83
  44. data/test/app/helpers/admin/dashboard_helper_test.rb +0 -32
  45. data/test/app/helpers/admin/file_preview_helper_test.rb +0 -90
  46. data/test/app/helpers/admin/filters_helper_test.rb +0 -166
  47. data/test/app/helpers/admin/form_helper_test.rb +0 -126
  48. data/test/app/helpers/admin/list_helper_test.rb +0 -76
  49. data/test/app/helpers/admin/relationships_helper_test.rb +0 -19
  50. data/test/app/helpers/admin/resources_helper_test.rb +0 -46
  51. data/test/app/helpers/admin/search_helper_test.rb +0 -60
  52. data/test/app/helpers/admin/sidebar_helper_test.rb +0 -34
  53. data/test/app/helpers/admin/table_helper_test.rb +0 -241
  54. data/test/app/mailers/admin/mailer_test.rb +0 -32
  55. data/test/app/models/admin_user_test.rb +0 -5
  56. data/test/app/models/typus_user_roles_test.rb +0 -125
  57. data/test/app/models/typus_user_test.rb +0 -228
  58. data/test/config/routes_test.rb +0 -29
  59. data/test/factories.rb +0 -122
  60. data/test/fixtures/config/broken/application.yml +0 -68
  61. data/test/fixtures/config/broken/application_roles.yml +0 -20
  62. data/test/fixtures/config/broken/empty.yml +0 -0
  63. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  64. data/test/fixtures/config/broken/undefined.yml +0 -3
  65. data/test/fixtures/config/broken/undefined_roles.yml +0 -6
  66. data/test/fixtures/config/default/typus.yml +0 -13
  67. data/test/fixtures/config/default/typus_roles.yml +0 -2
  68. data/test/fixtures/config/empty/empty_01.yml +0 -0
  69. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  70. data/test/fixtures/config/empty/empty_02.yml +0 -0
  71. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  72. data/test/fixtures/config/locales/es.yml +0 -10
  73. data/test/fixtures/config/namespaced/application.yml +0 -5
  74. data/test/fixtures/config/namespaced/application_roles.yml +0 -2
  75. data/test/fixtures/config/ordered/001_roles.yml +0 -2
  76. data/test/fixtures/config/ordered/002_roles.yml +0 -2
  77. data/test/fixtures/config/unordered/app_one_roles.yml +0 -2
  78. data/test/fixtures/config/unordered/app_two_roles.yml +0 -2
  79. data/test/lib/support/active_record_test.rb +0 -174
  80. data/test/lib/support/fake_user_test.rb +0 -63
  81. data/test/lib/support/hash_test.rb +0 -29
  82. data/test/lib/support/object_test.rb +0 -17
  83. data/test/lib/support/string_test.rb +0 -98
  84. data/test/lib/typus/configuration_test.rb +0 -46
  85. data/test/lib/typus/controller/actions_test.rb +0 -141
  86. data/test/lib/typus/controller/associations_test.rb +0 -7
  87. data/test/lib/typus/controller/autocomplete_test.rb +0 -7
  88. data/test/lib/typus/controller/filters_test.rb +0 -73
  89. data/test/lib/typus/controller/format_test.rb +0 -7
  90. data/test/lib/typus/i18n_test.rb +0 -9
  91. data/test/lib/typus/orm/active_record/class_methods_test.rb +0 -390
  92. data/test/lib/typus/orm/active_record/search_test.rb +0 -330
  93. data/test/lib/typus/regex_test.rb +0 -53
  94. data/test/lib/typus/resources_test.rb +0 -41
  95. data/test/lib/typus_test.rb +0 -142
  96. data/test/test_helper.rb +0 -15
@@ -1,98 +0,0 @@
1
- require "test_helper"
2
-
3
- class StringTest < ActiveSupport::TestCase
4
-
5
- should "extract_settings" do
6
- assert_equal %w( a b c ), "a, b, c".extract_settings
7
- assert_equal %w( a b c ), " a , b, c ".extract_settings
8
- end
9
-
10
- context "remove_prefix" do
11
-
12
- should "return strings without default prefix" do
13
- assert_equal "posts", "admin/posts".remove_prefix
14
- assert_equal "typus_users", "admin/typus_users".remove_prefix
15
- assert_equal "delayed/jobs", "admin/delayed/jobs".remove_prefix
16
- end
17
-
18
- should "return strings without custom prefix" do
19
- assert_equal "posts", "typus/posts".remove_prefix
20
- assert_equal "typus_users", "typus/typus_users".remove_prefix
21
- assert_equal "delayed/tasks", "typus/delayed/tasks".remove_prefix
22
- end
23
-
24
- end
25
-
26
- context "extract_class" do
27
-
28
- setup do
29
- class SucursalBancaria; end
30
-
31
- Typus::Configuration.models_constantized = { "Post" => Post,
32
- "TypusUser" => TypusUser,
33
- "Delayed::Task" => Delayed::Task,
34
- "SucursalBancaria" => SucursalBancaria }
35
- end
36
-
37
- should "work for models" do
38
- assert_equal Post, "admin/posts".extract_class
39
- assert_equal TypusUser, "admin/typus_users".extract_class
40
- end
41
-
42
- should "work for namespaced models" do
43
- assert_equal Delayed::Task, "admin/delayed/tasks".extract_class
44
- end
45
-
46
- should "work with inflections" do
47
- assert_equal SucursalBancaria, "admin/sucursales_bancarias".extract_class
48
- end
49
-
50
- end
51
-
52
- context "acl_action_mapper" do
53
-
54
- should "return create" do
55
- %w(new create).each do |action|
56
- assert_equal "create", action.acl_action_mapper
57
- end
58
- end
59
-
60
- should "return read" do
61
- %w(index show).each do |action|
62
- assert_equal "read", action.acl_action_mapper
63
- end
64
- end
65
-
66
- should "return update" do
67
- %w(edit update position toggle relate unrelate).each do |action|
68
- assert_equal "update", action.acl_action_mapper
69
- end
70
- end
71
-
72
- should "return delete" do
73
- %w(destroy trash).each do |action|
74
- assert_equal "delete", action.acl_action_mapper
75
- end
76
- end
77
-
78
- should "return other" do
79
- %w(other).each do |action|
80
- assert_equal "other", action.acl_action_mapper
81
- end
82
- end
83
-
84
- end
85
-
86
- context "to_resource" do
87
-
88
- should "convert String into resource" do
89
- assert_equal "entries", "Entry".to_resource
90
- end
91
-
92
- should "convert namespaced String into resource" do
93
- assert_equal "category/entries", "Category::Entry".to_resource
94
- end
95
-
96
- end
97
-
98
- end
@@ -1,46 +0,0 @@
1
- require "test_helper"
2
-
3
- class ConfigurationTest < ActiveSupport::TestCase
4
-
5
- should "verify typus roles is loaded" do
6
- assert Typus::Configuration.respond_to?(:roles!)
7
- assert Typus::Configuration.roles!.is_a?(Hash)
8
- end
9
-
10
- should "verify typus config file is loaded" do
11
- assert Typus::Configuration.respond_to?(:config!)
12
- assert Typus::Configuration.config!.is_a?(Hash)
13
- end
14
-
15
- should "load configuration files from config broken" do
16
- Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/broken")
17
- assert_not_equal Hash.new, Typus::Configuration.roles!
18
- assert_not_equal Hash.new, Typus::Configuration.config!
19
- end
20
-
21
- should "load configuration files from config empty" do
22
- Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/empty")
23
- assert_equal Hash.new, Typus::Configuration.roles!
24
- assert_equal Hash.new, Typus::Configuration.config!
25
- end
26
-
27
- should "load configuration files from config ordered" do
28
- Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/ordered")
29
- expected = { "admin" => { "categories" => "read" } }
30
- assert_equal expected, Typus::Configuration.roles!
31
- end
32
-
33
- should "load configuration files from config unordered" do
34
- Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/unordered")
35
- expected = { "admin" => { "categories" => "read, update" } }
36
- assert_equal expected, Typus::Configuration.roles!
37
- end
38
-
39
- should "load configuration files from config default" do
40
- Typus.expects(:config_folder).at_least_once.returns("test/fixtures/config/default")
41
- assert_not_equal Hash.new, Typus::Configuration.roles!
42
- assert_not_equal Hash.new, Typus::Configuration.config!
43
- assert Typus.resources.empty?
44
- end
45
-
46
- end
@@ -1,141 +0,0 @@
1
- require "test_helper"
2
-
3
- class ActionsTest < ActiveSupport::TestCase
4
-
5
- include Typus::Controller::Actions
6
-
7
- context "add_resource_action" do
8
-
9
- should "work" do
10
- output = add_resource_action("something")
11
- assert_equal [["something"]], @resource_actions
12
- end
13
-
14
- should "work when no params are set" do
15
- add_resource_action()
16
- assert @resource_actions.empty?
17
- end
18
-
19
- end
20
-
21
- context "prepend_resource_action" do
22
-
23
- should "work without args" do
24
- prepend_resource_action()
25
- assert @resource_actions.empty?
26
- end
27
-
28
- should "work with args" do
29
- prepend_resource_action("something")
30
- assert_equal [["something"]], @resource_actions
31
- end
32
-
33
- should "work prepending an action without args" do
34
- add_resource_action("something")
35
- prepend_resource_action()
36
- assert_equal [["something"]], @resource_actions
37
- end
38
-
39
- should "work prepending an action with args" do
40
- add_resource_action("something")
41
- prepend_resource_action("something_else")
42
- assert_equal [["something_else"], ["something"]], @resource_actions
43
- end
44
-
45
- end
46
-
47
- context "append_resource_action" do
48
-
49
- should "work without args" do
50
- append_resource_action()
51
- assert @resource_actions.empty?
52
- end
53
-
54
- should "work with args" do
55
- append_resource_action("something")
56
- assert_equal [["something"]], @resource_actions
57
- end
58
-
59
- should "work appending an action without args" do
60
- add_resource_action("something")
61
- append_resource_action()
62
- assert_equal [["something"]], @resource_actions
63
- end
64
-
65
- should "work appending an action with args" do
66
- add_resource_action("something")
67
- append_resource_action("something_else")
68
- assert_equal [["something"], ["something_else"]], @resource_actions
69
- end
70
-
71
- end
72
-
73
- # FIXME: Cleanup all test after this line.
74
-
75
- context "add_resources_action" do
76
-
77
- should "work" do
78
- add_resources_action("something")
79
- assert_equal [["something"]], @resources_actions
80
- end
81
-
82
- should "work when no params are set" do
83
- add_resources_action()
84
- assert @resources_actions.empty?
85
- end
86
-
87
- end
88
-
89
- context "prepend_resources_action" do
90
-
91
- should "work without args" do
92
- prepend_resources_action()
93
- assert @resources_actions.empty?
94
- end
95
-
96
- should "work with args" do
97
- prepend_resources_action("something")
98
- assert_equal [["something"]], @resources_actions
99
- end
100
-
101
- should "work prepending an action without args" do
102
- add_resources_action("something")
103
- prepend_resources_action()
104
- assert_equal [["something"]], @resources_actions
105
- end
106
-
107
- should "work prepending an action with args" do
108
- add_resources_action("something")
109
- prepend_resources_action("something_else")
110
- assert_equal [["something_else"], ["something"]], @resources_actions
111
- end
112
-
113
- end
114
-
115
- context "append_resources_action" do
116
-
117
- should "work without args" do
118
- append_resources_action()
119
- assert @resources_actions.empty?
120
- end
121
-
122
- should "work with args" do
123
- append_resources_action("something")
124
- assert_equal [["something"]], @resources_actions
125
- end
126
-
127
- should "work appending an action without args" do
128
- add_resources_action("something")
129
- append_resources_action()
130
- assert_equal [["something"]], @resources_actions
131
- end
132
-
133
- should "work appending an action with args" do
134
- add_resources_action("something")
135
- append_resources_action("something_else")
136
- assert_equal [["something"], ["something_else"]], @resources_actions
137
- end
138
-
139
- end
140
-
141
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class AssociationsTest < ActiveSupport::TestCase
4
-
5
- include Typus::Controller::Associations
6
-
7
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class AutocompleteTest < ActiveSupport::TestCase
4
-
5
- include Typus::Controller::Autocomplete
6
-
7
- end
@@ -1,73 +0,0 @@
1
- require "test_helper"
2
-
3
- class FiltersTest < ActiveSupport::TestCase
4
-
5
- include Typus::Controller::Filters
6
-
7
- context "add_predefined_filter" do
8
-
9
- should "work without args" do
10
- add_predefined_filter()
11
- assert @predefined_filters.empty?
12
- end
13
-
14
- should "work with args" do
15
- add_predefined_filter("something")
16
- assert_equal [["something"]], @predefined_filters
17
- end
18
-
19
- end
20
-
21
- context "prepend_predefined_filter" do
22
-
23
- should "work without args" do
24
- prepend_predefined_filter()
25
- assert @predefined_filters.empty?
26
- end
27
-
28
- should "work with args" do
29
- prepend_predefined_filter("something")
30
- assert_equal [["something"]], @predefined_filters
31
- end
32
-
33
- should "work prepending an action without args" do
34
- add_predefined_filter("something")
35
- prepend_predefined_filter()
36
- assert_equal [["something"]], @predefined_filters
37
- end
38
-
39
- should "work prepending an action with args" do
40
- add_predefined_filter("something")
41
- prepend_predefined_filter("something_else")
42
- assert_equal [["something_else"], ["something"]], @predefined_filters
43
- end
44
-
45
- end
46
-
47
- context "append_predefined_filter" do
48
-
49
- should "work without args" do
50
- append_predefined_filter()
51
- assert @predefined_filters.empty?
52
- end
53
-
54
- should "work with args" do
55
- append_predefined_filter("something")
56
- assert_equal [["something"]], @predefined_filters
57
- end
58
-
59
- should "work appending an action without args" do
60
- add_predefined_filter("something")
61
- append_predefined_filter()
62
- assert_equal [["something"]], @predefined_filters
63
- end
64
-
65
- should "work appending an action with args" do
66
- add_predefined_filter("something")
67
- append_predefined_filter("something_else")
68
- assert_equal [["something"], ["something_else"]], @predefined_filters
69
- end
70
-
71
- end
72
-
73
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class FormatTest < ActiveSupport::TestCase
4
-
5
- include Typus::Controller::Format
6
-
7
- end
@@ -1,9 +0,0 @@
1
- require "test_helper"
2
-
3
- class I18nTest < ActiveSupport::TestCase
4
-
5
- should "work" do
6
- assert_equal "Missing Translation", Typus::I18n.t("Missing Translation")
7
- end
8
-
9
- end
@@ -1,390 +0,0 @@
1
- require "test_helper"
2
-
3
- class ClassMethodsTest < ActiveSupport::TestCase
4
-
5
- context "model_fields" do
6
-
7
- should "be an ActiveSupport::OrderedHash" do
8
- assert TypusUser.model_fields.instance_of?(ActiveSupport::OrderedHash)
9
- end
10
-
11
- should "verify TypusUser model_fields" do
12
- expected = [[:id, :integer],
13
- [:first_name, :string],
14
- [:last_name, :string],
15
- [:role, :string],
16
- [:email, :string],
17
- [:status, :boolean],
18
- [:token, :string],
19
- [:salt, :string],
20
- [:crypted_password, :string],
21
- [:preferences, :string],
22
- [:created_at, :datetime],
23
- [:updated_at, :datetime]]
24
-
25
- assert_equal expected.map { |i| i.first }, TypusUser.model_fields.keys
26
- assert_equal expected.map { |i| i.last }, TypusUser.model_fields.values
27
- end
28
-
29
- should "verify Post model_fields" do
30
- expected = [[:id, :integer],
31
- [:title, :string],
32
- [:body, :text],
33
- [:status, :string],
34
- [:favorite_comment_id, :integer],
35
- [:published_at, :datetime],
36
- [:typus_user_id, :integer],
37
- [:published, :boolean],
38
- [:created_at, :datetime],
39
- [:updated_at, :datetime]]
40
-
41
- assert_equal expected.map { |i| i.first }, Post.model_fields.keys
42
- assert_equal expected.map { |i| i.last }, Post.model_fields.values
43
- end
44
-
45
- end
46
-
47
- context "model_relationships" do
48
-
49
- should "be an ActiveSupport::OrderedHash" do
50
- assert TypusUser.model_relationships.instance_of?(ActiveSupport::OrderedHash)
51
- end
52
-
53
- should "verify Post model_relationships" do
54
- expected = [[:comments, :has_many],
55
- [:categories, :has_and_belongs_to_many],
56
- [:user, nil]]
57
- expected.each do |key, value|
58
- assert_equal value, Post.model_relationships[key]
59
- end
60
- end
61
-
62
- end
63
-
64
- context "typus_description" do
65
-
66
- should "return the description of a model" do
67
- assert_equal "System Users Administration", TypusUser.typus_description
68
- end
69
-
70
- end
71
-
72
- context "typus_fields_for" do
73
-
74
- should "accept strings" do
75
- assert_equal %w(email role status), TypusUser.typus_fields_for("list").keys
76
- end
77
-
78
- should "accept symbols" do
79
- assert_equal %w(email role status), TypusUser.typus_fields_for(:list).keys
80
- end
81
-
82
- should "return list fields for TypusUser" do
83
- expected = [["email", :string],
84
- ["role", :selector],
85
- ["status", :boolean]]
86
-
87
- assert_equal expected.map { |i| i.first }, TypusUser.typus_fields_for(:list).keys
88
- assert_equal expected.map { |i| i.last }, TypusUser.typus_fields_for(:list).values
89
- end
90
-
91
- should "return form fields for TypusUser" do
92
- expected = [["first_name", :string],
93
- ["last_name", :string],
94
- ["role", :selector],
95
- ["email", :string],
96
- ["password", :password],
97
- ["password_confirmation", :password],
98
- ["locale", :selector]]
99
-
100
- assert_equal expected.map { |i| i.first }, TypusUser.typus_fields_for(:new).keys
101
- assert_equal expected.map { |i| i.last }, TypusUser.typus_fields_for(:form).values
102
- end
103
-
104
- should "return form fields for Asset" do
105
- expected = [["caption", :string],
106
- ["dragonfly", :file],
107
- ["dragonfly_required", :file],
108
- ["original_file_name", :virtual]]
109
-
110
- assert_equal expected.map { |i| i.first }, Asset.typus_fields_for(:special).keys
111
- assert_equal expected.map { |i| i.last }, Asset.typus_fields_for(:special).values
112
- end
113
-
114
- should "raise a RuntimeError when model does not have configuration" do
115
- assert_raises RuntimeError do
116
- Class.new(ActiveRecord::Base).typus_fields_for(:form)
117
- end
118
- end
119
-
120
- should "return relationship fields for TypusUser" do
121
- expected = %w(first_name last_name role email locale)
122
- assert_equal expected, TypusUser.typus_fields_for(:relationship).keys
123
- end
124
-
125
- should "return undefined fields for TypusUser" do
126
- expected = %w(first_name last_name role email locale)
127
- assert_equal expected, TypusUser.typus_fields_for(:undefined).keys
128
- end
129
-
130
- should "return fields for new Asset" do
131
- expected = %w(dragonfly dragonfly_required paperclip paperclip_required)
132
- assert_equal expected, Asset.typus_fields_for(:new).keys
133
- end
134
-
135
- should "return fields for edit Asset" do
136
- expected = %w(caption dragonfly dragonfly_required paperclip paperclip_required original_file_name)
137
- assert_equal expected, Asset.typus_fields_for(:edit).keys
138
- end
139
-
140
- should "work for transversal fields" do
141
- expected = [["email", :string],
142
- ["post", :belongs_to],
143
- ["post_id", :integer],
144
- ["spam", :boolean],
145
- ["post.title", :transversal]]
146
-
147
- assert_equal expected.map { |i| i.first }, Comment.typus_fields_for(:list).keys
148
- assert_equal expected.map { |i| i.last }, Comment.typus_fields_for(:list).values
149
- end
150
-
151
- end
152
-
153
- context "typus_filters" do
154
-
155
- should "return filters for TypusUser" do
156
- expected = [["status", :boolean],
157
- ["role", :string]]
158
-
159
- assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["TypusUser"]["filters"]
160
- assert_equal expected.map { |i| i.first }, TypusUser.typus_filters.keys
161
- assert_equal expected.map { |i| i.last }, TypusUser.typus_filters.values
162
- end
163
-
164
- should "return filters for Post" do
165
- expected = [["published", :boolean],
166
- ["status", :string],
167
- ["created_at", :datetime]]
168
-
169
- assert_equal expected.map { |i| i.first }.join(", "), Typus::Configuration.config["Post"]["filters"]
170
- assert_equal expected.map { |i| i.first }, Post.typus_filters.keys
171
- assert_equal expected.map { |i| i.last }, Post.typus_filters.values
172
- end
173
-
174
- end
175
-
176
- context "typus_actions_on" do
177
-
178
- should "accept strings" do
179
- assert_equal %w(cleanup), Post.typus_actions_on("index")
180
- end
181
-
182
- should "accept symbols" do
183
- assert_equal %w(cleanup), Post.typus_actions_on(:index)
184
- end
185
-
186
- should "return actions on list for TypusUser" do
187
- assert TypusUser.typus_actions_on(:list).empty?
188
- end
189
-
190
- should "return actions on edit for Post" do
191
- assert_equal %w(send_as_newsletter preview), Post.typus_actions_on(:edit)
192
- end
193
-
194
- end
195
-
196
- context "typus_options_for" do
197
-
198
- should "accept strings" do
199
- assert_equal 15, Post.typus_options_for("form_rows")
200
- end
201
-
202
- should "accept symbols" do
203
- assert_equal 15, Post.typus_options_for(:form_rows)
204
- end
205
-
206
- should "return nil when options do not exist" do
207
- assert_nil TypusUser.typus_options_for(:unexisting)
208
- end
209
-
210
- should "return options for Post" do
211
- assert_equal 15, Post.typus_options_for(:form_rows)
212
- end
213
-
214
- should "return options for Page" do
215
- assert_equal 25, Page.typus_options_for(:form_rows)
216
- end
217
-
218
- should "return sortable options as a boolean" do
219
- assert Post.typus_options_for(:sortable)
220
- assert !Page.typus_options_for(:sortable)
221
- end
222
-
223
- end
224
-
225
- context "typus_application" do
226
-
227
- should "return application for Post" do
228
- assert_equal "CRUD Extended", Post.typus_application
229
- end
230
-
231
- should "return application for View" do
232
- assert_equal "Unknown", View.typus_application
233
- end
234
-
235
- end
236
-
237
- context "typus_field_options_for" do
238
-
239
- should "verify on models" do
240
- assert_equal [:status], Post.typus_field_options_for(:selectors)
241
- assert_equal [:permalink], Post.typus_field_options_for(:read_only)
242
- assert_equal [:created_at], Post.typus_field_options_for(:auto_generated)
243
- end
244
-
245
- should "return empty array for unexisting option" do
246
- assert Post.typus_field_options_for(:unexisting).empty?
247
- end
248
-
249
- end
250
-
251
- context "typus_boolean" do
252
-
253
- should "accept strings" do
254
- expected = [["Active", "true"], ["Inactive", "false"]]
255
- assert_equal expected, TypusUser.typus_boolean("status")
256
- end
257
-
258
- should "accept symbols" do
259
- expected = [["Active", "true"], ["Inactive", "false"]]
260
- assert_equal expected, TypusUser.typus_boolean(:status)
261
- end
262
-
263
- should "return booleans for Post" do
264
- expected = [["True", "true"], ["False", "false"]]
265
- assert_equal expected, Post.typus_boolean(:status)
266
- end
267
-
268
- should "return booleans for Comment" do
269
- expected = [["Yes, it's spam", "true"], ["No, it's not spam", "false"]]
270
- assert_equal expected, Comment.typus_boolean(:spam)
271
- end
272
-
273
- end
274
-
275
- context "typus_date_format" do
276
-
277
- should "accept strings" do
278
- assert_equal :default, Post.typus_date_format("unknown")
279
- end
280
-
281
- should "accept symbols" do
282
- assert_equal :default, Post.typus_date_format(:unknown)
283
- end
284
-
285
- should "return date_format for Post" do
286
- assert_equal :default, Post.typus_date_format
287
- assert_equal :short, Post.typus_date_format(:created_at)
288
- end
289
-
290
- end
291
-
292
- context "typus_template" do
293
-
294
- should "accept strings" do
295
- assert_equal "datepicker", Post.typus_template("published_at")
296
- end
297
-
298
- should "accept symbols" do
299
- assert_equal "datepicker", Post.typus_template(:published_at)
300
- end
301
-
302
- should "return nil if template does not exist" do
303
- assert_nil Post.typus_template(:created_at)
304
- end
305
-
306
- end
307
-
308
- context "typus_defaults_for" do
309
-
310
- should "accept strings" do
311
- assert_equal %w(title), Post.typus_defaults_for("search")
312
- end
313
-
314
- should "accepts symbols" do
315
- assert_equal %w(title), Post.typus_defaults_for(:search)
316
- end
317
-
318
- should "return default_for relationships on Post" do
319
- assert_equal %w(categories comments views), Post.typus_defaults_for(:relationships)
320
- end
321
-
322
- end
323
-
324
- context "typus_search_fields" do
325
-
326
- should "return a hash with the search modifiers" do
327
- search = ["=id", "^title", "body"]
328
- Post.stubs(:typus_defaults_for).with(:search).returns(search)
329
- expected = {"body"=>"@", "title"=>"^", "id"=>"="}
330
- assert_equal expected, Post.typus_search_fields
331
- end
332
-
333
- should "return and empty hash" do
334
- search = []
335
- Post.stubs(:typus_defaults_for).with(:search).returns(search)
336
- expected = {}
337
- assert_equal expected, Post.typus_search_fields
338
- end
339
-
340
- end
341
-
342
- context "typus_export_formats" do
343
-
344
- should "return post formats" do
345
- assert_equal ["csv", "xml"], Post.typus_export_formats
346
- end
347
-
348
- end
349
-
350
- context "typus_order_by" do
351
-
352
- should "return defaults_for order_by on Post" do
353
- assert_equal "posts.title ASC, posts.created_at DESC", Post.typus_order_by
354
- assert_equal %w(title -created_at), Post.typus_defaults_for(:order_by)
355
- end
356
-
357
- end
358
-
359
- context "typus_user_id?" do
360
-
361
- should "exist on Post" do
362
- assert Post.typus_user_id?
363
- end
364
-
365
- should "not exist on TypusUser" do
366
- assert !TypusUser.typus_user_id?
367
- end
368
-
369
- end
370
-
371
- context "read_model_config" do
372
-
373
- should "return data for existing model" do
374
- expected = {"application"=>"CRUD Extended",
375
- "fields"=>{"default"=>"caption, dragonfly, dragonfly_required",
376
- "special"=>"caption, dragonfly, dragonfly_required, original_file_name",
377
- "form"=>"caption, dragonfly, dragonfly_required, paperclip, paperclip_required, original_file_name",
378
- "new"=>"dragonfly, dragonfly_required, paperclip, paperclip_required"}}
379
- assert_equal expected, Asset.read_model_config
380
- end
381
-
382
- should "raise error when model does not exist on configuration" do
383
- assert_raises RuntimeError do
384
- Article.read_model_config
385
- end
386
- end
387
-
388
- end
389
-
390
- end