databound 0.0.3
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 +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/config.ru +7 -0
- data/databound.gemspec +31 -0
- data/lib/databound.rb +83 -0
- data/lib/databound/data.rb +51 -0
- data/lib/databound/manager.rb +60 -0
- data/lib/databound/rails/routes.rb +17 -0
- data/lib/databound/version.rb +3 -0
- data/spec/controllers/databound_spec.rb +138 -0
- data/spec/controllers/dsl_controller_spec.rb +177 -0
- data/spec/controllers/loose_dsl_controller_spec.rb +127 -0
- data/spec/controllers/no_model_controller_spec.rb +9 -0
- data/spec/controllers/permitted_columns_controller_spec.rb +104 -0
- data/spec/internal/app/controllers/application_controller.rb +5 -0
- data/spec/internal/app/controllers/dsl_controller.rb +17 -0
- data/spec/internal/app/controllers/loose_dsl_controller.rb +13 -0
- data/spec/internal/app/controllers/no_model_controller.rb +3 -0
- data/spec/internal/app/controllers/permitted_columns_controller.rb +13 -0
- data/spec/internal/app/controllers/users_controller.rb +9 -0
- data/spec/internal/app/models/user.rb +2 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +7 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +7 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/rails_test_app/.gitignore +16 -0
- data/spec/support/rails_test_app/Gemfile +40 -0
- data/spec/support/rails_test_app/Gemfile.lock +120 -0
- data/spec/support/rails_test_app/README.rdoc +28 -0
- data/spec/support/rails_test_app/Rakefile +6 -0
- data/spec/support/rails_test_app/app/assets/images/.keep +0 -0
- data/spec/support/rails_test_app/app/assets/javascripts/application.js +16 -0
- data/spec/support/rails_test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/support/rails_test_app/app/controllers/application_controller.rb +5 -0
- data/spec/support/rails_test_app/app/controllers/concerns/.keep +0 -0
- data/spec/support/rails_test_app/app/helpers/application_helper.rb +2 -0
- data/spec/support/rails_test_app/app/mailers/.keep +0 -0
- data/spec/support/rails_test_app/app/models/.keep +0 -0
- data/spec/support/rails_test_app/app/models/concerns/.keep +0 -0
- data/spec/support/rails_test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/support/rails_test_app/bin/bundle +3 -0
- data/spec/support/rails_test_app/bin/rails +8 -0
- data/spec/support/rails_test_app/bin/rake +8 -0
- data/spec/support/rails_test_app/bin/spring +18 -0
- data/spec/support/rails_test_app/config.ru +4 -0
- data/spec/support/rails_test_app/config/application.rb +30 -0
- data/spec/support/rails_test_app/config/boot.rb +4 -0
- data/spec/support/rails_test_app/config/database.yml +25 -0
- data/spec/support/rails_test_app/config/environment.rb +5 -0
- data/spec/support/rails_test_app/config/environments/development.rb +37 -0
- data/spec/support/rails_test_app/config/environments/production.rb +78 -0
- data/spec/support/rails_test_app/config/environments/test.rb +39 -0
- data/spec/support/rails_test_app/config/initializers/assets.rb +8 -0
- data/spec/support/rails_test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/rails_test_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/support/rails_test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/rails_test_app/config/initializers/inflections.rb +16 -0
- data/spec/support/rails_test_app/config/initializers/mime_types.rb +4 -0
- data/spec/support/rails_test_app/config/initializers/session_store.rb +3 -0
- data/spec/support/rails_test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/rails_test_app/config/locales/en.yml +23 -0
- data/spec/support/rails_test_app/config/routes.rb +56 -0
- data/spec/support/rails_test_app/config/secrets.yml +22 -0
- data/spec/support/rails_test_app/db/seeds.rb +7 -0
- data/spec/support/rails_test_app/lib/assets/.keep +0 -0
- data/spec/support/rails_test_app/lib/tasks/.keep +0 -0
- data/spec/support/rails_test_app/log/.keep +0 -0
- data/spec/support/rails_test_app/public/404.html +67 -0
- data/spec/support/rails_test_app/public/422.html +67 -0
- data/spec/support/rails_test_app/public/500.html +66 -0
- data/spec/support/rails_test_app/public/favicon.ico +0 -0
- data/spec/support/rails_test_app/public/robots.txt +5 -0
- data/spec/support/rails_test_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/support/rails_test_app/vendor/assets/stylesheets/.keep +0 -0
- metadata +320 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DslController, type: :controller do
|
|
4
|
+
describe '#create' do
|
|
5
|
+
describe 'strict' do
|
|
6
|
+
describe 'without data usage' do
|
|
7
|
+
before :each do
|
|
8
|
+
data = {
|
|
9
|
+
data: {
|
|
10
|
+
name: 'John',
|
|
11
|
+
city: 'hottest',
|
|
12
|
+
},
|
|
13
|
+
scope: {},
|
|
14
|
+
extra_find_scopes: [],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
post(:create, javascriptize(data))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'responds consistently to js' do
|
|
21
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'creates the record' do
|
|
25
|
+
user = User.find(1)
|
|
26
|
+
user_attributes = user.attributes.to_options
|
|
27
|
+
|
|
28
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
29
|
+
id: 1,
|
|
30
|
+
name: 'John',
|
|
31
|
+
city: 'Miami',
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe 'with data usage' do
|
|
37
|
+
before :each do
|
|
38
|
+
data = {
|
|
39
|
+
data: {
|
|
40
|
+
name: 'John',
|
|
41
|
+
city: 'coldest',
|
|
42
|
+
},
|
|
43
|
+
scope: {},
|
|
44
|
+
extra_find_scopes: [],
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
post(:create, javascriptize(data))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'responds consistently to js' do
|
|
51
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'creates the record' do
|
|
55
|
+
user = User.find(1)
|
|
56
|
+
user_attributes = user.attributes.to_options
|
|
57
|
+
|
|
58
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
59
|
+
id: 1,
|
|
60
|
+
name: 'John',
|
|
61
|
+
city: 'Where John lives',
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe 'loose' do
|
|
68
|
+
it 'responds with error' do
|
|
69
|
+
data = {
|
|
70
|
+
data: {
|
|
71
|
+
name: 'John',
|
|
72
|
+
city: 'New York',
|
|
73
|
+
},
|
|
74
|
+
scope: {},
|
|
75
|
+
extra_find_scopes: [],
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
expect { post(:create, javascriptize(data)) }.to raise_error(
|
|
79
|
+
Databound::NotPermittedError,
|
|
80
|
+
"DSL column 'city' received unmatched string 'New York'." \
|
|
81
|
+
" Use 'strict: false' in DSL definition to allow everything.",
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe '#update' do
|
|
88
|
+
describe 'strict' do
|
|
89
|
+
describe 'without data usage' do
|
|
90
|
+
before :each do
|
|
91
|
+
User.create(name: 'John', city: 'New York')
|
|
92
|
+
|
|
93
|
+
data = {
|
|
94
|
+
data: {
|
|
95
|
+
id: 1,
|
|
96
|
+
city: 'hottest',
|
|
97
|
+
},
|
|
98
|
+
scope: {},
|
|
99
|
+
extra_find_scopes: [],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
post(:update, javascriptize(data))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'responds consistently to js' do
|
|
106
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'updates the record' do
|
|
110
|
+
user = User.find(1)
|
|
111
|
+
user_attributes = user.attributes.to_options
|
|
112
|
+
|
|
113
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
114
|
+
id: 1,
|
|
115
|
+
name: 'John',
|
|
116
|
+
city: 'Miami',
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe 'with data usage' do
|
|
122
|
+
before :each do
|
|
123
|
+
User.create(name: 'John', city: 'New York')
|
|
124
|
+
|
|
125
|
+
data = {
|
|
126
|
+
data: {
|
|
127
|
+
id: 1,
|
|
128
|
+
name: 'Peter',
|
|
129
|
+
city: 'coldest',
|
|
130
|
+
},
|
|
131
|
+
scope: {},
|
|
132
|
+
extra_find_scopes: [],
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
post(:update, javascriptize(data))
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'responds consistently to js' do
|
|
139
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'updates the record' do
|
|
143
|
+
user = User.find(1)
|
|
144
|
+
user_attributes = user.attributes.to_options
|
|
145
|
+
|
|
146
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
147
|
+
id: 1,
|
|
148
|
+
name: 'Peter',
|
|
149
|
+
city: 'Where Peter lives',
|
|
150
|
+
)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe 'loose' do
|
|
156
|
+
it 'responds with error' do
|
|
157
|
+
User.create(name: 'John', city: 'Los Angeles')
|
|
158
|
+
|
|
159
|
+
data = {
|
|
160
|
+
data: {
|
|
161
|
+
id: 1,
|
|
162
|
+
name: 'John',
|
|
163
|
+
city: 'New York',
|
|
164
|
+
},
|
|
165
|
+
scope: {},
|
|
166
|
+
extra_find_scopes: [],
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
expect { post(:create, javascriptize(data)) }.to raise_error(
|
|
170
|
+
Databound::NotPermittedError,
|
|
171
|
+
"DSL column 'city' received unmatched string 'New York'." \
|
|
172
|
+
" Use 'strict: false' in DSL definition to allow everything.",
|
|
173
|
+
)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe LooseDslController, type: :controller do
|
|
4
|
+
describe '#create strict' do
|
|
5
|
+
before :each do
|
|
6
|
+
data = {
|
|
7
|
+
data: {
|
|
8
|
+
name: 'John',
|
|
9
|
+
city: 'hottest',
|
|
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(success: true, id: 1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'creates the record' do
|
|
23
|
+
user = User.find(1)
|
|
24
|
+
user_attributes = user.attributes.to_options
|
|
25
|
+
|
|
26
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
27
|
+
id: 1,
|
|
28
|
+
name: 'John',
|
|
29
|
+
city: 'Miami',
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#create loose' do
|
|
35
|
+
before :each do
|
|
36
|
+
data = {
|
|
37
|
+
data: {
|
|
38
|
+
name: 'John',
|
|
39
|
+
city: 'New York',
|
|
40
|
+
},
|
|
41
|
+
scope: {},
|
|
42
|
+
extra_find_scopes: [],
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
post(:create, javascriptize(data))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'responds consistently to js' do
|
|
49
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'creates the record' do
|
|
53
|
+
user = User.find(1)
|
|
54
|
+
user_attributes = user.attributes.to_options
|
|
55
|
+
|
|
56
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
57
|
+
id: 1,
|
|
58
|
+
name: 'John',
|
|
59
|
+
city: 'New York',
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#update strict' do
|
|
65
|
+
before :each do
|
|
66
|
+
User.create(name: 'John', city: 'New York')
|
|
67
|
+
|
|
68
|
+
data = {
|
|
69
|
+
data: {
|
|
70
|
+
id: 1,
|
|
71
|
+
city: 'hottest',
|
|
72
|
+
},
|
|
73
|
+
scope: {},
|
|
74
|
+
extra_find_scopes: [],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
post(:update, javascriptize(data))
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'responds consistently to js' do
|
|
81
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'updates the record' do
|
|
85
|
+
user = User.find(1)
|
|
86
|
+
user_attributes = user.attributes.to_options
|
|
87
|
+
|
|
88
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
89
|
+
id: 1,
|
|
90
|
+
name: 'John',
|
|
91
|
+
city: 'Miami',
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe '#update loose' do
|
|
97
|
+
before :each do
|
|
98
|
+
User.create(name: 'John', city: 'New York')
|
|
99
|
+
|
|
100
|
+
data = {
|
|
101
|
+
data: {
|
|
102
|
+
id: 1,
|
|
103
|
+
city: 'Los Angeles',
|
|
104
|
+
},
|
|
105
|
+
scope: {},
|
|
106
|
+
extra_find_scopes: [],
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
post(:update, javascriptize(data))
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'responds consistently to js' do
|
|
113
|
+
expect(rubize(response)).to eq(success: true, id: 1)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'updates the record' do
|
|
117
|
+
user = User.find(1)
|
|
118
|
+
user_attributes = user.attributes.to_options
|
|
119
|
+
|
|
120
|
+
expect(user_attributes.slice(:id, :name, :city)).to eq(
|
|
121
|
+
id: 1,
|
|
122
|
+
name: 'John',
|
|
123
|
+
city: 'Los Angeles',
|
|
124
|
+
)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PermittedColumnsController, type: :controller do
|
|
4
|
+
describe '#create' do
|
|
5
|
+
it 'raise when param is not permitted' do
|
|
6
|
+
data = {
|
|
7
|
+
data: {
|
|
8
|
+
city: 'Barcelona',
|
|
9
|
+
},
|
|
10
|
+
scope: {},
|
|
11
|
+
extra_find_scopes: [],
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
expect { post(:create, javascriptize(data)) }.to raise_error(
|
|
15
|
+
Databound::NotPermittedError,
|
|
16
|
+
'Request includes unpermitted columns: city',
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should create when param is permitted' do
|
|
21
|
+
data = {
|
|
22
|
+
data: {
|
|
23
|
+
name: 'Nikki',
|
|
24
|
+
},
|
|
25
|
+
scope: {},
|
|
26
|
+
extra_find_scopes: [],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
expect { post(:create, javascriptize(data)) }.not_to raise_error
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#update' do
|
|
34
|
+
before :each do
|
|
35
|
+
User.create(name: 'Nikki')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'raise when param is not permitted' do
|
|
39
|
+
data = {
|
|
40
|
+
data: {
|
|
41
|
+
id: 1,
|
|
42
|
+
city: 'Barcelona',
|
|
43
|
+
},
|
|
44
|
+
scope: {},
|
|
45
|
+
extra_find_scopes: [],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
expect { post(:update, javascriptize(data)) }.to raise_error(
|
|
49
|
+
Databound::NotPermittedError,
|
|
50
|
+
'Request includes unpermitted columns: city',
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'should create when param is permitted' do
|
|
55
|
+
data = {
|
|
56
|
+
data: {
|
|
57
|
+
id: 1,
|
|
58
|
+
name: 'Nikki',
|
|
59
|
+
},
|
|
60
|
+
scope: {},
|
|
61
|
+
extra_find_scopes: [],
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
expect { post(:update, javascriptize(data)) }.not_to raise_error
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe 'via scope' do
|
|
69
|
+
describe '#create' do
|
|
70
|
+
it 'should raise when not permitted' do
|
|
71
|
+
data = {
|
|
72
|
+
data: {
|
|
73
|
+
name: 'Nikki',
|
|
74
|
+
},
|
|
75
|
+
scope: { city: 'Barcelona' },
|
|
76
|
+
extra_find_scopes: [],
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
expect { post(:create, javascriptize(data)) }.to raise_error(
|
|
80
|
+
Databound::NotPermittedError,
|
|
81
|
+
'Request includes unpermitted columns: city',
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#update' do
|
|
87
|
+
it 'should raise when not permitted' do
|
|
88
|
+
User.create(name: 'Nikki', city: 'New York')
|
|
89
|
+
data = {
|
|
90
|
+
data: {
|
|
91
|
+
name: 'Nikki',
|
|
92
|
+
},
|
|
93
|
+
scope: { city: 'Barcelona' },
|
|
94
|
+
extra_find_scopes: [],
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
expect { post(:update, javascriptize(data)) }.to raise_error(
|
|
98
|
+
Databound::NotPermittedError,
|
|
99
|
+
'Request includes unpermitted columns: city',
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|