Commit fd199f74 by John Donnal

added cors middleware and custom url settings for createnilm

parent ed0a8a8f
...@@ -33,6 +33,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc ...@@ -33,6 +33,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
gem 'httparty' gem 'httparty'
gem 'rack-cors'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
...@@ -46,6 +47,7 @@ group :development, :test do ...@@ -46,6 +47,7 @@ group :development, :test do
gem 'rspec-json_expectations' gem 'rspec-json_expectations'
gem 'cucumber-rails', require: false gem 'cucumber-rails', require: false
gem 'database_cleaner' gem 'database_cleaner'
gem 'tzinfo-data'
end end
group :development, :test do group :development, :test do
......
...@@ -38,11 +38,11 @@ GEM ...@@ -38,11 +38,11 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.4.0) addressable (2.4.0)
arel (6.0.3) arel (6.0.3)
ast (2.2.0) ast (2.3.0)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.2) builder (3.2.2)
byebug (8.2.5) byebug (9.0.5)
capybara (2.7.1) capybara (2.7.1)
addressable addressable
mime-types (>= 1.16) mime-types (>= 1.16)
...@@ -61,43 +61,44 @@ GEM ...@@ -61,43 +61,44 @@ GEM
concurrent-ruby (1.0.2) concurrent-ruby (1.0.2)
crack (0.4.3) crack (0.4.3)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
cucumber (2.3.3) cucumber (2.4.0)
builder (>= 2.1.2) builder (>= 2.1.2)
cucumber-core (~> 1.4.0) cucumber-core (~> 1.5.0)
cucumber-wire (~> 0.0.1) cucumber-wire (~> 0.0.1)
diff-lcs (>= 1.1.3) diff-lcs (>= 1.1.3)
gherkin (~> 3.2.0) gherkin (~> 4.0)
multi_json (>= 1.7.5, < 2.0) multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2) multi_test (>= 0.1.2)
cucumber-core (1.4.0) cucumber-core (1.5.0)
gherkin (~> 3.2.0) gherkin (~> 4.0)
cucumber-rails (1.4.3) cucumber-rails (1.4.4)
capybara (>= 1.1.2, < 3) capybara (>= 1.1.2, < 3)
cucumber (>= 1.3.8, < 3) cucumber (>= 1.3.8, < 3)
mime-types (>= 1.16, < 4) mime-types (>= 1.16, < 4)
nokogiri (~> 1.5) nokogiri (~> 1.5)
railties (>= 3, < 5) railties (>= 3, < 5.1)
cucumber-wire (0.0.1) cucumber-wire (0.0.1)
database_cleaner (1.5.3) database_cleaner (1.5.3)
debug_inspector (0.0.2) debug_inspector (0.0.2)
diff-lcs (1.2.5) diff-lcs (1.2.5)
erubis (2.7.0) erubis (2.7.0)
execjs (2.6.0) execjs (2.7.0)
factory_girl (4.7.0) factory_girl (4.7.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (4.7.0) factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0) factory_girl (~> 4.7.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.6.3) faker (1.6.6)
i18n (~> 0.5) i18n (~> 0.5)
ffi (1.9.10) ffi (1.9.14)
ffi (1.9.14-x64-mingw32)
formatador (0.2.5) formatador (0.2.5)
gherkin (3.2.0) gherkin (4.0.0)
globalid (0.3.6) globalid (0.3.7)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
guard (2.13.0) guard (2.14.0)
formatador (>= 0.2.4) formatador (>= 0.2.4)
listen (>= 2.7, <= 4.0) listen (>= 2.7, < 4.0)
lumberjack (~> 1.0) lumberjack (~> 1.0)
nenv (~> 0.1) nenv (~> 0.1)
notiffany (~> 0.0) notiffany (~> 0.0)
...@@ -105,7 +106,7 @@ GEM ...@@ -105,7 +106,7 @@ GEM
shellany (~> 0.0) shellany (~> 0.0)
thor (>= 0.18.1) thor (>= 0.18.1)
guard-compat (1.2.1) guard-compat (1.2.1)
guard-rspec (4.6.5) guard-rspec (4.7.3)
guard (~> 2.1) guard (~> 2.1)
guard-compat (~> 1.1) guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0) rspec (>= 2.99.0, < 4.0)
...@@ -113,11 +114,10 @@ GEM ...@@ -113,11 +114,10 @@ GEM
guard (~> 2.0) guard (~> 2.0)
rubocop (~> 0.20) rubocop (~> 0.20)
hashdiff (0.3.0) hashdiff (0.3.0)
httparty (0.13.7) httparty (0.14.0)
json (~> 1.8)
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
i18n (0.7.0) i18n (0.7.0)
jbuilder (2.4.1) jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1) activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2) multi_json (~> 1.2)
jquery-rails (4.1.1) jquery-rails (4.1.1)
...@@ -125,7 +125,7 @@ GEM ...@@ -125,7 +125,7 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3) json (1.8.3)
listen (3.1.4) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2) ruby_dep (~> 1.2)
...@@ -135,28 +135,34 @@ GEM ...@@ -135,28 +135,34 @@ GEM
mail (2.6.4) mail (2.6.4)
mime-types (>= 1.16, < 4) mime-types (>= 1.16, < 4)
method_source (0.8.2) method_source (0.8.2)
mime-types (3.0) mime-types (3.1)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221) mime-types-data (3.2016.0521)
mini_portile2 (2.0.0) mini_portile2 (2.1.0)
minitest (5.8.4) minitest (5.9.0)
multi_json (1.12.0) multi_json (1.12.1)
multi_test (0.1.2) multi_test (0.1.2)
multi_xml (0.5.5) multi_xml (0.5.5)
nenv (0.3.0) nenv (0.3.0)
nokogiri (1.6.7.2) nokogiri (1.6.8)
mini_portile2 (~> 2.0.0.rc2) mini_portile2 (~> 2.1.0)
notiffany (0.0.8) pkg-config (~> 1.1.7)
nokogiri (1.6.8-x64-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.1.1)
nenv (~> 0.1) nenv (~> 0.1)
shellany (~> 0.0) shellany (~> 0.0)
parser (2.3.1.0) parser (2.3.1.2)
ast (~> 2.2) ast (~> 2.2)
pkg-config (1.1.7)
powerpack (0.1.1) powerpack (0.1.1)
pry (0.10.3) pry (0.10.4)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
slop (~> 3.4) slop (~> 3.4)
rack (1.6.4) rack (1.6.4)
rack-cors (0.4.0)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.6) rails (4.2.6)
...@@ -184,46 +190,46 @@ GEM ...@@ -184,46 +190,46 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.1.0) rainbow (2.1.0)
rake (11.1.2) rake (11.2.2)
rb-fsevent (0.9.7) rb-fsevent (0.9.7)
rb-inotify (0.9.7) rb-inotify (0.9.7)
ffi (>= 0.5.0) ffi (>= 0.5.0)
rdoc (4.2.2) rdoc (4.2.2)
json (~> 1.4) json (~> 1.4)
rspec (3.4.0) rspec (3.5.0)
rspec-core (~> 3.4.0) rspec-core (~> 3.5.0)
rspec-expectations (~> 3.4.0) rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.4.0) rspec-mocks (~> 3.5.0)
rspec-core (3.4.4) rspec-core (3.5.2)
rspec-support (~> 3.4.0) rspec-support (~> 3.5.0)
rspec-expectations (3.4.0) rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0) rspec-support (~> 3.5.0)
rspec-json_expectations (1.3.0) rspec-json_expectations (1.4.0)
rspec-mocks (3.4.1) rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0) rspec-support (~> 3.5.0)
rspec-rails (3.4.2) rspec-rails (3.5.1)
actionpack (>= 3.0, < 4.3) actionpack (>= 3.0)
activesupport (>= 3.0, < 4.3) activesupport (>= 3.0)
railties (>= 3.0, < 4.3) railties (>= 3.0)
rspec-core (~> 3.4.0) rspec-core (~> 3.5.0)
rspec-expectations (~> 3.4.0) rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.4.0) rspec-mocks (~> 3.5.0)
rspec-support (~> 3.4.0) rspec-support (~> 3.5.0)
rspec-support (3.4.1) rspec-support (3.5.0)
rubocop (0.39.0) rubocop (0.42.0)
parser (>= 2.3.0.7, < 3.0) parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.0) ruby-progressbar (1.8.1)
ruby_dep (1.3.1) ruby_dep (1.4.0)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sass (3.4.22) sass (3.4.22)
sass-rails (5.0.4) sass-rails (5.0.6)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 6)
sass (~> 3.1) sass (~> 3.1)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
...@@ -233,36 +239,40 @@ GEM ...@@ -233,36 +239,40 @@ GEM
rdoc (~> 4.0) rdoc (~> 4.0)
shellany (0.0.1) shellany (0.0.1)
slop (3.6.0) slop (3.6.0)
spring (1.7.1) spring (1.7.2)
spring-commands-rspec (1.0.4) spring-commands-rspec (1.0.4)
spring (>= 0.9.1) spring (>= 0.9.1)
sprockets (3.6.0) sprockets (3.7.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (3.0.4) sprockets-rails (3.1.1)
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.11) sqlite3 (1.3.11)
sqlite3 (1.3.11-x64-mingw32)
terminal-notifier (1.6.3) terminal-notifier (1.6.3)
terminal-notifier-guard (1.7.0) terminal-notifier-guard (1.7.0)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.2) tilt (2.0.5)
turbolinks (2.5.3) turbolinks (5.0.1)
coffee-rails turbolinks-source (~> 5)
turbolinks-source (5.0.0)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.0) tzinfo-data (1.2016.6)
tzinfo (>= 1.0.0)
uglifier (3.0.1)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.0.5) unicode-display_width (1.1.0)
vcr (3.0.1) vcr (3.0.3)
web-console (2.3.0) web-console (2.3.0)
activemodel (>= 4.0) activemodel (>= 4.0)
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
webmock (2.0.2) webmock (2.1.0)
addressable (>= 2.3.6) addressable (>= 2.3.6)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff hashdiff
...@@ -271,6 +281,7 @@ GEM ...@@ -271,6 +281,7 @@ GEM
PLATFORMS PLATFORMS
ruby ruby
x64-mingw32
DEPENDENCIES DEPENDENCIES
byebug byebug
...@@ -285,6 +296,7 @@ DEPENDENCIES ...@@ -285,6 +296,7 @@ DEPENDENCIES
httparty httparty
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
rack-cors
rails (= 4.2.6) rails (= 4.2.6)
rspec-json_expectations rspec-json_expectations
rspec-rails (~> 3.1) rspec-rails (~> 3.1)
...@@ -297,10 +309,11 @@ DEPENDENCIES ...@@ -297,10 +309,11 @@ DEPENDENCIES
terminal-notifier terminal-notifier
terminal-notifier-guard terminal-notifier-guard
turbolinks turbolinks
tzinfo-data
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
vcr vcr
web-console (~> 2.0) web-console (~> 2.0)
webmock webmock
BUNDLED WITH BUNDLED WITH
1.12.4 1.12.5
...@@ -10,7 +10,7 @@ class Db < ActiveRecord::Base ...@@ -10,7 +10,7 @@ class Db < ActiveRecord::Base
def url def url
# return a custom URL if set # return a custom URL if set
return @url unless @url.nil? || @url.empty? return super unless super.nil? || super.empty?
# no default URL if no parent NILM available # no default URL if no parent NILM available
return '--error, no parent NILM--' if nilm.nil? return '--error, no parent NILM--' if nilm.nil?
# return the default URL" # return the default URL"
......
...@@ -9,13 +9,13 @@ class CreateNilm ...@@ -9,13 +9,13 @@ class CreateNilm
@warnings = [] @warnings = []
end end
def run(name:, url:, description: '') def run(name:, url:, description: '', db_url: '')
# create the NILM object # create the NILM object
@nilm = Nilm.new(name: name, url: url, @nilm = Nilm.new(name: name, url: url,
description: description) description: description)
@nilm.save @nilm.save
# create the database object and update it # create the database object and update it
db = Db.create(nilm: @nilm) db = Db.create(nilm: @nilm, url: db_url)
service = UpdateDb.new(db: db) service = UpdateDb.new(db: db)
adapter = DbAdapter.new(db.url) adapter = DbAdapter.new(db.url)
service.run(db_adapter: adapter) service.run(db_adapter: adapter)
......
...@@ -38,4 +38,12 @@ Rails.application.configure do ...@@ -38,4 +38,12 @@ Rails.application.configure do
# Raises error for missing translations # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
# allow cross origin requests
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :options]
end
end
end end
...@@ -14,4 +14,16 @@ RSpec.describe 'Db' do ...@@ -14,4 +14,16 @@ RSpec.describe 'Db' do
db.destroy db.destroy
expect(DbFolder.find_by_id(root_folder.id)).to be nil expect(DbFolder.find_by_id(root_folder.id)).to be nil
end end
describe 'url' do
it 'can be customized' do
db_x = Db.create(url: 'custom_string')
expect(db_x.url).to eq('custom_string')
end
it 'can be left as default' do
nilm = Nilm.create(url: "base")
db_x = Db.new(nilm: nilm, url: '')
expect(db_x.url).to eq("base/nilmdb")
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment