Compare commits

...

10 Commits

15 changed files with 193 additions and 171 deletions
+8 -2
View File
@@ -1,5 +1,10 @@
source 'https://rubygems.org' source 'https://rubygems.org'
git_source(:gitlab) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://gitlab.com/#{repo_name}.git"
end
# Declare your gem's dependencies in dunlop-ember.gemspec. # Declare your gem's dependencies in dunlop-ember.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and # Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group. # development dependencies will be added by default to the :development group.
@@ -17,9 +22,10 @@ group :development, :test do
gem 'rspec-rails' gem 'rspec-rails'
gem 'cancancan' gem 'cancancan'
gem 'slim-rails' gem 'slim-rails'
gem 'dunlop-core', github: 'companytools/dunlop-core', branch: 'master' gem 'paperclip', '~> 5.3'
gem 'dunlop-core', gitlab: 'benja-2/dunlop-core', branch: 'master'
#gem 'dunlop-core', path: '~/development/rails/components/dunlop-core' #gem 'dunlop-core', path: '~/development/rails/components/dunlop-core'
gem 'factory_girl_rails' gem 'factory_bot_rails'
gem 'active_model_serializers' gem 'active_model_serializers'
gem 'database_cleaner' gem 'database_cleaner'
end end
+155 -143
View File
@@ -1,11 +1,10 @@
GIT GIT
remote: git://github.com/companytools/dunlop-core.git remote: https://gitlab.com/benja-2/dunlop-core.git
revision: a7b86d3c17309d9de29bc2b4aa9a7dff842d619f revision: 064ab4fa280d3dc79bc9671891e46b5b72e06fac
branch: master branch: master
specs: specs:
dunlop-core (1.4.0) dunlop-core (1.4.0)
cancancan cancancan
carrierwave
coffee-rails (~> 4.1) coffee-rails (~> 4.1)
devise devise
devise-token_authenticatable devise-token_authenticatable
@@ -39,70 +38,71 @@ PATH
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (5.1.4) actioncable (5.2.1)
actionpack (= 5.1.4) actionpack (= 5.2.1)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (~> 0.6.1) websocket-driver (>= 0.6.1)
actionmailer (5.1.4) actionmailer (5.2.1)
actionpack (= 5.1.4) actionpack (= 5.2.1)
actionview (= 5.1.4) actionview (= 5.2.1)
activejob (= 5.1.4) activejob (= 5.2.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.1.4) actionpack (5.2.1)
actionview (= 5.1.4) actionview (= 5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
rack (~> 2.0) rack (~> 2.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4) actionview (5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_attr (0.10.2) active_attr (0.12.0)
activemodel (>= 3.0.2, < 5.2) activemodel (>= 3.0.2, < 6.0)
activesupport (>= 3.0.2, < 5.2) activesupport (>= 3.0.2, < 6.0)
active_model_serializers (0.10.6) active_model_serializers (0.10.7)
actionpack (>= 4.1, < 6) actionpack (>= 4.1, < 6)
activemodel (>= 4.1, < 6) activemodel (>= 4.1, < 6)
case_transform (>= 0.2) case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (5.1.4) activejob (5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.1.4) activemodel (5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
activerecord (5.1.4) activerecord (5.2.1)
activemodel (= 5.1.4) activemodel (= 5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
arel (~> 8.0) arel (>= 9.0)
activesupport (5.1.4) activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
marcel (~> 0.3.1)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.2) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0) public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0) arel (9.0.0)
bcrypt (3.1.11) bcrypt (3.1.12)
builder (3.2.3) builder (3.2.3)
cancancan (2.0.0) cancancan (2.2.0)
capybara (2.15.2) capybara (3.6.0)
addressable addressable
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3) nokogiri (~> 1.8)
rack (>= 1.0.0) rack (>= 1.6.0)
rack-test (>= 0.5.4) rack-test (>= 0.6.3)
xpath (~> 2.0) xpath (~> 3.1)
carrierwave (1.2.1)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
case_transform (0.2) case_transform (0.2)
activesupport activesupport
climate_control (0.2.0)
coderay (1.1.2) coderay (1.1.2)
coffee-rails (4.2.2) coffee-rails (4.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
@@ -112,117 +112,125 @@ GEM
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
crass (1.0.2) crass (1.0.4)
database_cleaner (1.6.1) database_cleaner (1.7.0)
devise (4.3.0) devise (4.4.3)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2) railties (>= 4.1.0, < 6.0)
responders responders
warden (~> 1.2.3) warden (~> 1.2.3)
devise-token_authenticatable (1.0.0) devise-token_authenticatable (1.0.1)
devise (>= 4.0.0, < 4.4.0) devise (>= 4.0.0, < 4.5.0)
diff-lcs (1.3) diff-lcs (1.3)
erubi (1.6.1) erubi (1.7.1)
exception_notification (4.2.2) exception_notification (4.2.2)
actionmailer (>= 4.0, < 6) actionmailer (>= 4.0, < 6)
activesupport (>= 4.0, < 6) activesupport (>= 4.0, < 6)
execjs (2.7.0) execjs (2.7.0)
facets (3.1.0) facets (3.1.0)
factory_girl (4.8.1) factory_bot (4.11.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (4.8.0) factory_bot_rails (4.11.0)
factory_girl (~> 4.8.0) factory_bot (~> 4.11.0)
railties (>= 3.0.0) railties (>= 3.0.0)
ffi (1.9.18) ffi (1.9.25)
font-awesome-rails (4.7.0.2) font-awesome-rails (4.7.0.4)
railties (>= 3.2, < 5.2) railties (>= 3.2, < 6.0)
globalid (0.4.0) globalid (0.4.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
i18n (0.8.6) i18n (1.1.0)
js-routes (1.4.2) concurrent-ruby (~> 1.0)
js-routes (1.4.4)
railties (>= 3.2) railties (>= 3.2)
sprockets-rails sprockets-rails
jsonapi-renderer (0.1.3) jsonapi-renderer (0.2.0)
kaminari (1.0.1) kaminari (1.1.1)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1) kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.0.1) kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.0.1) kaminari-core (= 1.1.1)
kaminari-actionview (1.0.1) kaminari-actionview (1.1.1)
actionview actionview
kaminari-core (= 1.0.1) kaminari-core (= 1.1.1)
kaminari-activerecord (1.0.1) kaminari-activerecord (1.1.1)
activerecord activerecord
kaminari-core (= 1.0.1) kaminari-core (= 1.1.1)
kaminari-core (1.0.1) kaminari-core (1.1.1)
loofah (2.1.1) loofah (2.2.2)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.6) mail (2.7.0)
mime-types (>= 1.16, < 4) mini_mime (>= 0.1.1)
marcel (0.3.2)
mimemagic (~> 0.3.2)
memoist (0.16.0) memoist (0.16.0)
method_source (0.9.0) method_source (0.9.0)
mime-types (3.1) mime-types (3.2.2)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521) mime-types-data (3.2018.0812)
mini_mime (0.1.4) mimemagic (0.3.2)
mini_mime (1.0.1)
mini_portile2 (2.3.0) mini_portile2 (2.3.0)
minitest (5.10.3) minitest (5.11.3)
momentjs-rails (2.17.1) momentjs-rails (2.20.1)
railties (>= 3.1) railties (>= 3.1)
nio4r (2.1.0) nio4r (2.3.1)
nokogiri (1.8.1) nokogiri (1.8.4)
mini_portile2 (~> 2.3.0) mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
paperclip (5.3.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
pickadate-rails (3.5.5.0) pickadate-rails (3.5.5.0)
railties (>= 3.1.0) railties (>= 3.1.0)
polyamorous (1.3.1) pry (0.11.3)
activerecord (>= 3.0)
pry (0.11.1)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.9.0) method_source (~> 0.9.0)
pry-doc (0.11.1) pry-doc (0.13.4)
pry (~> 0.9) pry (~> 0.11)
yard (~> 0.9) yard (~> 0.9.11)
pry-rails (0.3.6) pry-rails (0.3.6)
pry (>= 0.10.4) pry (>= 0.10.4)
public_suffix (3.0.0) public_suffix (3.0.3)
rack (2.0.3) rack (2.0.5)
rack-cors (1.0.1) rack-cors (1.0.2)
rack-test (0.7.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (5.1.4) rails (5.2.1)
actioncable (= 5.1.4) actioncable (= 5.2.1)
actionmailer (= 5.1.4) actionmailer (= 5.2.1)
actionpack (= 5.1.4) actionpack (= 5.2.1)
actionview (= 5.1.4) actionview (= 5.2.1)
activejob (= 5.1.4) activejob (= 5.2.1)
activemodel (= 5.1.4) activemodel (= 5.2.1)
activerecord (= 5.1.4) activerecord (= 5.2.1)
activesupport (= 5.1.4) activestorage (= 5.2.1)
activesupport (= 5.2.1)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.1.4) railties (= 5.2.1)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.4)
loofah (~> 2.0) loofah (~> 2.2, >= 2.2.2)
railties (5.1.4) railties (5.2.1)
actionpack (= 5.1.4) actionpack (= 5.2.1)
activesupport (= 5.1.4) activesupport (= 5.2.1)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.19.0, < 2.0)
rake (12.1.0) rake (12.3.1)
ransack (1.8.3) ransack (2.0.1)
actionpack (>= 3.0) actionpack (>= 5.0)
activerecord (>= 3.0) activerecord (>= 5.0)
activesupport (>= 3.0) activesupport (>= 5.0)
i18n i18n
polyamorous (~> 1.3) rb-fsevent (0.10.3)
rb-fsevent (0.10.2)
rb-inotify (0.9.10) rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2) ffi (>= 0.5.0, < 2)
record_collection (0.10.4) record_collection (0.10.4)
@@ -230,28 +238,29 @@ GEM
activemodel (>= 4.1) activemodel (>= 4.1)
railties (>= 3.1) railties (>= 3.1)
redcarpet (3.4.0) redcarpet (3.4.0)
request_store (1.3.2) request_store (1.4.1)
rack (>= 1.4)
responders (2.4.0) responders (2.4.0)
actionpack (>= 4.2.0, < 5.3) actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3)
rspec-core (3.6.0) rspec-core (3.8.0)
rspec-support (~> 3.6.0) rspec-support (~> 3.8.0)
rspec-expectations (3.6.0) rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0) rspec-support (~> 3.8.0)
rspec-mocks (3.6.0) rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0) rspec-support (~> 3.8.0)
rspec-rails (3.6.1) rspec-rails (3.8.0)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
rspec-core (~> 3.6.0) rspec-core (~> 3.8.0)
rspec-expectations (~> 3.6.0) rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.6.0) rspec-mocks (~> 3.8.0)
rspec-support (~> 3.6.0) rspec-support (~> 3.8.0)
rspec-support (3.6.0) rspec-support (3.8.0)
sass (3.5.3) sass (3.5.7)
sass-listen (~> 4.0.0) sass-listen (~> 4.0.0)
sass-listen (4.0.0) sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
@@ -262,13 +271,13 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
simple_form (3.5.0) simple_form (4.0.1)
actionpack (> 4, < 5.2) actionpack (>= 5.0)
activemodel (> 4, < 5.2) activemodel (>= 5.0)
slim (3.0.8) slim (3.0.9)
temple (>= 0.7.6, < 0.9) temple (>= 0.7.6, < 0.9)
tilt (>= 1.3.3, < 2.1) tilt (>= 1.3.3, < 2.1)
slim-rails (3.1.2) slim-rails (3.1.3)
actionpack (>= 3.1) actionpack (>= 3.1)
railties (>= 3.1) railties (>= 3.1)
slim (~> 3.0) slim (~> 3.0)
@@ -276,7 +285,7 @@ GEM
activesupport (>= 4.2) activesupport (>= 4.2)
spring-commands-rspec (1.0.4) spring-commands-rspec (1.0.4)
spring (>= 0.9.1) spring (>= 0.9.1)
sprockets (3.7.1) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (3.2.1) sprockets-rails (3.2.1)
@@ -285,26 +294,28 @@ GEM
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.13) sqlite3 (1.3.13)
state_machines (0.5.0) state_machines (0.5.0)
state_machines-activemodel (0.5.0) state_machines-activemodel (0.5.1)
activemodel (>= 4.1, < 5.2) activemodel (>= 4.1, < 6.0)
state_machines (>= 0.5.0) state_machines (>= 0.5.0)
state_machines-activerecord (0.5.0) state_machines-activerecord (0.5.1)
activerecord (>= 4.1, < 5.2) activerecord (>= 4.1, < 6.0)
state_machines-activemodel (>= 0.5.0) state_machines-activemodel (>= 0.5.0)
temple (0.8.0) temple (0.8.0)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
thor (0.20.0) thor (0.20.0)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.8) tilt (2.0.8)
tzinfo (1.2.3) tzinfo (1.2.5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (1.2.7) warden (1.2.7)
rack (>= 1.0) rack (>= 1.0)
websocket-driver (0.6.5) websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2) websocket-extensions (0.1.3)
xpath (2.1.0) xpath (3.1.0)
nokogiri (~> 1.3) nokogiri (~> 1.8)
yard (0.9.9) yard (0.9.16)
PLATFORMS PLATFORMS
ruby ruby
@@ -317,8 +328,9 @@ DEPENDENCIES
database_cleaner database_cleaner
dunlop-core! dunlop-core!
dunlop-ember! dunlop-ember!
factory_girl_rails factory_bot_rails
kaminari kaminari
paperclip (~> 5.3)
pry-doc pry-doc
pry-rails pry-rails
rack-cors rack-cors
@@ -329,4 +341,4 @@ DEPENDENCIES
sqlite3 sqlite3
BUNDLED WITH BUNDLED WITH
1.16.0 1.16.3
@@ -8,23 +8,23 @@ module Dunlop
def ember_path def ember_path
app_globals = {} app_globals = {}
if adapter_name = params[:adapter].to_s.scan(/\w+/).first.presence if adapter_name = params[:adapter].to_s.scan(/\w+/).first.presence
app_index = Rails.root.join("public/adapters/#{adapter_name}/app/index.html") return render html: '403 - unauthorized, no adapter engine', status: 403 unless adapter = Panda.adapters[adapter_name]
return render text: 'unauthorized, no adapter engine', status: 403 unless adapter = Panda.adapters[adapter_name] @app_index = Rails.root.join("public/adapters/#{adapter.url_name}/app/index.html")
#app_globals = adapter.settings # load through request instead. More stable then changing environments #app_globals = adapter.settings # load through request instead. More stable then changing environments
unless Rails.application.config.try(:loose_ember_app_authorization) unless Rails.application.config.try(:loose_ember_app_authorization)
return render text: 'unauthorized, no adapter engine', status: 403 unless current_user.admin? or authorize!(:read, adapter.engine) return render html: '403 - unauthorized, no adapter engine permission', status: 403 unless current_user.admin? or can?(:read, adapter.engine)
end end
else else
app_index = Rails.root.join('public/app/index.html') @app_index = Rails.root.join('public/app/index.html')
end end
Rails.logger.info "Loading ember app for path '#/#{params[:rest]}' adapter: '#{params[:adapter].presence || 'main_app'}'" Rails.logger.info "Loading ember app for path '#/#{params[:rest]}' adapter: '#{params[:adapter].presence || 'main_app'}'"
if app_index.exist? if @app_index.exist?
index_html = app_index.read.to_s index_html = @app_index.read.to_s
app_globals[:flash] = flash.to_h if flash.present? app_globals[:flash] = flash.to_h if flash.present?
index_html.sub! 'app_globals={}', "app_globals=#{app_globals.to_json}" if app_globals.present? index_html.sub! 'app_globals={}', "app_globals=#{app_globals.to_json}" if app_globals.present?
render html: index_html.html_safe render html: index_html.html_safe
else else
render html: "App file <tt>#{app_index}</tt> not found".html_safe render html: "App file <tt>#{@app_index.to_s}</tt> not found".html_safe
end end
end end
@@ -1,4 +1,4 @@
h3 h3
span Could not find span Could not find
tt= '/app/index.html' tt= @app_index || '/app/index.html'
span file span file
-2
View File
@@ -23,7 +23,5 @@ Gem::Specification.new do |s|
s.add_dependency "active_model_serializers" s.add_dependency "active_model_serializers"
s.add_development_dependency "sqlite3" s.add_development_dependency "sqlite3"
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'capybara' s.add_development_dependency 'capybara'
s.add_development_dependency 'factory_girl_rails'
end end
+10 -4
View File
@@ -20,7 +20,7 @@ module Dunlop::Ember::ApiBaseController
def index def index
index_safeguard record_class index_safeguard record_class
result = record_scope.search(query).result result = record_scope.ransack(query).result
result = result.includes(*FlatKeys.as_nested_structure(index_include_relations)) if index_include_relations.present? result = result.includes(*FlatKeys.as_nested_structure(index_include_relations)) if index_include_relations.present?
result = result.uniq if params[:uniq].present? result = result.uniq if params[:uniq].present?
if index_pagination? if index_pagination?
@@ -37,7 +37,7 @@ module Dunlop::Ember::ApiBaseController
end end
def create def create
@record ||= record_class.new(record_params) @record ||= record_scope.new(record_params)
create_safeguard @record create_safeguard @record
return if performed? return if performed?
if @record.save if @record.save
@@ -50,7 +50,7 @@ module Dunlop::Ember::ApiBaseController
def update def update
update_safeguard @record update_safeguard @record
return if performed? return if performed?
@record.update_attributes record_params @record.update record_params
render json: @record render json: @record
end end
@@ -144,7 +144,11 @@ module Dunlop::Ember::ApiBaseController
def find_record(options = {}) def find_record(options = {})
scope = record_scope scope = record_scope
scope = scope.includes(*Array.wrap(options[:includes])) if options[:includes] scope = scope.includes(*Array.wrap(options[:includes])) if options[:includes]
@record = scope.find(params[:id]) if record_class.include?(HasUuidIdentifier) and HasUuidIdentifier::UUID_MATCH =~ params[:id].to_s
@record = scope.find_by(identifier: params[:id]) or raise ActiveRecord::RecordNotFound # I (Benjamin) don't agree with this (raising) behaviour, but this is the rails standard for raising and rescue
else
@record = scope.find(params[:id])
end
end end
def record_params def record_params
@@ -189,6 +193,7 @@ module Dunlop::Ember::ApiBaseController
self.class.predicate_end_matcher ||= Regexp.new("(_#{Ransack.predicates.keys.join('|_')})$") self.class.predicate_end_matcher ||= Regexp.new("(_#{Ransack.predicates.keys.join('|_')})$")
mapped_query = {} mapped_query = {}
(params[:q] || {}).each do |key, value| (params[:q] || {}).each do |key, value|
# not setting the matcher means equality
key = "#{key}_eq" unless %w[s sorts].include?(key) or record_class.try(:ransackable_scopes).try(:include?, key.to_sym) or key =~ self.class.predicate_end_matcher # expect equality when no predicate is given key = "#{key}_eq" unless %w[s sorts].include?(key) or record_class.try(:ransackable_scopes).try(:include?, key.to_sym) or key =~ self.class.predicate_end_matcher # expect equality when no predicate is given
if key =~ /^type_/ if key =~ /^type_/
# map type to sti_type # map type to sti_type
@@ -211,6 +216,7 @@ module Dunlop::Ember::ApiBaseController
end end
return resource.to_json if resource.is_a?(Hash) return resource.to_json if resource.is_a?(Hash)
return resource if resource.is_a?(String) return resource if resource.is_a?(String)
return resource.to_json if resource.try(:custom_data?)
action_serialize_options_method = :"#{action_name}_serialize_options" action_serialize_options_method = :"#{action_name}_serialize_options"
#action_serialize_options = respond_to?(action_serialize_options_method) ? __send__(action_serialize_options_method) : {} #action_serialize_options = respond_to?(action_serialize_options_method) ? __send__(action_serialize_options_method) : {}
@@ -98,7 +98,7 @@ RSpec.describe Api::PostsController, type: :controller do
type: "comment", type: "comment",
attributes: {body: "post-1-comment-1"}, attributes: {body: "post-1-comment-1"},
relationships: { relationships: {
post: {data: {id: post1.id.to_s, type: "posts"}} post: {data: {id: post1.id.to_s, type: "post"}}
} }
} }
], ],
@@ -31,7 +31,7 @@ RSpec.describe Api::PostsController, type: :controller do
type: "comment", type: "comment",
attributes: {body: "post-1-comment-1"}, attributes: {body: "post-1-comment-1"},
relationships: { relationships: {
post: {data: {id: post1.id.to_s, type: "posts"}} post: {data: {id: post1.id.to_s, type: "post"}}
} }
} }
] ]
@@ -1,4 +1,4 @@
class Api::CommentSerializer < ActiveModel::Serializer class Api::CommentSerializer < ActiveModel::Serializer
attribute :body attribute :body
belongs_to :post belongs_to :post, serializer: Api::PostSerializer
end end
@@ -1,5 +1,5 @@
class Api::PostSerializer < ActiveModel::Serializer class Api::PostSerializer < ActiveModel::Serializer
attribute :title attribute :title
attribute :body attribute :body
has_many :comments has_many :comments, serializer: Api::CommentSerializer
end end
@@ -17,8 +17,8 @@ ActiveSupport.to_time_preserves_timezone = true
# Require `belongs_to` associations by default. Previous versions had false. # Require `belongs_to` associations by default. Previous versions had false.
Rails.application.config.active_record.belongs_to_required_by_default = true Rails.application.config.active_record.belongs_to_required_by_default = true
# Do not halt callback chains when a callback returns false. Previous versions had true. ## Do not halt callback chains when a callback returns false. Previous versions had true.
ActiveSupport.halt_callback_chains_on_return_false = false #ActiveSupport.halt_callback_chains_on_return_false = false
# Configure SSL options to enable HSTS with subdomains. Previous versions had false. # Configure SSL options to enable HSTS with subdomains. Previous versions had false.
Rails.application.config.ssl_options = { hsts: { subdomains: true } } Rails.application.config.ssl_options = { hsts: { subdomains: true } }
+1 -1
View File
@@ -1,4 +1,4 @@
FactoryGirl.define do FactoryBot.define do
factory :comment do factory :comment do
user_id 1 user_id 1
post_id 1 post_id 1
+1 -1
View File
@@ -1,4 +1,4 @@
FactoryGirl.define do FactoryBot.define do
factory :post do factory :post do
sequence(:title) {|i| "post-#{i}"} sequence(:title) {|i| "post-#{i}"}
sequence(:body) {|i| "post-body-#{i}"} sequence(:body) {|i| "post-body-#{i}"}
+1 -1
View File
@@ -1,4 +1,4 @@
FactoryGirl.define do FactoryBot.define do
factory :user do factory :user do
sequence(:email) { |i| "user#{i}@example.com" } sequence(:email) { |i| "user#{i}@example.com" }
password 'secret' password 'secret'
+3 -3
View File
@@ -19,7 +19,7 @@ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
# in spec/support/ and its subdirectories. # in spec/support/ and its subdirectories.
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f } Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f } Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f }
#FactoryGirl.definition_file_paths = [File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")] # not needed here #FactoryBot.definition_file_paths = [File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")] # not needed here
Dir.glob("spec/acceptance/steps/**/*steps.rb") { |f| load f, true } Dir.glob("spec/acceptance/steps/**/*steps.rb") { |f| load f, true }
# Add additional requires below this line. Rails is not loaded until this point! # Add additional requires below this line. Rails is not loaded until this point!
@@ -53,7 +53,7 @@ RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures" config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] } config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
config.include FactoryGirl::Syntax::Methods config.include FactoryBot::Syntax::Methods
config.include Rspec::Dunlop::GeneralHelpers config.include Rspec::Dunlop::GeneralHelpers
config.include Rspec::Dunlop::FeatureHelpers, type: :feature config.include Rspec::Dunlop::FeatureHelpers, type: :feature
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
@@ -64,7 +64,7 @@ RSpec.configure do |config|
# instead of true. # instead of true.
config.use_transactional_fixtures = false config.use_transactional_fixtures = false
config.before :suite do config.before :suite do
#FactoryGirl.reload # to add the adapter factories #FactoryBot.reload # to add the adapter factories
#DatabaseCleaner.clean_with(:truncation) #DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
Dunlop::NestedLogger.options[:yaml_options][:line_width] = 2000 Dunlop::NestedLogger.options[:yaml_options][:line_width] = 2000