backframe 0.0.49 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +2 -2
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +1156 -0
  6. data/Gemfile +9 -13
  7. data/README.md +133 -4
  8. data/Rakefile +3 -7
  9. data/backframe.gemspec +10 -11
  10. data/circle.yml +5 -2
  11. data/lib/backframe.rb +21 -34
  12. data/lib/backframe/mime.rb +4 -0
  13. data/lib/backframe/query.rb +48 -0
  14. data/lib/backframe/query/sort.rb +29 -0
  15. data/lib/backframe/railtie.rb +1 -16
  16. data/lib/backframe/response.rb +60 -0
  17. data/lib/backframe/response/adapter/csv.rb +39 -0
  18. data/lib/backframe/response/adapter/json.rb +53 -0
  19. data/lib/backframe/response/adapter/xlsx.rb +41 -0
  20. data/lib/backframe/response/adapter/xml.rb +37 -0
  21. data/lib/backframe/response/collection.rb +43 -0
  22. data/lib/backframe/response/fields.rb +62 -0
  23. data/lib/backframe/response/record.rb +38 -0
  24. data/lib/backframe/service.rb +60 -0
  25. data/lib/backframe/service/result/base.rb +24 -0
  26. data/lib/backframe/service/result/failure.rb +21 -0
  27. data/lib/backframe/service/result/success.rb +21 -0
  28. data/lib/backframe/version.rb +1 -1
  29. data/spec/fixtures/active_record.rb +22 -0
  30. data/spec/fixtures/models.rb +25 -0
  31. data/spec/fixtures/queries.rb +28 -0
  32. data/spec/fixtures/seeds.rb +12 -0
  33. data/spec/fixtures/serializers.rb +23 -0
  34. data/spec/fixtures/services.rb +26 -0
  35. data/spec/query/sort_spec.rb +47 -0
  36. data/spec/query_spec.rb +63 -0
  37. data/spec/response/adapter/csv_spec.rb +47 -0
  38. data/spec/response/adapter/json_spec.rb +66 -0
  39. data/spec/response/adapter/xlsx_spec.rb +59 -0
  40. data/spec/response/adapter/xml_spec.rb +63 -0
  41. data/spec/response/fields_spec.rb +45 -0
  42. data/spec/response/record_spec.rb +45 -0
  43. data/spec/response_spec.rb +153 -0
  44. data/spec/service/result/failure_spec.rb +16 -0
  45. data/spec/service/result/sucess_spec.rb +17 -0
  46. data/spec/service_spec.rb +16 -0
  47. data/spec/spec_helper.rb +15 -52
  48. metadata +78 -81
  49. data/lib/backframe/actioncontroller/acts_as_activation.rb +0 -70
  50. data/lib/backframe/actioncontroller/acts_as_api.rb +0 -39
  51. data/lib/backframe/actioncontroller/acts_as_api/adapter.rb +0 -53
  52. data/lib/backframe/actioncontroller/acts_as_api/errors.rb +0 -48
  53. data/lib/backframe/actioncontroller/acts_as_api/headers.rb +0 -11
  54. data/lib/backframe/actioncontroller/acts_as_api/page.rb +0 -181
  55. data/lib/backframe/actioncontroller/acts_as_reset.rb +0 -86
  56. data/lib/backframe/actioncontroller/acts_as_resource.rb +0 -92
  57. data/lib/backframe/actioncontroller/acts_as_resource/actions.rb +0 -100
  58. data/lib/backframe/actioncontroller/acts_as_session.rb +0 -80
  59. data/lib/backframe/activerecord/acts_as_activable.rb +0 -50
  60. data/lib/backframe/activerecord/acts_as_distinct.rb +0 -49
  61. data/lib/backframe/activerecord/acts_as_enum.rb +0 -62
  62. data/lib/backframe/activerecord/acts_as_orderable.rb +0 -40
  63. data/lib/backframe/activerecord/acts_as_percent.rb +0 -46
  64. data/lib/backframe/activerecord/acts_as_phone.rb +0 -59
  65. data/lib/backframe/activerecord/acts_as_user.rb +0 -101
  66. data/lib/backframe/activerecord/default_values.rb +0 -32
  67. data/lib/backframe/activerecord/filter_sort.rb +0 -79
  68. data/lib/backframe/activerecord/migration.rb +0 -25
  69. data/lib/backframe/image_cache/image_cache.rb +0 -45
  70. data/lib/backframe/image_cache/lib/asset.rb +0 -109
  71. data/lib/backframe/image_cache/lib/cache.rb +0 -67
  72. data/lib/backframe/image_cache/lib/conversions.rb +0 -132
  73. data/lib/backframe/models/activation.rb +0 -60
  74. data/lib/backframe/models/activity.rb +0 -40
  75. data/lib/backframe/models/reset.rb +0 -59
  76. data/lib/backframe/models/story.rb +0 -9
  77. data/lib/backframe/serializers/activity_serializer.rb +0 -44
  78. data/spec/backframe/acts_as_api_spec.rb +0 -225
  79. data/spec/backframe/acts_as_resource_spec.rb +0 -178
  80. data/spec/support/example_factory.rb +0 -9
  81. data/spec/support/example_serializer.rb +0 -3
  82. data/spec/support/schema.rb +0 -8
