fron 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/Rakefile +18 -0
- data/docs/configuration.md +8 -8
- data/lib/fron/version.rb +1 -1
- data/opal/fron/core.rb +1 -1
- data/opal/fron/core/adapters/{local-storage.rb → local.rb} +7 -6
- data/opal/fron/core/application.rb +13 -11
- data/opal/fron/core/configuration.rb +3 -4
- data/opal/fron/core/controller.rb +2 -2
- data/opal/fron/core/eventable.rb +5 -2
- data/opal/fron/core/logger.rb +7 -0
- data/opal/fron/core/model.rb +10 -8
- data/opal/fron/core/router.rb +1 -1
- data/opal/fron/dom.rb +1 -0
- data/opal/fron/dom/document.rb +4 -0
- data/opal/fron/dom/element.rb +22 -6
- data/opal/fron/dom/event.rb +71 -68
- data/opal/fron/dom/fragment.rb +1 -3
- data/opal/fron/dom/modules/classlist.rb +2 -2
- data/opal/fron/dom/modules/dimensions.rb +7 -8
- data/opal/fron/dom/modules/events.rb +57 -12
- data/opal/fron/dom/node.rb +45 -11
- data/opal/fron/dom/nodelist.rb +14 -0
- data/opal/fron/dom/style.rb +17 -15
- data/opal/fron/dom/text.rb +2 -4
- data/opal/fron/dom/window.rb +2 -3
- data/opal/fron/request/request.rb +17 -14
- data/opal/fron/storage/local-storage.rb +29 -13
- data/spec/core-ext/hash_spec.rb +18 -0
- data/spec/core/adapter/local_spec.rb +65 -0
- data/spec/core/adapter/rails_spec.rb +72 -0
- data/spec/core/application_spec.rb +35 -0
- data/spec/core/component_spec.rb +107 -0
- data/spec/core/configuration_spec.rb +20 -0
- data/spec/core/controlller_spec.rb +68 -0
- data/spec/core/eventable_spec.rb +74 -0
- data/spec/core/logger_spec.rb +28 -0
- data/spec/core/model_spec.rb +125 -0
- data/spec/core/router_spec.rb +127 -0
- data/spec/dom/document_spec.rb +41 -0
- data/spec/dom/element_spec.rb +164 -0
- data/spec/dom/event_spec.rb +121 -0
- data/spec/dom/fragment_spec.rb +13 -0
- data/spec/dom/modules/classlist_spec.rb +72 -0
- data/spec/dom/modules/dimensions_spec.rb +55 -0
- data/spec/dom/modules/events_spec.rb +73 -0
- data/spec/dom/node_spec.rb +189 -0
- data/spec/dom/nodelist_spec.rb +12 -0
- data/spec/dom/style_spec.rb +31 -0
- data/spec/dom/text_spec.rb +12 -0
- data/spec/dom/window_spec.rb +30 -0
- data/spec/request/request_spec.rb +71 -0
- data/spec/request/response_spec.rb +46 -0
- data/spec/storage/local-storage_spec.rb +58 -0
- metadata +36 -4
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
require 'fron/storage'
|
3
|
+
|
4
|
+
describe Fron::Adapters::RailsAdapter do
|
5
|
+
|
6
|
+
subject do
|
7
|
+
described_class.new({
|
8
|
+
fields: [:name],
|
9
|
+
endpoint: "test",
|
10
|
+
resources: "users",
|
11
|
+
resource: "user"
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:proc) { Proc.new {} }
|
16
|
+
let(:request) { double :request }
|
17
|
+
|
18
|
+
before do
|
19
|
+
subject.instance_variable_set "@request", request
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#all" do
|
23
|
+
it "should call GET request to resources url" do
|
24
|
+
request.should receive(:url=).with "test/users.json"
|
25
|
+
request.should receive(:get) do |&block|
|
26
|
+
block.call double json: true
|
27
|
+
end
|
28
|
+
proc.should receive(:call)
|
29
|
+
subject.all &proc
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#get" do
|
34
|
+
it "should call GET request to resource url" do
|
35
|
+
request.should receive(:url=).with "test/users/0"
|
36
|
+
request.should receive(:get) do |&block|
|
37
|
+
block.call double json: true
|
38
|
+
end
|
39
|
+
proc.should receive(:call)
|
40
|
+
subject.get '0', &proc
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#set" do
|
45
|
+
it "should call POST request for new record" do
|
46
|
+
request.should receive(:url=).with "test/users.json"
|
47
|
+
request.should receive(:post) do |&block|
|
48
|
+
block.call double status: 201
|
49
|
+
end
|
50
|
+
proc.should receive(:call)
|
51
|
+
subject.set nil, {}, &proc
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should call PUT request for exsistsing record" do
|
55
|
+
request.should receive(:url=).with "test/users/0"
|
56
|
+
request.should receive(:put) do |&block|
|
57
|
+
block.call double status: 201
|
58
|
+
end
|
59
|
+
proc.should receive(:call)
|
60
|
+
subject.set 0, {}, &proc
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should call block with error" do
|
64
|
+
request.should receive(:url=).with "test/users/0"
|
65
|
+
request.should receive(:put) do |&block|
|
66
|
+
block.call double status: 422, json: 'error'
|
67
|
+
end
|
68
|
+
proc.should receive(:call).with 'error'
|
69
|
+
subject.set 0, {}, &proc
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class TestApplication < Fron::Application
|
4
|
+
config.title = 'Test Application'
|
5
|
+
config.logger.level = :error
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Fron::Application do
|
9
|
+
|
10
|
+
subject { TestApplication.new }
|
11
|
+
|
12
|
+
after do
|
13
|
+
subject.config.app.remove!
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it 'should insert the application into the DOM' do
|
18
|
+
subject.config.app.parent.should_not be nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should set the title of the document' do
|
22
|
+
DOM::Document.title.should eq 'Test Application'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#loadExternalStylesheets" do
|
27
|
+
it 'should load external stylesheets' do
|
28
|
+
subject.config.stylesheets = ['test']
|
29
|
+
subject.send(:loadExternalStylesheets)
|
30
|
+
link = DOM::Document.head.find('link')
|
31
|
+
link['href'].should be 'test'
|
32
|
+
link.remove!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class TestComponent < Fron::Component
|
4
|
+
attr_reader :rendered
|
5
|
+
|
6
|
+
def render
|
7
|
+
@rendered = true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Fron::Component do
|
12
|
+
|
13
|
+
subject { TestComponent.new }
|
14
|
+
let(:listeners) { subject.instance_variable_get("@listeners") }
|
15
|
+
|
16
|
+
describe "DSL" do
|
17
|
+
|
18
|
+
subject { TestComponent }
|
19
|
+
|
20
|
+
describe "#tag" do
|
21
|
+
it 'should set the tagname' do
|
22
|
+
subject.tag 'td'
|
23
|
+
subject.tagname.should eq 'td'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#on" do
|
28
|
+
it 'should create events array' do
|
29
|
+
subject.on :click, :test
|
30
|
+
subject.events.should_not be nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should push event into the events array' do
|
34
|
+
subject.on :click, :test
|
35
|
+
subject.events.length.should be 2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#component' do
|
40
|
+
it 'should create components array' do
|
41
|
+
subject.component :test, 'test'
|
42
|
+
subject.components.should_not be nil
|
43
|
+
subject.components.length.should be 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should create attr_reader for component' do
|
47
|
+
subject.component :a, 'a'
|
48
|
+
subject.instance_methods.include?(:a).should be true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#delegate' do
|
53
|
+
it 'should create delegated methods' do
|
54
|
+
subject.delegate :text, :test
|
55
|
+
subject.instance_methods.include?(:text).should be true
|
56
|
+
subject.instance_methods.include?(:text=).should be true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#initialize" do
|
62
|
+
it 'should create element' do
|
63
|
+
subject.tag.should eq 'td'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should apply events' do
|
67
|
+
listeners[:click].length.should eq 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should create components' do
|
71
|
+
subject.a.should_not be nil
|
72
|
+
subject.a.tag.should eq 'a'
|
73
|
+
|
74
|
+
subject.test.should_not be nil
|
75
|
+
subject.test.tag.should be 'test'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should call render if model given' do
|
79
|
+
comp = TestComponent.new(Fron::Model.new)
|
80
|
+
comp.rendered.should be true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#component" do
|
85
|
+
it 'should create a component from a Class' do
|
86
|
+
subject.component 'b', TestComponent
|
87
|
+
subject.instance_variable_get("@b").class.should eq TestComponent
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should create a component from a String' do
|
91
|
+
subject.component 'e', 'i'
|
92
|
+
subject.instance_variable_get("@e").class.should eq Fron::Component
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should append component' do
|
96
|
+
subject.component 'd', TestComponent
|
97
|
+
comp = subject.instance_variable_get("@d")
|
98
|
+
comp.parent.should eq subject
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should call block if block given' do
|
102
|
+
called = false
|
103
|
+
subject.component('c', 'x') { called = true }
|
104
|
+
called.should be true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'fron'
|
2
|
+
|
3
|
+
describe Fron::Configuration do
|
4
|
+
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'should create a logger' do
|
9
|
+
subject.logger.class.should be Fron::Logger
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should create the application container' do
|
13
|
+
subject.app.class.should be Fron::Configuration::App
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create the yield container' do
|
17
|
+
subject.main.class.should be Fron::Configuration::Yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class TestController < Fron::Controller
|
4
|
+
end
|
5
|
+
|
6
|
+
describe TestController do
|
7
|
+
|
8
|
+
subject { described_class.new }
|
9
|
+
|
10
|
+
describe 'DSL' do
|
11
|
+
|
12
|
+
subject { TestController }
|
13
|
+
|
14
|
+
describe '#base' do
|
15
|
+
it 'should set the baseComponent' do
|
16
|
+
subject.base Fron::Component
|
17
|
+
subject.baseComponent.should eq Fron::Component
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#route' do
|
22
|
+
it 'should set routes map' do
|
23
|
+
allow(Fron::Router).to receive(:map)
|
24
|
+
subject.route '/', :test
|
25
|
+
subject.routes.should_not be nil
|
26
|
+
subject.routes.length.should eq 1
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should call Router.map' do
|
30
|
+
expect(Fron::Router).to receive(:map).once
|
31
|
+
subject.route '/a', :a
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#on' do
|
36
|
+
it 'should set events array' do
|
37
|
+
subject.on :event, :action
|
38
|
+
subject.events.should_not be nil
|
39
|
+
subject.events[0].should eq({name: :event, action: :action})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#before' do
|
44
|
+
it 'should set before filters' do
|
45
|
+
subject.before :method, :action
|
46
|
+
subject.beforeFilters.should_not be nil
|
47
|
+
subject.beforeFilters[0].should eq({method: :method, actions: :action})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#initialize" do
|
53
|
+
it 'should create Element if no component is specified' do
|
54
|
+
TestController.base nil
|
55
|
+
subject.base.class.should eq DOM::Element
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should create component if component is specified' do
|
59
|
+
TestController.base Fron::Component
|
60
|
+
subject.base.class.should eq Fron::Component
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should call Eventable.on for event' do
|
64
|
+
expect(Fron::Eventable).to receive(:on).once.with 'event'
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class TestEventable
|
4
|
+
include Fron::Eventable
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Fron::Eventable do
|
8
|
+
|
9
|
+
subject { described_class }
|
10
|
+
let(:events) { subject.instance_variable_get("@events") }
|
11
|
+
let(:instance) { TestEventable.new }
|
12
|
+
|
13
|
+
describe "#on" do
|
14
|
+
it "should add to events array" do
|
15
|
+
subject.on 'event' do end
|
16
|
+
events.should_not be nil
|
17
|
+
events[:event].should_not be nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should add block to events array" do
|
21
|
+
a = Proc.new {}
|
22
|
+
subject.on 'event', &a
|
23
|
+
events[:event].last.should eq a
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#trigger" do
|
28
|
+
it "should not trigger global event if called on self" do
|
29
|
+
expect(subject).to receive(:trigger).once.and_call_original
|
30
|
+
subject.trigger 'test'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should trigger global event if specified and not self" do
|
34
|
+
expect(subject).to receive(:trigger).once.and_call_original
|
35
|
+
instance.on 'test' do end
|
36
|
+
instance.trigger 'test'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not trigger global event if not specified" do
|
40
|
+
expect(subject).not_to receive(:trigger)
|
41
|
+
instance.trigger 'test', false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should call listeners" do
|
45
|
+
a = Proc.new {}
|
46
|
+
expect(a).to receive(:call)
|
47
|
+
instance.on 'test', &a
|
48
|
+
instance.trigger 'test'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#off" do
|
53
|
+
it "should remove the block from the events array" do
|
54
|
+
block = subject.on 'test' do end
|
55
|
+
events['test'].last.should eq block
|
56
|
+
subject.off 'test', block
|
57
|
+
events['test'].last.should_not eq block
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should remove all corressponding events' do
|
61
|
+
subject.on 'test' do end
|
62
|
+
events['test'].length.should_not be 0
|
63
|
+
subject.off 'test'
|
64
|
+
events['test'].length.should be 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should remove all events' do
|
68
|
+
subject.on 'test' do end
|
69
|
+
events.keys.length.should eq 2
|
70
|
+
subject.off
|
71
|
+
events.keys.length.should eq 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
describe Fron::Logger do
|
4
|
+
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(subject).to receive(:puts)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
it 'should set log level to :info' do
|
13
|
+
subject.level.should eq :info
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#info" do
|
18
|
+
it "should add timestamp to message" do
|
19
|
+
expect(Time).to receive(:now).and_call_original
|
20
|
+
subject.info 'test'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should call puts" do
|
24
|
+
expect(subject).to receive(:puts).once
|
25
|
+
subject.info 'test'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class TestModel < Fron::Model
|
4
|
+
end
|
5
|
+
|
6
|
+
class MockAdapter
|
7
|
+
def all(&block)
|
8
|
+
block.call [{},{}]
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(&block)
|
12
|
+
block.call({name: 'User'})
|
13
|
+
end
|
14
|
+
|
15
|
+
def set(id,&block)
|
16
|
+
if id == 0
|
17
|
+
block.call
|
18
|
+
else
|
19
|
+
block.call({errors: true})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe TestModel do
|
25
|
+
|
26
|
+
subject { described_class }
|
27
|
+
|
28
|
+
describe "DSL" do
|
29
|
+
describe "#adapter" do
|
30
|
+
it "should set adapter" do
|
31
|
+
subject.adapter MockAdapter
|
32
|
+
subject.adapterObject.should_not be nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#field" do
|
37
|
+
it "should set fields array" do
|
38
|
+
subject.field :name
|
39
|
+
subject.fields.should_not be nil
|
40
|
+
subject.fields.should include(:name)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should define methods" do
|
44
|
+
subject.field :description
|
45
|
+
subject.instance_methods.should include(:description)
|
46
|
+
subject.instance_methods.should include(:description=)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Class Methods" do
|
52
|
+
describe "#all" do
|
53
|
+
it "should call adapter#call" do
|
54
|
+
subject.adapterObject.should receive(:all)
|
55
|
+
subject.all
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should call new on self class for items" do
|
59
|
+
subject.should receive(:new).twice
|
60
|
+
subject.adapterObject.should receive(:all).and_call_original
|
61
|
+
subject.all do end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#find" do
|
66
|
+
it "should return class instance" do
|
67
|
+
subject.adapterObject.should receive(:get).and_call_original
|
68
|
+
subject.find do |instance|
|
69
|
+
instance.class.should eq described_class
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should merge user data" do
|
74
|
+
subject.adapterObject.should receive(:get).and_call_original
|
75
|
+
subject.find do |instance|
|
76
|
+
instance.name.should eq 'User'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "Instance Methods" do
|
83
|
+
subject { described_class.new({name: 'Test'}) }
|
84
|
+
|
85
|
+
describe "#initialize" do
|
86
|
+
it "should set data" do
|
87
|
+
subject.name.should eq 'Test'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#update" do
|
92
|
+
it "should call adapter#set" do
|
93
|
+
described_class.adapterObject.should receive(:set).and_call_original
|
94
|
+
subject.update
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should merge user data" do
|
98
|
+
described_class.adapterObject.should receive(:set).and_call_original
|
99
|
+
subject.id = 0
|
100
|
+
subject.update name: "User" do
|
101
|
+
subject.errors.should be nil
|
102
|
+
subject.name.should eq 'User'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should set errors" do
|
107
|
+
subject.id == 2
|
108
|
+
subject.update do
|
109
|
+
subject.errors.should_not be nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#dirty?" do
|
115
|
+
it "should return true if there is no id" do
|
116
|
+
subject.dirty?.should eq true
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return false if there is and id" do
|
120
|
+
subject.id = 0
|
121
|
+
subject.dirty?.should eq false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|