admin_it 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +6 -0
- data/lib/admin_it/context/collection_context.rb +5 -22
- data/lib/admin_it/context/context.rb +13 -34
- data/lib/admin_it/context/show_context.rb +8 -7
- data/lib/admin_it/context/single_context.rb +35 -33
- data/lib/admin_it/context/table_context.rb +18 -11
- data/lib/admin_it/context/tiles_context.rb +14 -14
- data/lib/admin_it/data/active_record.rb +0 -2
- data/lib/admin_it/field/field.rb +95 -23
- data/lib/admin_it/filters/field_filter.rb +4 -0
- data/lib/admin_it/filters/filter.rb +37 -14
- data/lib/admin_it/helpers/table.rb +13 -17
- data/lib/admin_it/resource.rb +58 -115
- data/lib/admin_it/shared.rb +64 -0
- data/lib/admin_it/version.rb +1 -1
- data/lib/admin_it.rb +7 -5
- data/lib/extend_it/array_of.rb +3 -3
- data/lib/extend_it/asserts.rb +5 -3
- data/lib/extend_it/{class.rb → base.rb} +29 -10
- data/lib/extend_it/callbacks.rb +7 -7
- data/lib/extend_it/config.rb +30 -0
- data/lib/extend_it/dsl.rb +223 -64
- data/lib/extend_it/ensures.rb +193 -0
- data/lib/extend_it.rb +1 -1
- data/spec/extend_it/config_spec.rb +52 -0
- data/spec/extend_it/dsl_spec.rb +149 -0
- data/spec/extend_it/ensures_spec.rb +39 -0
- data/spec/lib/context/collection_context_spec.rb +4 -2
- data/spec/lib/context/context_spec.rb +3 -1
- data/spec/lib/context/single_context_spec.rb +3 -2
- data/spec/lib/data/object_spec.rb +2 -2
- data/spec/lib/field_spec.rb +1 -56
- data/spec/lib/resource_spec.rb +1 -13
- data/spec/spec_helper.rb +7 -0
- data/spec/support/example_groups/context_example_group.rb +3 -3
- metadata +14 -11
- data/lib/admin_it/renderable.rb +0 -18
- data/lib/extend_it/refines.rb +0 -6
- data/lib/extend_it/symbolize.rb +0 -39
- data/spec/lib/definitions_spec.rb +0 -171
- data/spec/lib/utils_spec.rb +0 -39
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AdminIt::ResourceDefinition do
|
4
|
-
subject { described_class.new(object_resource) }
|
5
|
-
|
6
|
-
it 'delegates methods to fake context' do
|
7
|
-
subject.field :name
|
8
|
-
expect(
|
9
|
-
subject.instance_variable_get(:@fake).find_field(:name)
|
10
|
-
).to_not be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#default_context' do
|
14
|
-
it 'returns first single context name by default' do
|
15
|
-
subject.contexts(%i(tiles edit table))
|
16
|
-
expect(subject.default_context).to eq :edit
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'drops unknown context name' do
|
20
|
-
subject.default_context(:test)
|
21
|
-
expect(subject.default_context).to eq :show
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'sets known context name' do
|
25
|
-
subject.default_context(:table)
|
26
|
-
expect(subject.default_context).to eq :table
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#icon' do
|
31
|
-
it 'has nil icon by default' do
|
32
|
-
expect(subject.icon).to be_nil
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'sets icon as string' do
|
36
|
-
subject.icon :test
|
37
|
-
expect(subject.icon).to eq 'test'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#single' do
|
42
|
-
it { expect(subject.single <= AdminIt::SingleContext).to be_true }
|
43
|
-
|
44
|
-
it 'copies fields from fake context' do
|
45
|
-
subject.field :name
|
46
|
-
expect(subject.single.fields[:name]).to_not be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'yields block in single instance context' do
|
50
|
-
expect(subject.single).to receive(:instance_eval)
|
51
|
-
subject.single { }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#collection' do
|
56
|
-
it { expect(subject.collection <= AdminIt::CollectionContext).to be_true }
|
57
|
-
|
58
|
-
it 'copies fields from single context' do
|
59
|
-
subject.field :name
|
60
|
-
expect(subject.collection.find_field(:name)).to_not be_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'yields block in collection instance context' do
|
64
|
-
expect(subject.collection).to receive(:instance_eval)
|
65
|
-
subject.collection { }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#context' do
|
70
|
-
it 'yields block in context instance context' do
|
71
|
-
expect(subject.context(:edit)).to receive(:instance_eval)
|
72
|
-
subject.context(:edit) { }
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'creates context on-demand' do
|
76
|
-
subject.context :test, context_class: AdminIt::TilesContext
|
77
|
-
expect(subject.contexts.map(&:context_name)).to include :test
|
78
|
-
expect(subject.context(:test) <= AdminIt::TilesContext).to be_true
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'with some fields' do
|
82
|
-
before do
|
83
|
-
subject.field :name
|
84
|
-
subject.single { field :amount }
|
85
|
-
subject.collection { field :size }
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'copies fields from single fake context for singles' do
|
89
|
-
subject.context(:edit) { field :title }
|
90
|
-
expect(subject.context(:edit).fields[:title]).to_not be_nil
|
91
|
-
expect(subject.context(:edit).fields[:name]).to_not be_nil
|
92
|
-
expect(subject.context(:edit).fields[:amount]).to_not be_nil
|
93
|
-
expect(subject.context(:edit).fields[:size]).to be_nil
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'copies fields from collection fake context for collections' do
|
97
|
-
subject.context(:table) { field :rows }
|
98
|
-
expect(subject.context(:table).fields[:rows]).to_not be_nil
|
99
|
-
expect(subject.context(:table).fields[:amount]).to be_nil
|
100
|
-
expect(subject.context(:table).fields[:name]).to_not be_nil
|
101
|
-
expect(subject.context(:table).fields[:size]).to_not be_nil
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'copies fields from single fake context for on-demand singles' do
|
105
|
-
subject.context :test, context_class: AdminIt::EditContext do
|
106
|
-
field :title
|
107
|
-
end
|
108
|
-
expect(subject.context(:test).fields[:title]).to_not be_nil
|
109
|
-
expect(subject.context(:test).fields[:name]).to_not be_nil
|
110
|
-
expect(subject.context(:test).fields[:amount]).to_not be_nil
|
111
|
-
expect(subject.context(:test).fields[:size]).to be_nil
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'copies fields from col fake context for on-demand collections' do
|
115
|
-
subject.context :test, context_class: AdminIt::TableContext do
|
116
|
-
field :rows
|
117
|
-
end
|
118
|
-
expect(subject.context(:test).fields[:rows]).to_not be_nil
|
119
|
-
expect(subject.context(:test).fields[:name]).to_not be_nil
|
120
|
-
expect(subject.context(:test).fields[:amount]).to be_nil
|
121
|
-
expect(subject.context(:test).fields[:size]).to_not be_nil
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#contexts' do
|
127
|
-
it 'yields block in each context instance context' do
|
128
|
-
subject.contexts.each { |c| expect(c).to receive(:instance_eval) }
|
129
|
-
subject.contexts { }
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'reorders contexts' do
|
133
|
-
list = %i(list tiles show table edit new)
|
134
|
-
subject.contexts(*list)
|
135
|
-
expect(subject.contexts.map(&:context_name)).to eq list
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'reduces contexts' do
|
139
|
-
subject.contexts(:tiles, :table)
|
140
|
-
expect(subject.contexts.size).to eq 2
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#exclude_collection' do
|
145
|
-
it 'removes all collection contexts' do
|
146
|
-
subject.exclude_collection
|
147
|
-
expect(subject.contexts.map(&:context_name))
|
148
|
-
.to eq described_class::SINGLE
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#exclude_single' do
|
153
|
-
it 'removes all single contexts' do
|
154
|
-
subject.exclude_single
|
155
|
-
expect(subject.contexts.map(&:context_name))
|
156
|
-
.to eq described_class::COLLECTIONS
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#exclude_context' do
|
161
|
-
it 'removes contexts' do
|
162
|
-
subject.exclude_context(%i(show edit new table))
|
163
|
-
expect(subject.contexts.map(&:context_name)).to eq %i(tiles list)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe AdminIt do
|
169
|
-
describe '.resource' do
|
170
|
-
end
|
171
|
-
end
|
data/spec/lib/utils_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AdminIt::Utils do
|
4
|
-
subject { AdminIt::Utils }
|
5
|
-
|
6
|
-
describe '.assert_symbol_arg' do
|
7
|
-
it 'just passes throw symbol args' do
|
8
|
-
expect(subject.assert_symbol_arg(:test)).to eq :test
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'converts string to symbol' do
|
12
|
-
expect(subject.assert_symbol_arg('test')).to eq :test
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'calls block if it given for non-symbol args' do
|
16
|
-
test = false
|
17
|
-
subject.assert_symbol_arg(10) { |value| test = value }
|
18
|
-
expect(test).to eq 10
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '.assert_symbol_arg!' do
|
23
|
-
def some_method(name)
|
24
|
-
subject.assert_symbol_arg!(10, name)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'calls .assert_symbol_arg' do
|
28
|
-
expect(subject).to receive(:assert_symbol_arg).with(:test)
|
29
|
-
subject.assert_symbol_arg!(:test, name: 'name')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'raises ArgumentError for wrong args' do
|
33
|
-
expect { some_method('arg') }.to raise_error(
|
34
|
-
ArgumentError,
|
35
|
-
'Argument arg for some_method should be a String or Symbol'
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|