@@ -1,178 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Backframe::ActsAsResource', type: :controller do
4
- controller do
5
- include Backframe::ActsAsAPI
6
- include Backframe::ActsAsResource
7
-
8
- acts_as_api
9
- acts_as_resource 'Example', allowed: [:a, :b, :c]
10
-
11
- def base_api_url
12
- '/example'
13
- end
14
- end
15
-
16
- describe '#index' do
17
- it 'responds with 200 status' do
18
- get :index, format: :json
19
- expect(response.status).to eq 200
20
- end
21
- end
22
-
23
- describe '#create' do
24
- let(:params) { attributes_for(:example).merge(format: :json) }
25
-
26
- it 'responds with 201 status' do
27
- post :create, params
28
- expect(response.status).to eq 201
29
- end
30
-
31
- it 'creates record' do
32
- expect { post :create, params }.to change { Example.count }.by 1
33
- end
34
-
35
- it 'responds with record' do
36
- post :create, params
37
- expect(json_response).to eq serialize(Example.last).stringify_keys
38
- end
39
-
40
- context 'when save fails' do
41
- before do
42
- allow_any_instance_of(Example).to receive(:save) { false }
43
- end
44
-
45
- it 'responds with 422 status' do
46
- post :create, params
47
- expect(response.status).to eq 422
48
- end
49
-
50
- it 'does not create record' do
51
- expect { post :create, params }.to change { Example.count }.by 0
52
- end
53
-
54
- it 'responds with errors' do
55
- post :create, params
56
- expect(json_response[:errors]).to be
57
- expect(json_response[:message]).to be
58
- expect(json_response[:status]).to eq 422
59
- end
60
- end
61
- end
62
-
63
- describe '#show' do
64
- let!(:record) { create(:example) }
65
-
66
- it 'responds with 200 status' do
67
- get :show, id: record.id
68
- expect(response.status).to eq 200
69
- end
70
-
71
- it 'responds with record' do
72
- get :show, id: record.id
73
- expect(json_response).to eq serialize(record).stringify_keys
74
- end
75
- end
76
-
77
- describe '#edit' do
78
- let!(:record) { create(:example) }
79
-
80
- it 'responds with 200 status' do
81
- get :edit, id: record.id
82
- expect(response.status).to eq 200
83
- end
84
-
85
- it 'responds with record' do
86
- get :edit, id: record.id
87
- expect(json_response).to eq serialize(record).stringify_keys
88
- end
89
- end
90
-
91
- describe '#update' do
92
- let!(:record) { create(:example) }
93
- let(:params) { attributes_for(:example).merge(id: record.id) }
94
-
95
- it 'responds with 200 status' do
96
- patch :update, params
97
- expect(response.status).to eq 200
98
- end
99
-
100
- it 'udpates record' do
101
- patch :update, params
102
- expect(json_response[:a]).to eq params[:a]
103
- end
104
-
105
- it 'responds with updated record' do
106
- patch :update, params
107
- expect(json_response).to eq serialize(record.reload).stringify_keys
108
- end
109
-
110
- context 'when save fails' do
111
- before do
112
- allow_any_instance_of(Example).to receive(:save) { false }
113
- patch :update, params
114
- end
115
-
116
- it 'responds with 422 status' do
117
- expect(response.status).to eq 422
118
- end
119
-
120
- it 'does not update record' do
121
- expect(record.a).to eq record.reload.a
122
- end
123
-
124
- it 'responds with errors' do
125
- expect(json_response[:errors]).to be
126
- expect(json_response[:message]).to be
127
- expect(json_response[:status]).to eq 422
128
- end
129
- end
130
- end
131
-
132
- describe '#update_all' do
133
- let!(:records) { create_list(:example, 3) }
134
- let(:attrs) { records.map { |record| { id: record.id, a: 'a' } } }
135
- let(:params) { ActionController::Parameters.new(records: attrs, format: :json) }
136
-
137
- before do
138
- routes.draw { post :update_all, to: 'anonymous#update_all' }
139
- post :update_all, params
140
- end
141
-
142
- it 'responds with 200 status' do
143
- expect(response.status).to eq 200
144
- end
145
-
146
- it 'updates all records' do
147
- records.each { |record| expect(record.reload.a).to eq 'a' }
148
- end
149
- end
150
-
151
- describe '#destroy' do
152
- let!(:record) { create(:example) }
153
-
154
- it 'responds with 204 status' do
155
- delete :destroy, id: record.id
156
- expect(response.status).to eq 204
157
- end
158
-
159
- it 'deletes record' do
160
- expect { delete :destroy, id: record.id }.to change { Example.count }.by(-1)
161
- end
162
-
163
- context 'when delete fails' do
164
- before do
165
- allow_any_instance_of(Example).to receive(:destroy) { false }
166
- end
167
-
168
- it 'responds with 422 status' do
169
- delete :destroy, id: record.id
170
- expect(response.status).to eq 422
171
- end
172
-
173
- it 'does not delete record' do
174
- expect { delete :destroy, id: record.id }.to change { Example.count }.by 0
175
- end
176
- end
177
- end
178
- end
@@ -1,9 +0,0 @@
1
- require 'faker'
2
-
3
- FactoryGirl.define do
4
- factory :example do
5
- a { Faker::Lorem.word }
6
- b { Faker::Lorem.word }
7
- c { Faker::Lorem.word }
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- class ExampleSerializer < ActiveModel::Serializer
2
- attributes :a, :b, :c
3
- end
@@ -1,8 +0,0 @@
1
- ActiveRecord::Schema.define(version: 1) do
2
- create_table 'examples' do |t|
3
- t.string 'a'
4
- t.string 'b'
5
- t.string 'c'
6
- t.timestamps null: false
7
- end
8
- end