wedge 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -1
- data/Makefile +2 -0
- data/Rakefile +8 -4
- data/TODO.md +4 -0
- data/lib/roda/plugins/wedge.rb +14 -96
- data/lib/wedge.rb +9 -4
- data/lib/wedge/component.rb +70 -29
- data/lib/wedge/config.rb +36 -6
- data/lib/wedge/middleware.rb +43 -35
- data/lib/wedge/opal.rb +15 -4
- data/lib/wedge/plugins/ability_list.rb +95 -0
- data/lib/wedge/plugins/current_user.rb +48 -0
- data/lib/wedge/plugins/factory.rb +36 -0
- data/lib/wedge/plugins/form.rb +216 -343
- data/lib/wedge/plugins/{validations.rb → form/validations.rb} +64 -37
- data/lib/wedge/plugins/form_backup.rb +442 -0
- data/lib/wedge/plugins/render.rb +110 -0
- data/lib/wedge/plugins/uploader.rb +2 -2
- data/lib/wedge/utilis/duplicable.rb +104 -0
- data/lib/wedge/utilis/hash.rb +48 -0
- data/lib/wedge/version.rb +1 -1
- data/playground/app/app.rb +27 -11
- data/playground/app/components/abilities.rb +11 -0
- data/playground/app/components/current_user.rb +12 -0
- data/playground/app/components/layout.rb +5 -0
- data/playground/app/components/todo_list.rb +24 -0
- data/playground/app/config/boot.rb +3 -0
- data/playground/app/forms/todo_list_add.rb +9 -0
- data/playground/app/models/user.rb +5 -0
- data/playground/public/css/styles.css +139 -0
- data/playground/public/css/todo_list.css +138 -0
- data/playground/public/todo_list.html +23 -0
- data/playground/src/css/styles.scss +2 -1
- data/playground/src/css/todo_list.scss +165 -0
- data/playground/src/todo_list.slim +17 -0
- data/spec/playground/uploader_spec.rb +27 -29
- data/spec/spec_helper.rb +29 -0
- data/spec/stubs/models/user.rb +15 -0
- data/spec/wedge/plugins/current_user_spec.rb +29 -0
- data/spec/wedge/plugins/factory_spec.rb +16 -0
- data/spec/wedge/plugins/form_spec.rb +119 -0
- data/spec/wedge/plugins/uploader_spec.rb +1 -3
- data/spec/wedge_spec.rb +3 -3
- metadata +28 -3
@@ -0,0 +1,17 @@
|
|
1
|
+
.container
|
2
|
+
h1#title Today’s Goals
|
3
|
+
p#notice.hidden You have no goals for today.
|
4
|
+
ul#list
|
5
|
+
li
|
6
|
+
| Buy apples
|
7
|
+
button.delete Delete
|
8
|
+
li
|
9
|
+
| Buy bananas
|
10
|
+
button.delete Delete
|
11
|
+
li
|
12
|
+
| Eat apples and bananas
|
13
|
+
button.delete Delete
|
14
|
+
form#add-form
|
15
|
+
textarea#task-input name="todo[description]" placeholder=("Enter new goal here") rows="1"
|
16
|
+
button#add Add to list
|
17
|
+
/! .container
|
@@ -2,33 +2,31 @@ require 'spec_helper'
|
|
2
2
|
require 'components/uploader'
|
3
3
|
|
4
4
|
describe 'Playground::UploaderComponent' do
|
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
|
-
# end
|
33
|
-
# end if Wedge.client?
|
5
|
+
subject(:uploader) { Wedge[:uploader] }
|
6
|
+
|
7
|
+
html Wedge.html! { button 'Upload' }.to_html
|
8
|
+
|
9
|
+
context '#display' do
|
10
|
+
subject { uploader.display }
|
11
|
+
|
12
|
+
if Wedge.server?
|
13
|
+
it { is_expected.to be_a Wedge::DOM }
|
14
|
+
else
|
15
|
+
it { is_expected.to be_nil }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'browser_events' do
|
20
|
+
before do
|
21
|
+
allow_any_instance_of(Wedge::Plugins::Uploader).to receive(:settings).and_return({
|
22
|
+
aws_access_key_id: 123456,
|
23
|
+
bucket: 'wedge'
|
24
|
+
})
|
25
|
+
uploader.trigger :browser_events
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have fine uploader button' do
|
29
|
+
expect(uploader.dom.find('.qq-uploader').to_html).not_to be_empty
|
30
|
+
end
|
31
|
+
end if Wedge.client?
|
34
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ if RUBY_ENGINE == 'opal'
|
|
4
4
|
require 'opal/rspec'
|
5
5
|
require 'opal/jquery/rspec'
|
6
6
|
else
|
7
|
+
require 'rspec'
|
7
8
|
|
8
9
|
ENV['RACK_ENV'] ||= 'test'
|
9
10
|
|
@@ -19,7 +20,35 @@ else
|
|
19
20
|
RSpec.configure do |c|
|
20
21
|
c.extend RSpecHelpers
|
21
22
|
c.filter_run_excluding :slow
|
23
|
+
c.color = true
|
24
|
+
# c.before do
|
25
|
+
# allow(Playground::User).to receive(:find) do |id|
|
26
|
+
# if id == 1
|
27
|
+
# {id: 1, first_name: 'Test', last_name: 'Admin', is_admin: true}
|
28
|
+
# else
|
29
|
+
# nil
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
22
33
|
end
|
23
34
|
|
24
35
|
require 'config/boot'
|
36
|
+
|
37
|
+
Dir["./spec/stubs/**/*.rb"].sort.each { |file| require file }
|
38
|
+
|
39
|
+
Wedge.plugin(:factory)
|
40
|
+
user = HashObject.new(
|
41
|
+
first_name: 'moo',
|
42
|
+
last_name: 'cow',
|
43
|
+
location: {
|
44
|
+
address: HashObject.new(
|
45
|
+
line1: 'The fields',
|
46
|
+
city: 'milkton',
|
47
|
+
state: 'texas',
|
48
|
+
zip: 40004
|
49
|
+
)
|
50
|
+
}
|
51
|
+
)
|
52
|
+
|
53
|
+
Wedge[:factory].stub user, :user, location: [:address]
|
25
54
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wedge/plugins/current_user'
|
3
|
+
|
4
|
+
class TestComponent < Wedge::Component
|
5
|
+
name :test
|
6
|
+
|
7
|
+
def display
|
8
|
+
if current_user.can? :view, :admin
|
9
|
+
'admin'
|
10
|
+
else
|
11
|
+
'user'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Wedge::Plugins::CurrentUser do
|
17
|
+
let(:test_comp) { Wedge[:test] }
|
18
|
+
let(:current_user) { Wedge[:current_user_plugin].current_user }
|
19
|
+
|
20
|
+
context 'admin' do
|
21
|
+
it 'expects to be an admin' do
|
22
|
+
expect(test_comp.display).to eq 'admin'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'secret_key' do
|
26
|
+
expect(current_user.secret_key).to eq(Wedge.server?? 123456 : nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wedge/plugins/factory'
|
3
|
+
|
4
|
+
describe Wedge::Plugins::Factory do
|
5
|
+
let(:user_stub) { Wedge[:factory][:user].to_h }
|
6
|
+
|
7
|
+
it 'expects the correct fields returned' do
|
8
|
+
expect(user_stub.keys).to include *%w'first_name last_name location'
|
9
|
+
expect(user_stub[:location][:address].keys).to include 'line1'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts override params' do
|
13
|
+
data = Wedge[:factory][:user, api_key: 123456].to_h
|
14
|
+
expect(data.keys).to include 'api_key'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wedge/plugins/form'
|
3
|
+
|
4
|
+
class TestForm < Wedge::Plugins::Form
|
5
|
+
name :test_form
|
6
|
+
|
7
|
+
attr_reader :id, type: Integer, default: '1'
|
8
|
+
attr_reader :type, type: Symbol, default: -> { id == 1 ? 'admin' : 'user' }
|
9
|
+
attr_reader :zipcode
|
10
|
+
|
11
|
+
attr_accessor :first_name, :last_name
|
12
|
+
attr_accessor :phone_number, type: Integer
|
13
|
+
attr_accessor :user_only, default: true, unless: -> { current_user.admin? }
|
14
|
+
attr_accessor :email, hidden: true
|
15
|
+
|
16
|
+
model_alias :phone_num, :phone_number
|
17
|
+
|
18
|
+
form_accessor :car
|
19
|
+
|
20
|
+
def validate
|
21
|
+
assert_present %w'first_name last_name'
|
22
|
+
assert_numeric :phone_number
|
23
|
+
assert_form :car
|
24
|
+
end
|
25
|
+
|
26
|
+
def full_name
|
27
|
+
"#{first_name} #{last_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def phone_number= number
|
31
|
+
super(number.gsub(/[^\d]/, ''))
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_zipcode
|
35
|
+
55555
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class TestLimitForm < TestForm
|
40
|
+
name :test_limit_form
|
41
|
+
form_accessor :car, atts: %w'make model'
|
42
|
+
end
|
43
|
+
|
44
|
+
class CarForm < Wedge::Plugins::Form
|
45
|
+
name :car_form
|
46
|
+
|
47
|
+
attr_reader :id, default: 1
|
48
|
+
attr_accessor :make, :model, :vin, :year
|
49
|
+
|
50
|
+
def validate
|
51
|
+
assert_present %w'make model vin year'
|
52
|
+
assert_length :vin, 17
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_year
|
56
|
+
Time.now.year
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe Wedge::Plugins::Form do
|
61
|
+
let(:params) {{
|
62
|
+
id: 5, first_name: 'CJ', last_name: 'Lazell', phone_num: '(555) 555 - 5555',
|
63
|
+
car: {
|
64
|
+
make: 'ford', model: 'focus', vin: '12121212121212121'
|
65
|
+
}
|
66
|
+
}}
|
67
|
+
subject(:test_form) { Wedge[:test_form, params] }
|
68
|
+
|
69
|
+
context 'attributes' do
|
70
|
+
subject(:attributes) { test_form.attributes }
|
71
|
+
|
72
|
+
# id is 1 because values that are attr_readers can't be set via passed in
|
73
|
+
# params, this stops people updating values they shouldn't and is why you
|
74
|
+
# should always use a form to filter param data before passing it to a model.
|
75
|
+
it { is_expected.to include({
|
76
|
+
id: 1, first_name: 'CJ', last_name: 'Lazell', phone_number: 5555555555, zipcode: 55555
|
77
|
+
})}
|
78
|
+
it { is_expected.not_to have_key :full_name }
|
79
|
+
it { is_expected.not_to have_key :email }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'model_attributes' do
|
83
|
+
subject(:attributes) { test_form.model_attributes }
|
84
|
+
|
85
|
+
it { is_expected.not_to have_key :phone_number }
|
86
|
+
it { is_expected.to have_key :phone_num }
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'validation errors' do
|
90
|
+
subject { form = Wedge[:test_form]; form.valid?; form.errors }
|
91
|
+
|
92
|
+
it { is_expected.to include({
|
93
|
+
first_name: [:not_present], last_name: [:not_present],
|
94
|
+
:car => {
|
95
|
+
make: [:not_present], model: [:not_present], vin: [:not_present]
|
96
|
+
}
|
97
|
+
}) }
|
98
|
+
|
99
|
+
it { is_expected.not_to include phone_number: [:not_numeric] }
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'limit form validation' do
|
103
|
+
subject { form = Wedge[:test_limit_form]; form.valid?; form.errors }
|
104
|
+
|
105
|
+
it { is_expected.to include({
|
106
|
+
:car => {
|
107
|
+
make: [:not_present], model: [:not_present]
|
108
|
+
}
|
109
|
+
})}
|
110
|
+
|
111
|
+
it { is_expected.not_to include vin: [:not_present] }
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'block#current_user' do
|
115
|
+
it 'should not have access to user_only' do
|
116
|
+
expect(test_form.user_only).to be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -21,9 +21,7 @@ describe Wedge::Plugins::Uploader do
|
|
21
21
|
if Wedge.server?
|
22
22
|
expect(settings.keys).to include *%w'aws_access_key_id aws_secret_access_key bucket'
|
23
23
|
else
|
24
|
-
|
25
|
-
# ran server side first.
|
26
|
-
# expect(settings).to be_nil
|
24
|
+
expect(settings.keys).not_to include *%w'aws_secret_access_key'
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
data/spec/wedge_spec.rb
CHANGED
@@ -12,9 +12,9 @@ describe Wedge do
|
|
12
12
|
expect(Wedge.source_map).to match /mappings/
|
13
13
|
end
|
14
14
|
else
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
it 'should not have an assets key' do
|
16
|
+
expect(Wedge.config.assets_key).not_to be_nil
|
17
|
+
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wedge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -160,8 +160,10 @@ files:
|
|
160
160
|
- ".gitignore"
|
161
161
|
- Gemfile
|
162
162
|
- LICENSE.txt
|
163
|
+
- Makefile
|
163
164
|
- README.md
|
164
165
|
- Rakefile
|
166
|
+
- TODO.md
|
165
167
|
- lib/roda/plugins/wedge.rb
|
166
168
|
- lib/wedge.rb
|
167
169
|
- lib/wedge/component.rb
|
@@ -171,14 +173,20 @@ files:
|
|
171
173
|
- lib/wedge/html.rb
|
172
174
|
- lib/wedge/middleware.rb
|
173
175
|
- lib/wedge/opal.rb
|
176
|
+
- lib/wedge/plugins/ability_list.rb
|
177
|
+
- lib/wedge/plugins/current_user.rb
|
178
|
+
- lib/wedge/plugins/factory.rb
|
174
179
|
- lib/wedge/plugins/form.rb
|
180
|
+
- lib/wedge/plugins/form/validations.rb
|
181
|
+
- lib/wedge/plugins/form_backup.rb
|
175
182
|
- lib/wedge/plugins/history.rb
|
176
183
|
- lib/wedge/plugins/location.rb
|
177
184
|
- lib/wedge/plugins/pjax.rb
|
185
|
+
- lib/wedge/plugins/render.rb
|
178
186
|
- lib/wedge/plugins/uploader.rb
|
179
|
-
- lib/wedge/plugins/validations.rb
|
180
187
|
- lib/wedge/require.rb
|
181
188
|
- lib/wedge/utilis/blank.rb
|
189
|
+
- lib/wedge/utilis/duplicable.rb
|
182
190
|
- lib/wedge/utilis/element.rb
|
183
191
|
- lib/wedge/utilis/hash.rb
|
184
192
|
- lib/wedge/utilis/indifferent_hash.rb
|
@@ -189,11 +197,16 @@ files:
|
|
189
197
|
- lib/wedge/version.rb
|
190
198
|
- playground/Gruntfile.coffee
|
191
199
|
- playground/app/app.rb
|
200
|
+
- playground/app/components/abilities.rb
|
201
|
+
- playground/app/components/current_user.rb
|
192
202
|
- playground/app/components/index.rb
|
193
203
|
- playground/app/components/layout.rb
|
204
|
+
- playground/app/components/todo_list.rb
|
194
205
|
- playground/app/components/uploader.rb
|
195
206
|
- playground/app/config/boot.rb
|
196
207
|
- playground/app/config/variables.rb
|
208
|
+
- playground/app/forms/todo_list_add.rb
|
209
|
+
- playground/app/models/user.rb
|
197
210
|
- playground/backup/components/bar.rb
|
198
211
|
- playground/backup/components/base.rb
|
199
212
|
- playground/backup/components/layout.rb
|
@@ -207,8 +220,10 @@ files:
|
|
207
220
|
- playground/package.json
|
208
221
|
- playground/public/css/styles.css
|
209
222
|
- playground/public/css/styles.css.map
|
223
|
+
- playground/public/css/todo_list.css
|
210
224
|
- playground/public/includes/_head.html
|
211
225
|
- playground/public/index.html
|
226
|
+
- playground/public/todo_list.html
|
212
227
|
- playground/public/uploader.html
|
213
228
|
- playground/public/vendor/fine-uploader/s3.jquery.fine-uploader.js
|
214
229
|
- playground/public/vendor/font-awesome/fonts/FontAwesome.otf
|
@@ -223,14 +238,20 @@ files:
|
|
223
238
|
- playground/src/css/_variables.scss
|
224
239
|
- playground/src/css/addons/_buttons.scss
|
225
240
|
- playground/src/css/styles.scss
|
241
|
+
- playground/src/css/todo_list.scss
|
226
242
|
- playground/src/includes/_head.slim
|
227
243
|
- playground/src/index.slim
|
244
|
+
- playground/src/todo_list.slim
|
228
245
|
- playground/src/uploader.slim
|
229
246
|
- spec/index.html.erb
|
230
247
|
- spec/playground/layout_spec.rb
|
231
248
|
- spec/playground/uploader_spec.rb
|
232
249
|
- spec/spec_helper.rb
|
250
|
+
- spec/stubs/models/user.rb
|
233
251
|
- spec/wedge/component_spec.rb
|
252
|
+
- spec/wedge/plugins/current_user_spec.rb
|
253
|
+
- spec/wedge/plugins/factory_spec.rb
|
254
|
+
- spec/wedge/plugins/form_spec.rb
|
234
255
|
- spec/wedge/plugins/uploader_spec.rb
|
235
256
|
- spec/wedge_spec.rb
|
236
257
|
- wedge.gemspec
|
@@ -263,7 +284,11 @@ test_files:
|
|
263
284
|
- spec/playground/layout_spec.rb
|
264
285
|
- spec/playground/uploader_spec.rb
|
265
286
|
- spec/spec_helper.rb
|
287
|
+
- spec/stubs/models/user.rb
|
266
288
|
- spec/wedge/component_spec.rb
|
289
|
+
- spec/wedge/plugins/current_user_spec.rb
|
290
|
+
- spec/wedge/plugins/factory_spec.rb
|
291
|
+
- spec/wedge/plugins/form_spec.rb
|
267
292
|
- spec/wedge/plugins/uploader_spec.rb
|
268
293
|
- spec/wedge_spec.rb
|
269
294
|
has_rdoc:
|