-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
application_helper_spec.rb
114 lines (89 loc) · 3.11 KB
/
application_helper_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require "rails_helper"
RSpec.describe Administrate::ApplicationHelper do
describe "#display_resource_name" do
it "defaults to the plural of the model name" do
displayed = display_resource_name(:customer)
expect(displayed).to eq("Customers")
end
it "can return singular of the model name" do
displayed = display_resource_name(:customer, singular: true)
expect(displayed).to eq("Customer")
end
it "handles string arguments" do
displayed = display_resource_name("customer")
expect(displayed).to eq("Customers")
end
it "handles plural arguments" do
displayed = display_resource_name(:customers)
expect(displayed).to eq("Customers")
end
it "handles namespaced resources" do
displayed = display_resource_name("blog/posts")
expect(displayed).to eq("Blog Posts")
end
context "when translations are defined" do
let(:translations) do
{
activerecord: {
models: {
customer: {
one: "User",
other: "Users",
},
},
},
}
end
it "uses the plural of the defined translation as default" do
with_translations(:en, translations) do
displayed = display_resource_name(:customer)
expect(displayed).to eq("Users")
end
end
it "uses the singular of the defined translation" do
with_translations(:en, translations) do
displayed = display_resource_name(:customer, singular: true)
expect(displayed).to eq("User")
end
end
end
context "using custom dashboards" do
it "pluralizes the resource name" do
displayed = display_resource_name("stat")
expect(displayed).to eq("Stats")
end
it "handles plural arguments" do
displayed = display_resource_name(:stats)
expect(displayed).to eq("Stats")
end
end
end
describe "#requireness" do
let(:page) do
Administrate::Page::Form.new(ProductDashboard.new, Product.new)
end
it "returns 'required' if field is required" do
name = page.attributes.detect { |i| i.attribute == :name }
expect(requireness(name)).to eq("required")
end
it "returns 'optional' if field is not required" do
release_year = page.attributes.detect { |i| i.attribute == :release_year }
expect(requireness(release_year)).to eq("optional")
end
it "returns 'optional' if field is required if condition is met" do
description = page.attributes.detect { |i| i.attribute == :description }
expect(requireness(description)).to eq("optional")
end
it "returns 'optional' if field is required unless condition is met" do
price = page.attributes.detect { |i| i.attribute == :price }
expect(requireness(price)).to eq("optional")
end
end
describe "#sort_order" do
it "sanitizes to ascending/descending/none" do
expect(sort_order("asc")).to eq("ascending")
expect(sort_order("desc")).to eq("descending")
expect(sort_order("for anything else")).to eq("none")
end
end
end