databound 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/databound.rb +1 -0
- data/lib/databound/rails/routes.rb +3 -1
- data/lib/databound/utils.rb +29 -0
- data/lib/databound/version.rb +1 -1
- data/spec/controllers/databound_spec.rb +2 -2
- data/spec/controllers/dsl_controller_spec.rb +4 -4
- data/spec/controllers/loose_dsl_controller_spec.rb +4 -4
- data/spec/controllers/on_the_fly_spec.rb +32 -0
- data/spec/internal/app/models/message.rb +2 -0
- data/spec/internal/config/routes.rb +1 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +6 -0
- data/spec/spec_helper.rb +3 -4
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc120402dc3597810b2c3287923e38b866ec3cd4
|
4
|
+
data.tar.gz: f67f1667a90604c4d73e954ec0347a9f5c7b248f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4952ab9c69bed7a162d02f8bd1a3f15216cadb468c885c33694568b5255675ccdf0835a9365725304b4e50abb37ad20fe6e48021cdbcb58f55cec4e48a79316
|
7
|
+
data.tar.gz: 79fb642e6fcf2253f4d27e6011efb5d00ae0d94469ee9242f8d5fc4aed2b455aeeda7db7efec5d5b38599930e73aacb167ab823d1d08771b5ce06f7ba76ad370
|
data/lib/databound.rb
CHANGED
@@ -5,9 +5,11 @@ class ActionDispatch::Routing::Mapper
|
|
5
5
|
|
6
6
|
resources.each do |resource|
|
7
7
|
Rails.application.routes.draw do
|
8
|
+
controller = [namespace, resource].compact.join('/')
|
9
|
+
Databound::Utils.create_controller_unless_exists(controller, resource)
|
10
|
+
|
8
11
|
%i(where create update destroy).each do |name|
|
9
12
|
path = [namespace, resource, name].compact.join('/')
|
10
|
-
controller = [namespace, resource].compact.join('/')
|
11
13
|
to = [controller, name].join('#')
|
12
14
|
post path => to
|
13
15
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Databound
|
2
|
+
class Utils
|
3
|
+
def self.create_controller_unless_exists(path, resource)
|
4
|
+
return if exists?(path)
|
5
|
+
|
6
|
+
controller = Class.new(ApplicationController)
|
7
|
+
controller.send(:include, Databound)
|
8
|
+
controller.send(:define_method, :model) do
|
9
|
+
resource.to_s.classify.constantize
|
10
|
+
end
|
11
|
+
|
12
|
+
Object.const_set(name(path), controller)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.exists?(path)
|
16
|
+
begin
|
17
|
+
name(path).constantize
|
18
|
+
rescue NameError
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.name(path)
|
26
|
+
"#{path.camelize}Controller"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/databound/version.rb
CHANGED
@@ -17,7 +17,7 @@ describe UsersController, type: :controller do
|
|
17
17
|
it 'responds consistently to js' do
|
18
18
|
expect(rubize(response)).to eq(
|
19
19
|
success: true,
|
20
|
-
id: 1,
|
20
|
+
id: '1',
|
21
21
|
scoped_records: all_records,
|
22
22
|
)
|
23
23
|
end
|
@@ -85,7 +85,7 @@ describe UsersController, type: :controller do
|
|
85
85
|
it 'respond with updated record id' do
|
86
86
|
expect(rubize(response)).to eq(
|
87
87
|
success: true,
|
88
|
-
id: @user.id,
|
88
|
+
id: @user.id.to_s,
|
89
89
|
scoped_records: all_records,
|
90
90
|
)
|
91
91
|
end
|
@@ -20,7 +20,7 @@ describe DslController, type: :controller do
|
|
20
20
|
it 'responds consistently to js' do
|
21
21
|
expect(rubize(response)).to eq(
|
22
22
|
success: true,
|
23
|
-
id: 1,
|
23
|
+
id: '1',
|
24
24
|
scoped_records: all_records,
|
25
25
|
)
|
26
26
|
end
|
@@ -54,7 +54,7 @@ describe DslController, type: :controller do
|
|
54
54
|
it 'responds consistently to js' do
|
55
55
|
expect(rubize(response)).to eq(
|
56
56
|
success: true,
|
57
|
-
id: 1,
|
57
|
+
id: '1',
|
58
58
|
scoped_records: all_records,
|
59
59
|
)
|
60
60
|
end
|
@@ -113,7 +113,7 @@ describe DslController, type: :controller do
|
|
113
113
|
it 'responds consistently to js' do
|
114
114
|
expect(rubize(response)).to eq(
|
115
115
|
success: true,
|
116
|
-
id: 1,
|
116
|
+
id: '1',
|
117
117
|
scoped_records: all_records,
|
118
118
|
)
|
119
119
|
end
|
@@ -150,7 +150,7 @@ describe DslController, type: :controller do
|
|
150
150
|
it 'responds consistently to js' do
|
151
151
|
expect(rubize(response)).to eq(
|
152
152
|
success: true,
|
153
|
-
id: 1,
|
153
|
+
id: '1',
|
154
154
|
scoped_records: all_records,
|
155
155
|
)
|
156
156
|
end
|
@@ -18,7 +18,7 @@ describe LooseDslController, type: :controller do
|
|
18
18
|
it 'responds consistently to js' do
|
19
19
|
expect(rubize(response)).to eq(
|
20
20
|
success: true,
|
21
|
-
id: 1,
|
21
|
+
id: '1',
|
22
22
|
scoped_records: all_records,
|
23
23
|
)
|
24
24
|
end
|
@@ -52,7 +52,7 @@ describe LooseDslController, type: :controller do
|
|
52
52
|
it 'responds consistently to js' do
|
53
53
|
expect(rubize(response)).to eq(
|
54
54
|
success: true,
|
55
|
-
id: 1,
|
55
|
+
id: '1',
|
56
56
|
scoped_records: all_records,
|
57
57
|
)
|
58
58
|
end
|
@@ -88,7 +88,7 @@ describe LooseDslController, type: :controller do
|
|
88
88
|
it 'responds consistently to js' do
|
89
89
|
expect(rubize(response)).to eq(
|
90
90
|
success: true,
|
91
|
-
id: 1,
|
91
|
+
id: '1',
|
92
92
|
scoped_records: all_records,
|
93
93
|
)
|
94
94
|
end
|
@@ -124,7 +124,7 @@ describe LooseDslController, type: :controller do
|
|
124
124
|
it 'responds consistently to js' do
|
125
125
|
expect(rubize(response)).to eq(
|
126
126
|
success: true,
|
127
|
-
id: 1,
|
127
|
+
id: '1',
|
128
128
|
scoped_records: all_records,
|
129
129
|
)
|
130
130
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MessagesController, type: :controller do
|
4
|
+
describe '#create' do
|
5
|
+
before :each do
|
6
|
+
data = {
|
7
|
+
data: {
|
8
|
+
name: 'John',
|
9
|
+
city: 'Prague',
|
10
|
+
},
|
11
|
+
scope: {},
|
12
|
+
extra_find_scopes: [],
|
13
|
+
}
|
14
|
+
|
15
|
+
post(:create, javascriptize(data))
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'responds consistently to js' do
|
19
|
+
expect(rubize(response)).to eq(
|
20
|
+
success: true,
|
21
|
+
id: '1',
|
22
|
+
scoped_records: all_records(Message),
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates the record' do
|
27
|
+
message = Message.find(1)
|
28
|
+
message_attributes = message.attributes.to_options
|
29
|
+
expect(message_attributes.slice(:id, :name)).to eq(id: 1, name: 'John')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
Binary file
|
data/spec/internal/db/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
-
|
4
3
|
require 'combustion'
|
5
4
|
|
6
5
|
Combustion.initialize! :all
|
@@ -35,7 +34,7 @@ def convert_scoped_records(obj)
|
|
35
34
|
return obj unless obj.is_a?(Hash)
|
36
35
|
result = obj
|
37
36
|
|
38
|
-
converted = obj[:scoped_records].map do |record|
|
37
|
+
converted = JSON.parse(obj[:scoped_records]).map do |record|
|
39
38
|
record.except('created_at', 'updated_at')
|
40
39
|
end
|
41
40
|
|
@@ -47,6 +46,6 @@ def gather(attribute, response)
|
|
47
46
|
rubize(response).map { |record| record[attribute] }
|
48
47
|
end
|
49
48
|
|
50
|
-
def all_records
|
51
|
-
|
49
|
+
def all_records(model = User)
|
50
|
+
model.select(:id, :name, :city).map(&:attributes)
|
52
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: databound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domas Bitvinskas
|
@@ -143,11 +143,13 @@ files:
|
|
143
143
|
- lib/databound/extensions.rb
|
144
144
|
- lib/databound/manager.rb
|
145
145
|
- lib/databound/rails/routes.rb
|
146
|
+
- lib/databound/utils.rb
|
146
147
|
- lib/databound/version.rb
|
147
148
|
- spec/controllers/databound_spec.rb
|
148
149
|
- spec/controllers/dsl_controller_spec.rb
|
149
150
|
- spec/controllers/loose_dsl_controller_spec.rb
|
150
151
|
- spec/controllers/no_model_controller_spec.rb
|
152
|
+
- spec/controllers/on_the_fly_spec.rb
|
151
153
|
- spec/controllers/permitted_columns_controller_spec.rb
|
152
154
|
- spec/internal/app/controllers/application_controller.rb
|
153
155
|
- spec/internal/app/controllers/dsl_controller.rb
|
@@ -155,6 +157,7 @@ files:
|
|
155
157
|
- spec/internal/app/controllers/no_model_controller.rb
|
156
158
|
- spec/internal/app/controllers/permitted_columns_controller.rb
|
157
159
|
- spec/internal/app/controllers/users_controller.rb
|
160
|
+
- spec/internal/app/models/message.rb
|
158
161
|
- spec/internal/app/models/user.rb
|
159
162
|
- spec/internal/config/database.yml
|
160
163
|
- spec/internal/config/routes.rb
|
@@ -241,6 +244,7 @@ test_files:
|
|
241
244
|
- spec/controllers/dsl_controller_spec.rb
|
242
245
|
- spec/controllers/loose_dsl_controller_spec.rb
|
243
246
|
- spec/controllers/no_model_controller_spec.rb
|
247
|
+
- spec/controllers/on_the_fly_spec.rb
|
244
248
|
- spec/controllers/permitted_columns_controller_spec.rb
|
245
249
|
- spec/internal/app/controllers/application_controller.rb
|
246
250
|
- spec/internal/app/controllers/dsl_controller.rb
|
@@ -248,6 +252,7 @@ test_files:
|
|
248
252
|
- spec/internal/app/controllers/no_model_controller.rb
|
249
253
|
- spec/internal/app/controllers/permitted_columns_controller.rb
|
250
254
|
- spec/internal/app/controllers/users_controller.rb
|
255
|
+
- spec/internal/app/models/message.rb
|
251
256
|
- spec/internal/app/models/user.rb
|
252
257
|
- spec/internal/config/database.yml
|
253
258
|
- spec/internal/config/routes.rb
|