diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..04ba039 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] + +# Change these settings to your own preference +indent_style = space +indent_size = 2 + +# We recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 3ffb48a..828da4d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /spec/dummy/db/*.sqlite3 /spec/dummy/log/*.log /pkg +/doc/example/gemfiles/*.lock diff --git a/.travis.yml b/.travis.yml index b80c31a..a6b4b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,23 @@ language: ruby cache: bundler before_install: "cd $TEST_DIR" -install: "bundle install --jobs=3 --retry=3" +install: bundle install --jobs=3 --retry=3 +script: bundle exec rake env: - TEST_DIR=. - TEST_DIR=doc/example rvm: + - 2.3.0 + - 2.2.2 - 2.1.1 - 2.0.0 gemfile: - $TEST_DIR/gemfiles/rails-4.0.gemfile - $TEST_DIR/gemfiles/rails-4.1.gemfile + - $TEST_DIR/gemfiles/rails-5.0.gemfile +matrix: + exclude: + - rvm: 2.1.1 + gemfile: $TEST_DIR/gemfiles/rails-5.0.gemfile + - rvm: 2.0.0 + gemfile: $TEST_DIR/gemfiles/rails-5.0.gemfile diff --git a/Gemfile.lock b/Gemfile.lock index fa40578..53b5f78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,7 +4,7 @@ PATH daylight (0.9.0) actionpack-page_caching (~> 1.0.2) active_model_serializers (~> 0.8.2) - activeresource (~> 4.0.0) + activeresource (>= 4.0.0) haml (~> 4.0.5) hanna-bootstrap (~> 0.0.5) @@ -26,7 +26,7 @@ GEM activesupport (= 4.1.4) builder (~> 3.1) erubis (~> 2.7.0) - active_model_serializers (0.8.2) + active_model_serializers (0.8.3) activemodel (>= 3.0) activemodel (4.1.4) activesupport (= 4.1.4) @@ -49,21 +49,21 @@ GEM arel (5.0.1.20140414130214) builder (3.2.2) coderay (1.1.0) - coffee-script (2.3.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.8.0) + coffee-script-source (1.10.0) crack (0.4.2) safe_yaml (~> 1.0.0) diff-lcs (1.2.5) docile (1.1.5) erubis (2.7.0) - execjs (2.2.1) + execjs (2.6.0) factory_girl (4.4.0) activesupport (>= 3.0.0) faker (1.4.2) i18n (~> 0.5) - haml (4.0.5) + haml (4.0.7) tilt hanna-bootstrap (0.0.5) bundler @@ -75,7 +75,7 @@ GEM sass hike (1.2.3) i18n (0.6.11) - json (1.8.1) + json (1.8.3) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -120,8 +120,8 @@ GEM rspec-core (~> 2.14.0) rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) - safe_yaml (1.0.3) - sass (3.4.3) + safe_yaml (1.0.4) + sass (3.4.20) simplecov (0.9.0) docile (~> 1.1.0) multi_json @@ -165,3 +165,6 @@ DEPENDENCIES simplecov-rcov (~> 0.2.3) sqlite3 webmock (~> 1.18.0) + +BUNDLED WITH + 1.11.2 diff --git a/daylight.gemspec b/daylight.gemspec index 7ae9e37..dc40938 100644 --- a/daylight.gemspec +++ b/daylight.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| allow your ActiveResource client API to perform more like to ActiveRecord DESC - s.add_runtime_dependency 'activeresource', '~> 4.0.0' + s.add_runtime_dependency 'activeresource', '>= 4.0.0' s.add_runtime_dependency 'haml', '~> 4.0.5' s.add_runtime_dependency 'actionpack-page_caching', '~> 1.0.2' s.add_runtime_dependency 'hanna-bootstrap', '~> 0.0.5' diff --git a/doc/example/config/application.rb b/doc/example/config/application.rb index e33d2e3..7013ebf 100644 --- a/doc/example/config/application.rb +++ b/doc/example/config/application.rb @@ -1,6 +1,7 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' +ActiveSupport::Deprecation.debug = true Bundler.require(*Rails.groups) diff --git a/doc/example/config/environments/test.rb b/doc/example/config/environments/test.rb index 183211e..8cfe71b 100644 --- a/doc/example/config/environments/test.rb +++ b/doc/example/config/environments/test.rb @@ -13,8 +13,17 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + if Rails::VERSION::STRING == '4.2.0' + config.serve_static_files = true + else + config.serve_static_assets = true + end + + if Rails::VERSION::MAJOR >= 5 + config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'} + else + config.static_cache_control = "public, max-age=3600" + end # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/doc/example/gemfiles/rails-4.0.gemfile b/doc/example/gemfiles/rails-4.0.gemfile index 306134c..ed269e3 100644 --- a/doc/example/gemfiles/rails-4.0.gemfile +++ b/doc/example/gemfiles/rails-4.0.gemfile @@ -9,5 +9,6 @@ gem 'daylight', path: '../../..' group :test do gem 'rspec-rails', '~> 2.14.0' + gem 'test-unit', '~> 3.0' gem 'artifice', '~> 0.6' end diff --git a/doc/example/gemfiles/rails-4.2.gemfile b/doc/example/gemfiles/rails-4.2.gemfile new file mode 100644 index 0000000..06c8d9c --- /dev/null +++ b/doc/example/gemfiles/rails-4.2.gemfile @@ -0,0 +1,13 @@ +source 'https://rubygems.org' + +gem 'rails', '~> 4.2.0' +gem 'activeresource', '4.0.0' + +gem 'sqlite3', '1.3.9' + +gem 'daylight', path: '../../..' + +group :test do + gem 'rspec-rails', '~> 2.14.0' + gem 'artifice', '~> 0.6' +end diff --git a/doc/example/gemfiles/rails-5.0.gemfile b/doc/example/gemfiles/rails-5.0.gemfile new file mode 100644 index 0000000..d46866c --- /dev/null +++ b/doc/example/gemfiles/rails-5.0.gemfile @@ -0,0 +1,15 @@ +source 'https://rubygems.org' + +gem 'rails', '~> 5.0.x' +gem 'activeresource', '5.0.0', github: 'rails/activeresource' +gem 'activemodel-serializers-xml', github: 'rails/activemodel-serializers-xml' + +gem 'sqlite3', '1.3.9' + +gem 'daylight', path: '../../..' +gem 'rails-observers', github: 'rails/rails-observers' + +group :test do + gem 'rspec-rails', '~> 2.14.0' + gem 'artifice', '~> 0.6' +end diff --git a/gemfiles/rails-5.0.gemfile b/gemfiles/rails-5.0.gemfile new file mode 100644 index 0000000..6441fe8 --- /dev/null +++ b/gemfiles/rails-5.0.gemfile @@ -0,0 +1,8 @@ +source "http://rubygems.org" + +gem 'rails', '~> 5.x' +gem 'activeresource', '5.0.0', github: 'rails/activeresource' +gem 'activemodel-serializers-xml', github: 'rails/activemodel-serializers-xml' +gem 'rails-observers', github: 'rails/rails-observers' + +gemspec path: "../" diff --git a/rails/daylight/refiners.rb b/rails/daylight/refiners.rb index 8193b4c..b4291a2 100644 --- a/rails/daylight/refiners.rb +++ b/rails/daylight/refiners.rb @@ -126,7 +126,9 @@ def reflection_names # Supplies where conditions and returns the resulting +ActiveRecord::Relation+. # Raises +ArgumentError+ if the keys are not valid attributes on the model. def filter_by params - where (params||{}).with_indifferent_access.assert_valid_keys(attribute_names + reflection_names) + params = params || {} + params = params.with_indifferent_access rescue params.to_h + where params.assert_valid_keys(attribute_names + reflection_names) end ## diff --git a/rails/extensions/route_options.rb b/rails/extensions/route_options.rb index b516046..812f491 100644 --- a/rails/extensions/route_options.rb +++ b/rails/extensions/route_options.rb @@ -10,9 +10,9 @@ module RouteOptions def set_member_mappings_for_resource super - associated = parent_resource.options[:associated] || [] - remoted = parent_resource.options[:remoted] || [] - scopes = parent_resource.options[:scopes] + associated = resource_options[:associated] || [] + remoted = resource_options[:remoted] || [] + scopes = resource_options[:scopes] model_class = controller_model_class model_class.whitelist_scopes(*scopes) if scopes.present? @@ -39,6 +39,14 @@ def controller_model_class Rails.logger.warn "Could not lookup model for #{parent_resource.name} to apply remoted." end + def resource_options + if Rails::VERSION::MAJOR >= 5 + parent_resource.instance_variable_get(:@options) + else + parent_resource.options + end + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af38fba..5fad7a6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,7 +31,11 @@ # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. - config.use_transactional_fixtures = true + if Rails::VERSION::MAJOR >= 5 + config.use_transactional_tests = true + else + config.use_transactional_fixtures = true + end # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of