From 4ae08d3244b0d522c46d5202345e61c7c401fa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ba=CC=88uerlein?= Date: Thu, 24 Nov 2016 10:47:05 +0100 Subject: [PATCH] drop ruby 1.8 syntax, rubocop enhancements --- Gemfile | 4 +- Rakefile | 17 +- acts_as_api.gemspec | 26 +- lib/acts_as_api.rb | 22 +- lib/acts_as_api/adapters.rb | 2 +- lib/acts_as_api/api_template.rb | 48 ++- lib/acts_as_api/base.rb | 31 +- lib/acts_as_api/collection.rb | 3 +- lib/acts_as_api/config.rb | 5 - lib/acts_as_api/exceptions.rb | 4 +- lib/acts_as_api/rails_renderer.rb | 2 - lib/acts_as_api/rendering.rb | 17 +- lib/acts_as_api/responder.rb | 21 +- lib/acts_as_api/version.rb | 2 +- spec/active_record_dummy/Gemfile | 9 +- spec/active_record_dummy/app/models/user.rb | 63 ++-- spec/active_record_dummy/config.ru | 2 +- .../active_record_dummy/config/application.rb | 4 +- spec/active_record_dummy/config/boot.rb | 2 +- .../config/environments/test.rb | 4 +- .../config/initializers/session_store.rb | 2 +- .../config/initializers/wrap_parameters.rb | 2 +- spec/active_record_dummy/config/routes.rb | 58 +--- .../migrate/20110214201640_create_tables.rb | 51 ++-- spec/active_record_dummy/db/schema.rb | 56 ++-- spec/active_record_dummy/script/rails | 4 +- .../plain_objects_controller_spec.rb | 23 +- .../respond_with_users_controller_spec.rb | 113 +++---- spec/controllers/users_controller_spec.rb | 5 +- spec/models/model_spec.rb | 36 ++- spec/mongoid_dummy/Gemfile | 7 +- spec/mongoid_dummy/app/models/.#profile.rb | 1 + spec/mongoid_dummy/app/models/profile.rb | 12 +- spec/mongoid_dummy/app/models/task.rb | 20 +- spec/mongoid_dummy/app/models/untouched.rb | 8 +- spec/mongoid_dummy/app/models/user.rb | 26 +- spec/mongoid_dummy/config.ru | 2 +- spec/mongoid_dummy/config/application.rb | 14 +- spec/mongoid_dummy/config/boot.rb | 2 +- .../config/environments/development.rb | 1 - .../config/environments/production.rb | 1 - .../mongoid_dummy/config/environments/test.rb | 4 +- .../initializers/include_acts_as_api.rb | 2 +- .../config/initializers/session_store.rb | 2 +- .../config/initializers/wrap_parameters.rb | 3 +- spec/mongoid_dummy/config/routes.rb | 58 +--- spec/mongoid_dummy/script/rails | 4 +- spec/shared_engine/Gemfile | 2 +- spec/shared_engine/Rakefile | 5 +- .../shared_engine/plain_objects_controller.rb | 4 +- .../respond_with_users_controller.rb | 28 +- .../shared_engine/users_controller.rb | 36 ++- spec/shared_engine/app/models/plain_object.rb | 4 +- .../shared_engine/app/models/user_template.rb | 57 ++-- spec/shared_engine/dummy/config.ru | 2 +- .../shared_engine/dummy/config/application.rb | 15 +- spec/shared_engine/dummy/config/boot.rb | 2 +- .../dummy/config/environments/test.rb | 4 +- .../config/initializers/session_store.rb | 2 +- .../config/initializers/wrap_parameters.rb | 2 +- spec/shared_engine/dummy/config/routes.rb | 3 +- spec/shared_engine/dummy/script/rails | 4 +- spec/shared_engine/lib/shared_engine.rb | 2 +- .../lib/shared_engine/version.rb | 2 +- spec/shared_engine/shared_engine.gemspec | 22 +- spec/spec_helper.rb | 14 +- spec/support/api_test_helpers.rb | 2 - spec/support/controller_examples.rb | 281 ++++++++---------- spec/support/it_supports.rb | 2 +- spec/support/model_examples/associations.rb | 122 ++++---- spec/support/model_examples/callbacks.rb | 36 +-- spec/support/model_examples/closures.rb | 30 +- spec/support/model_examples/conditional_if.rb | 88 +++--- .../model_examples/conditional_unless.rb | 88 +++--- spec/support/model_examples/enabled.rb | 7 +- spec/support/model_examples/extending.rb | 57 ++-- spec/support/model_examples/methods.rb | 14 +- spec/support/model_examples/options.rb | 44 ++- spec/support/model_examples/renaming.rb | 27 +- spec/support/model_examples/simple.rb | 12 +- spec/support/model_examples/sub_nodes.rb | 58 ++-- spec/support/model_examples/undefined.rb | 10 +- spec/support/model_examples/untouched.rb | 10 +- spec/support/simple_fixtures.rb | 49 +-- 84 files changed, 790 insertions(+), 1162 deletions(-) create mode 120000 spec/mongoid_dummy/app/models/.#profile.rb diff --git a/Gemfile b/Gemfile index bf54b64..a21b303 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source 'http://rubygems.org' # Specify your gem's dependencies in acts_as_api.gemspec gemspec @@ -15,5 +15,5 @@ group :test do gem 'rspec-rails', '>= 2.5.0' gem 'webrat' gem 'responders' - gem 'shared_engine', :path => './spec/shared_engine' + gem 'shared_engine', path: './spec/shared_engine' end diff --git a/Rakefile b/Rakefile index 1fddc99..2e324f6 100644 --- a/Rakefile +++ b/Rakefile @@ -7,13 +7,12 @@ Bundler::GemHelper.install_tasks RSpec::Core::RakeTask.new namespace :spec do - supported_orms = %w(mongoid active_record) supported_orms.each do |orm| desc "Run #{orm} specs only" RSpec::Core::RakeTask.new(orm) do |t| - t.rspec_opts = ["--color"] + t.rspec_opts = ['--color'] end task "prepare_#{orm}" do @@ -23,26 +22,20 @@ namespace :spec do Rake::Task["spec:#{orm}"].prerequisites << "spec:prepare_#{orm}" end - -# task :all => supported_orms.map{|orm| "spec:#{orm}"} - desc "Runs specs for all ORMs (#{supported_orms.join(', ')})" task :all do supported_orms.each do |orm| puts "Starting to run specs for #{orm}..." system("bundle exec rake spec:#{orm}") - raise "#{orm} failed!" unless $?.exitstatus == 0 + raise "#{orm} failed!" unless $?.exitstatus.zero? end end end +task default: 'spec:all' -gemspec = Gem::Specification.load("acts_as_api.gemspec") - -task :default => "spec:all" - -desc "Generate the gh_pages site" +desc 'Generate the gh_pages site' task :rocco do - system "bundle exec rocco examples/introduction/index.rb -t examples/introduction/layout.mustache" + system 'bundle exec rocco examples/introduction/index.rb -t examples/introduction/layout.mustache' end diff --git a/acts_as_api.gemspec b/acts_as_api.gemspec index c29a0a8..b967143 100644 --- a/acts_as_api.gemspec +++ b/acts_as_api.gemspec @@ -1,20 +1,20 @@ # encoding: utf-8 -$:.push File.expand_path("../lib", __FILE__) -require "acts_as_api/version" +$LOAD_PATH.push File.expand_path('../lib', __FILE__) +require 'acts_as_api/version' Gem::Specification.new do |s| - s.name = "acts_as_api" + s.name = 'acts_as_api' s.version = ActsAsApi::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Christian Bäuerlein"] - s.email = ["christian@ffwdme.com"] - s.homepage = "https://github.com/fabrik42/acts_as_api" - s.summary = %q{Makes creating XML/JSON responses in Rails 3, 4 and 5 easy and fun.} - s.description = %q{acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.} + s.authors = ['Christian Bäuerlein'] + s.email = ['christian@ffwdme.com'] + s.homepage = 'https://github.com/fabrik42/acts_as_api' + s.summary = 'Makes creating XML/JSON responses in Rails 3, 4 and 5 easy and fun.' + s.description = 'acts_as_api enriches the models and controllers of your app in a rails-like way so you can easily determine how your XML/JSON API responses should look like.' - s.add_dependency('activemodel','>= 3.0.0') - s.add_dependency('activesupport','>= 3.0.0') - s.add_dependency('rack','>= 1.1.0') + s.add_dependency('activemodel', '>= 3.0.0') + s.add_dependency('activesupport', '>= 3.0.0') + s.add_dependency('rack', '>= 1.1.0') s.add_development_dependency('rails', ['>= 3.2.22.2']) s.add_development_dependency('mongoid', ['>= 3.0.1']) @@ -23,6 +23,6 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + s.require_paths = ['lib'] end diff --git a/lib/acts_as_api.rb b/lib/acts_as_api.rb index 3e6aaf6..0561447 100644 --- a/lib/acts_as_api.rb +++ b/lib/acts_as_api.rb @@ -1,12 +1,12 @@ require 'active_model' require 'active_support/core_ext/class' -$:.unshift(File.dirname(__FILE__)) unless - $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) +$LOAD_PATH.unshift(File.dirname(__FILE__)) unless + $LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__))) -require "acts_as_api/collection" -require "acts_as_api/rails_renderer" -require "acts_as_api/exceptions" +require 'acts_as_api/collection' +require 'acts_as_api/rails_renderer' +require 'acts_as_api/exceptions' # acts_as_api is a gem that aims to make the construction of JSON and XML # responses in Rails 3, 4 and 5 easy and fun. @@ -17,12 +17,12 @@ # acts_as_api uses the default serializers of your rails app and doesn't # force you into more dependencies. module ActsAsApi - autoload :Config, "acts_as_api/config" - autoload :ApiTemplate, "acts_as_api/api_template" - autoload :Base, "acts_as_api/base" - autoload :Rendering, "acts_as_api/rendering" - autoload :Responder, "acts_as_api/responder" - autoload :Adapters, "acts_as_api/adapters" + autoload :Config, 'acts_as_api/config' + autoload :ApiTemplate, 'acts_as_api/api_template' + autoload :Base, 'acts_as_api/base' + autoload :Rendering, 'acts_as_api/rendering' + autoload :Responder, 'acts_as_api/responder' + autoload :Adapters, 'acts_as_api/adapters' end # Neccessary to render an Array of models, e.g. the result of a search. diff --git a/lib/acts_as_api/adapters.rb b/lib/acts_as_api/adapters.rb index 80d9a7f..02d8878 100644 --- a/lib/acts_as_api/adapters.rb +++ b/lib/acts_as_api/adapters.rb @@ -1,5 +1,5 @@ module ActsAsApi module Adapters - autoload :Mongoid, "acts_as_api/adapters/mongoid" + autoload :Mongoid, 'acts_as_api/adapters/mongoid' end end diff --git a/lib/acts_as_api/api_template.rb b/lib/acts_as_api/api_template.rb index 161ad54..11eec42 100644 --- a/lib/acts_as_api/api_template.rb +++ b/lib/acts_as_api/api_template.rb @@ -8,7 +8,6 @@ module ActsAsApi # Please note that +ApiTemplate+ inherits from +Hash+ so you can use all # kind of +Hash+ and +Enumerable+ methods to manipulate the template. class ApiTemplate < Hash - # The name of the api template as a Symbol. attr_accessor :api_template @@ -21,7 +20,7 @@ def initialize(api_template) def merge!(other_hash, &block) super - self.options.merge!(other_hash.options) if other_hash.respond_to?(:options) + options.merge!(other_hash.options) if other_hash.respond_to?(:options) end # Adds a field to the api template @@ -44,7 +43,7 @@ def add(val, options = {}) # Removes a field from the template def remove(field) - self.delete(field) + delete(field) end # Returns the options of a field in the api template @@ -67,9 +66,9 @@ def api_template_for(fieldset, field) # the response based on the conditional options passed. def allowed_to_render?(fieldset, field, model, options) return true unless fieldset.is_a? ActsAsApi::ApiTemplate - + fieldset_options = fieldset.options_for(field) - + if fieldset_options[:unless] !(condition_fulfilled?(model, fieldset_options[:unless], options)) elsif fieldset_options[:if] @@ -112,28 +111,27 @@ def to_response_hash(model, fieldset = self, options = {}) api_output end - private - - def process_value(model, value, options) - case value - when Symbol - model.send(value) - when Proc - call_proc(value,model,options) - when String - value.split('.').inject(model) { |result, method| result.send(method) } - when Hash - to_response_hash(model, value) + private + + def process_value(model, value, options) + case value + when Symbol + model.send(value) + when Proc + call_proc(value, model, options) + when String + value.split('.').inject(model) { |result, method| result.send(method) } + when Hash + to_response_hash(model, value) + end end - end - def call_proc(the_proc,model,options) - if the_proc.arity == 2 - the_proc.call(model, options) - else - the_proc.call(model) + def call_proc(the_proc, model, options) + if the_proc.arity == 2 + the_proc.call(model, options) + else + the_proc.call(model) + end end - end - end end diff --git a/lib/acts_as_api/base.rb b/lib/acts_as_api/base.rb index 24c37ca..e704c7a 100644 --- a/lib/acts_as_api/base.rb +++ b/lib/acts_as_api/base.rb @@ -10,7 +10,6 @@ def acts_as_api? # When invoked, it enriches the current model with the # class and instance methods to act as api. def acts_as_api - class_eval do include ActsAsApi::Base::InstanceMethods extend ActsAsApi::Base::ClassMethods @@ -19,13 +18,11 @@ def acts_as_api if block_given? yield ActsAsApi::Config end - end module ClassMethods - - def acts_as_api?#:nodoc: - self.included_modules.include?(InstanceMethods) + def acts_as_api? #:nodoc: + included_modules.include?(InstanceMethods) end # Determines the attributes, methods of the model that are accessible in the api response. @@ -33,9 +30,7 @@ def acts_as_api?#:nodoc: # So once the model acts as api, you have to determine all attributes here that should # be contained in the api responses. def api_accessible(api_template, options = {}, &block) - attributes = api_accessible_attributes(api_template).try(:dup) || ApiTemplate.new(api_template) - attributes.merge!(api_accessible_attributes(options[:extend])) if options[:extend] if block_given? @@ -53,12 +48,11 @@ def api_accessible_attributes(api_template) end module InstanceMethods - # Creates the api response of the model and returns it as a Hash. # Will raise an exception if the passed api template is not defined for the model def as_api_response(api_template, options = {}) api_attributes = self.class.api_accessible_attributes(api_template) - raise ActsAsApi::TemplateNotFoundError.new("acts_as_api template :#{api_template.to_s} was not found for model #{self.class}") if api_attributes.nil? + raise ActsAsApi::TemplateNotFoundError.new("acts_as_api template :#{api_template} was not found for model #{self.class}") if api_attributes.nil? before_api_response(api_template) response_hash = around_api_response(api_template) do @@ -69,20 +63,17 @@ def as_api_response(api_template, options = {}) response_hash end - protected - - def before_api_response(api_remplate) - end + protected - def after_api_response(api_remplate) - end + def before_api_response(_api_template) + end - def around_api_response(api_remplate) - yield - end + def after_api_response(_api_template) + end + def around_api_response(_api_template) + yield + end end - end - end diff --git a/lib/acts_as_api/collection.rb b/lib/acts_as_api/collection.rb index 87bed7a..ef51834 100644 --- a/lib/acts_as_api/collection.rb +++ b/lib/acts_as_api/collection.rb @@ -6,12 +6,11 @@ module Collection def as_api_response(api_template, options = {}) collect do |item| if item.respond_to?(:as_api_response) - item.as_api_response(api_template,options) + item.as_api_response(api_template, options) else item end end end - end end diff --git a/lib/acts_as_api/config.rb b/lib/acts_as_api/config.rb index a2c1c28..eb94d20 100644 --- a/lib/acts_as_api/config.rb +++ b/lib/acts_as_api/config.rb @@ -1,9 +1,6 @@ module ActsAsApi - module Config - class << self - attr_writer :accepted_api_formats, :dasherize_for, :include_root_in_json_collections, :add_root_node_for, :default_root, :allow_jsonp_callback, :add_http_status_to_jsonp_response # The accepted response formats @@ -52,7 +49,5 @@ def add_http_status_to_jsonp_response @add_http_status_to_jsonp_response.nil? ? true : @add_http_status_to_jsonp_response end end - end - end diff --git a/lib/acts_as_api/exceptions.rb b/lib/acts_as_api/exceptions.rb index d3b6fdc..dc85496 100644 --- a/lib/acts_as_api/exceptions.rb +++ b/lib/acts_as_api/exceptions.rb @@ -1,4 +1,4 @@ module ActsAsApi class ActsAsApiError < RuntimeError; end - class TemplateNotFoundError < ActsAsApiError; end -end \ No newline at end of file + class TemplateNotFoundError < ActsAsApiError; end +end diff --git a/lib/acts_as_api/rails_renderer.rb b/lib/acts_as_api/rails_renderer.rb index bd986cd..4b610d9 100644 --- a/lib/acts_as_api/rails_renderer.rb +++ b/lib/acts_as_api/rails_renderer.rb @@ -3,7 +3,6 @@ module ActsAsApi # # See ActsAsApi::Config about the possible configurations module RailsRenderer - def self.setup ActionController.add_renderer :acts_as_api_jsonp do |json, options| json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str) @@ -16,6 +15,5 @@ def self.setup self.response_body = json end end - end end diff --git a/lib/acts_as_api/rendering.rb b/lib/acts_as_api/rendering.rb index 08ebd1b..6f05947 100644 --- a/lib/acts_as_api/rendering.rb +++ b/lib/acts_as_api/rendering.rb @@ -1,9 +1,7 @@ module ActsAsApi - # The methods of this module are included into the AbstractController::Rendering # module. module Rendering - # Provides an alternative to the +render+ method used within the controller # to simply generate API outputs. # @@ -23,13 +21,13 @@ def render_for_api(api_template_or_options, render_options) api_format_options = {} ActsAsApi::Config.accepted_api_formats.each do |item| - if render_options.has_key?(item) + if render_options.key?(item) api_format_options[item] = render_options[item] render_options.delete item end end - meta_hash = render_options[:meta] if render_options.has_key?(:meta) + meta_hash = render_options[:meta] if render_options.key?(:meta) api_format = api_format_options.keys.first api_model = api_format_options.values.first @@ -64,17 +62,14 @@ def render_for_api(api_template_or_options, render_options) output_params[:root] = api_root_name - #output_params[:root] = output_params[:root].camelize if render_options.has_key?(:camelize) && render_options[:camelize] - #output_params[:root] = output_params[:root].dasherize if !render_options.has_key?(:dasherize) || render_options[:dasherize] - api_response = api_model.as_api_response(api_template) if api_response.is_a?(Array) && api_format.to_sym == :json && ActsAsApi::Config.include_root_in_json_collections - api_response = api_response.collect{|f| { api_root_name.singularize => f } } + api_response = api_response.collect { |f| { api_root_name.singularize => f } } end - if meta_hash or ActsAsApi::Config.add_root_node_for.include? api_format - api_response = { api_root_name.to_sym => api_response} + if meta_hash || ActsAsApi::Config.add_root_node_for.include?(api_format) + api_response = { api_root_name.to_sym => api_response } end api_response = meta_hash.merge api_response if meta_hash @@ -89,7 +84,5 @@ def render_for_api(api_template_or_options, render_options) render output_params end - end - end diff --git a/lib/acts_as_api/responder.rb b/lib/acts_as_api/responder.rb index e64b36c..979d7b5 100644 --- a/lib/acts_as_api/responder.rb +++ b/lib/acts_as_api/responder.rb @@ -18,22 +18,17 @@ module ActsAsApi # end # # The `:api_template` parameter is required so the responder knows which api template it should render. - class Responder < ActionController::Responder - module Module - # Overrides the base implementation of display, replacing it with - # the render_for_api method whenever api_template is specified. - def display(resource, given_options={}) - api_template = options[:api_template] + # Overrides the base implementation of display, replacing it with + # the render_for_api method whenever api_template is specified. + def display(resource, given_options = {}) + api_template = options[:api_template] - if api_template.nil? || !resource.respond_to?(:as_api_response) - controller.render given_options.merge!(options).merge!(format => resource) - else - controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource) - end + if api_template.nil? || !resource.respond_to?(:as_api_response) + controller.render given_options.merge!(options).merge!(format => resource) + else + controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource) end end - - include Module end end diff --git a/lib/acts_as_api/version.rb b/lib/acts_as_api/version.rb index 70e5b1d..9bf1231 100644 --- a/lib/acts_as_api/version.rb +++ b/lib/acts_as_api/version.rb @@ -1,3 +1,3 @@ module ActsAsApi - VERSION = "0.4.4" + VERSION = '0.4.4'.freeze end diff --git a/spec/active_record_dummy/Gemfile b/spec/active_record_dummy/Gemfile index b75a090..19f9e35 100644 --- a/spec/active_record_dummy/Gemfile +++ b/spec/active_record_dummy/Gemfile @@ -2,15 +2,12 @@ source 'https://rubygems.org' gem 'rails', '5.0.0.1' -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - gem 'sqlite3' -gem 'shared_engine', :path => '../shared_engine' -gem 'acts_as_api', :path => '../../' +gem 'shared_engine', path: '../shared_engine' +gem 'acts_as_api', path: '../../' group :test do gem 'rspec-rails', '>= 2.5.0' - gem 'webrat' + gem 'webrat' end diff --git a/spec/active_record_dummy/app/models/user.rb b/spec/active_record_dummy/app/models/user.rb index 0a9bc9d..f2da99b 100644 --- a/spec/active_record_dummy/app/models/user.rb +++ b/spec/active_record_dummy/app/models/user.rb @@ -1,5 +1,5 @@ class User < ActiveRecord::Base - validates :first_name, :last_name, :presence => true + validates :first_name, :last_name, presence: true has_many :tasks @@ -17,11 +17,11 @@ class User < ActiveRecord::Base end api_accessible :rename_last_name do |t| - t.add :last_name, :as => :family_name + t.add :last_name, as: :family_name end api_accessible :rename_full_name do |t| - t.add :full_name, :as => :other_full_name + t.add :full_name, as: :other_full_name end api_accessible :with_former_value do |t| @@ -29,19 +29,19 @@ class User < ActiveRecord::Base t.add :last_name end - api_accessible :age_and_first_name, :extend => :with_former_value do |t| + api_accessible :age_and_first_name, extend: :with_former_value do |t| t.add :age t.remove :last_name end api_accessible :calling_a_proc do |t| - t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name - t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param + t.add proc { |model| model.full_name.upcase }, as: :all_caps_name + t.add proc { |_| Time.now.class.to_s }, as: :without_param end api_accessible :calling_a_lambda do |t| - t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name - t.add lambda{|model| Time.now.class.to_s }, :as => :without_param + t.add ->(model) { model.full_name.upcase }, as: :all_caps_name + t.add ->(_) { Time.now.class.to_s }, as: :without_param end api_accessible :include_tasks do |t| t.add :tasks @@ -53,19 +53,19 @@ class User < ActiveRecord::Base api_accessible :other_sub_template do |t| t.add :first_name - t.add :tasks, :template => :other_template + t.add :tasks, template: :other_template end api_accessible :include_completed_tasks do |t| - t.add "tasks.completed.all", :as => :completed_tasks + t.add 'tasks.completed.all', as: :completed_tasks end api_accessible :sub_node do |t| - t.add Hash[:foo => :say_something], :as => :sub_nodes + t.add Hash[foo: :say_something], as: :sub_nodes end api_accessible :nested_sub_node do |t| - t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes + t.add Hash[:foo, Hash[:bar, :last_name]], as: :sub_nodes end api_accessible :nested_sub_hash do |t| @@ -74,46 +74,46 @@ class User < ActiveRecord::Base api_accessible :if_over_thirty do |t| t.add :first_name - t.add :last_name, :if => :over_thirty? + t.add :last_name, if: :over_thirty? end api_accessible :if_returns_nil do |t| t.add :first_name - t.add :last_name, :if => :return_nil + t.add :last_name, if: :return_nil end api_accessible :if_over_thirty_proc do |t| t.add :first_name - t.add :last_name, :if => lambda{|u| u.over_thirty? } + t.add :last_name, if: ->(model) { model.over_thirty? } end api_accessible :if_returns_nil_proc do |t| t.add :first_name - t.add :last_name, :if => lambda{|u| nil } + t.add :last_name, if: ->(_) { nil } end api_accessible :unless_under_thirty do |t| t.add :first_name - t.add :last_name, :unless => :under_thirty? + t.add :last_name, unless: :under_thirty? end api_accessible :unless_returns_nil do |t| t.add :first_name - t.add :last_name, :unless => :return_nil + t.add :last_name, unless: :return_nil end api_accessible :unless_under_thirty_proc do |t| t.add :first_name - t.add :last_name, :unless => lambda{|u| u.under_thirty? } + t.add :last_name, unless: ->(model) { model.under_thirty? } end api_accessible :unless_returns_nil_proc do |t| t.add :first_name - t.add :last_name, :unless => lambda{|u| nil } + t.add :last_name, unless: ->(_) { nil } end api_accessible :with_prefix_name_only do |t| - t.add lambda{|model| 'true' }, :as => :prefix + t.add ->(_) { 'true' }, as: :prefix t.add :first_name t.add :last_name end @@ -121,17 +121,17 @@ class User < ActiveRecord::Base api_accessible :name_only_with_postfix do |t| t.add :first_name t.add :last_name - t.add lambda{|model| 'true' }, :as => :postfix + t.add ->(_) { 'true' }, as: :postfix end api_accessible :with_prefix_name_only_with_postfix do |t| - t.add lambda{|model| 'true' }, :as => :prefix + t.add ->(_) { 'true' }, as: :prefix t.add :first_name t.add :last_name - t.add lambda{|model| 'true' }, :as => :postfix + t.add ->(_) { 'true' }, as: :postfix end - def before_api_response(api_response) + def before_api_response(_api_response) @before_api_response_called = true end @@ -139,7 +139,7 @@ def before_api_response_called? !!@before_api_response_called end - def after_api_response(api_response) + def after_api_response(_api_response) @after_api_response_called = true end @@ -151,8 +151,8 @@ def skip_api_response=(should_skip) @skip_api_response = should_skip end - def around_api_response(api_response) - @skip_api_response ? { :skipped => true } : yield + def around_api_response(_api_response) + @skip_api_response ? { skipped: true } : yield end def over_thirty? @@ -172,14 +172,13 @@ def full_name end def say_something - "something" + 'something' end def sub_hash { - :foo => "bar", - :hello => "world" + foo: 'bar', + hello: 'world' } end - end diff --git a/spec/active_record_dummy/config.ru b/spec/active_record_dummy/config.ru index 48484a7..9a7052d 100644 --- a/spec/active_record_dummy/config.ru +++ b/spec/active_record_dummy/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run ActiveRecordDummy::Application diff --git a/spec/active_record_dummy/config/application.rb b/spec/active_record_dummy/config/application.rb index c73d7de..2e683c6 100644 --- a/spec/active_record_dummy/config/application.rb +++ b/spec/active_record_dummy/config/application.rb @@ -4,7 +4,7 @@ if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) + Bundler.require(*Rails.groups(assets: %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end @@ -34,7 +34,7 @@ class Application < Rails::Application # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" + config.encoding = 'utf-8' # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] diff --git a/spec/active_record_dummy/config/boot.rb b/spec/active_record_dummy/config/boot.rb index 4489e58..f2830ae 100644 --- a/spec/active_record_dummy/config/boot.rb +++ b/spec/active_record_dummy/config/boot.rb @@ -3,4 +3,4 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/spec/active_record_dummy/config/environments/test.rb b/spec/active_record_dummy/config/environments/test.rb index 80896cc..1ea5c25 100644 --- a/spec/active_record_dummy/config/environments/test.rb +++ b/spec/active_record_dummy/config/environments/test.rb @@ -14,14 +14,14 @@ config.whiny_nils = true # Show full error reports and disable caching - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/spec/active_record_dummy/config/initializers/session_store.rb b/spec/active_record_dummy/config/initializers/session_store.rb index acb8413..cdbbc48 100644 --- a/spec/active_record_dummy/config/initializers/session_store.rb +++ b/spec/active_record_dummy/config/initializers/session_store.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -ActiveRecordDummy::Application.config.session_store :cookie_store, :key => '_active_record_dummy_session' +ActiveRecordDummy::Application.config.session_store :cookie_store, key: '_active_record_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/spec/active_record_dummy/config/initializers/wrap_parameters.rb b/spec/active_record_dummy/config/initializers/wrap_parameters.rb index da4fb07..999df20 100644 --- a/spec/active_record_dummy/config/initializers/wrap_parameters.rb +++ b/spec/active_record_dummy/config/initializers/wrap_parameters.rb @@ -5,7 +5,7 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters :format => [:json] + wrap_parameters format: [:json] end # Disable root element in JSON by default. diff --git a/spec/active_record_dummy/config/routes.rb b/spec/active_record_dummy/config/routes.rb index 8b285e3..d0022a0 100644 --- a/spec/active_record_dummy/config/routes.rb +++ b/spec/active_record_dummy/config/routes.rb @@ -1,59 +1,3 @@ ActiveRecordDummy::Application.routes.draw do - mount SharedEngine::Engine => "/shared", :as => "shared" - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id))(.:format)' + mount SharedEngine::Engine => '/shared', :as => 'shared' end diff --git a/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb b/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb index 9cb5e61..840ec0d 100644 --- a/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +++ b/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb @@ -1,35 +1,34 @@ class CreateTables < ActiveRecord::Migration def self.up + create_table 'users', force: true do |t| + t.string 'first_name' + t.string 'last_name' + t.integer 'age' + t.boolean 'active' + t.datetime 'created_at' + t.datetime 'updated_at' + end - create_table "users", :force => true do |t| - t.string "first_name" - t.string "last_name" - t.integer "age" - t.boolean "active" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'tasks', force: true do |t| + t.integer 'user_id' + t.string 'heading' + t.string 'description' + t.integer 'time_spent' + t.boolean 'done' + t.datetime 'created_at' + t.datetime 'updated_at' end - create_table "tasks", :force => true do |t| - t.integer "user_id" - t.string "heading" - t.string "description" - t.integer "time_spent" - t.boolean "done" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'profiles', force: true do |t| + t.integer 'user_id' + t.string 'avatar' + t.string 'homepage' + t.datetime 'created_at' + t.datetime 'updated_at' end - - create_table "profiles", :force => true do |t| - t.integer "user_id" - t.string "avatar" - t.string "homepage" - t.datetime "created_at" - t.datetime "updated_at" - end - + create_table :untoucheds do |t| - t.string "nothing" + t.string 'nothing' t.timestamps end @@ -39,6 +38,6 @@ def self.down drop_table :untoucheds drop_table :profiles drop_table :tasks - drop_table :users + drop_table :users end end diff --git a/spec/active_record_dummy/db/schema.rb b/spec/active_record_dummy/db/schema.rb index b399982..bfb8e28 100644 --- a/spec/active_record_dummy/db/schema.rb +++ b/spec/active_record_dummy/db/schema.rb @@ -10,38 +10,36 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110214201640) do +ActiveRecord::Schema.define(version: 20110214201640) do + create_table 'tasks', force: true do |t| + t.integer 'user_id' + t.string 'heading' + t.string 'description' + t.integer 'time_spent' + t.boolean 'done' + t.datetime 'created_at' + t.datetime 'updated_at' + end - create_table "tasks", :force => true do |t| - t.integer "user_id" - t.string "heading" - t.string "description" - t.integer "time_spent" - t.boolean "done" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'profiles', force: true do |t| + t.integer 'user_id' + t.string 'avatar' + t.string 'homepage' + t.datetime 'created_at' + t.datetime 'updated_at' end - - create_table "profiles", :force => true do |t| - t.integer "user_id" - t.string "avatar" - t.string "homepage" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "users", :force => true do |t| - t.string "first_name" - t.string "last_name" - t.integer "age" - t.boolean "active" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'users', force: true do |t| + t.string 'first_name' + t.string 'last_name' + t.integer 'age' + t.boolean 'active' + t.datetime 'created_at' + t.datetime 'updated_at' end - - create_table "untoucheds", :force => true do |t| - t.string "nothing" - t.timestamps - end + create_table 'untoucheds', force: true do |t| + t.string 'nothing' + t.timestamps + end end diff --git a/spec/active_record_dummy/script/rails b/spec/active_record_dummy/script/rails index f8da2cf..bd79dce 100755 --- a/spec/active_record_dummy/script/rails +++ b/spec/active_record_dummy/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/controllers/plain_objects_controller_spec.rb b/spec/controllers/plain_objects_controller_spec.rb index 75d6195..ba16a00 100644 --- a/spec/controllers/plain_objects_controller_spec.rb +++ b/spec/controllers/plain_objects_controller_spec.rb @@ -11,27 +11,26 @@ class SharedEngine::PlainObjectsController end describe 'get all users as a an array of plain objects, autodetecting the root node name' do - before(:each) do - get :index, :format => 'json', params: { :api_template => :name_only } + get :index, format: 'json', params: { api_template: :name_only } end - it "should have a root node named users" do - response_body_json.should have_key("plain_objects") + it 'should have a root node named users' do + response_body_json.should have_key('plain_objects') end - it "should contain all users" do - response_body_json["plain_objects"].should be_a(Array) + it 'should contain all users' do + response_body_json['plain_objects'].should be_a(Array) end - it "should contain the specified attributes" do - response_body_json["plain_objects"].first.should have_key("first_name") - response_body_json["plain_objects"].first.should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['plain_objects'].first.should have_key('first_name') + response_body_json['plain_objects'].first.should have_key('last_name') end - it "should contain the specified values" do - response_body_json["plain_objects"].first["first_name"].should eql("Han") - response_body_json["plain_objects"].first["last_name"].should eql("Solo") + it 'should contain the specified values' do + response_body_json['plain_objects'].first['first_name'].should eql('Han') + response_body_json['plain_objects'].first['last_name'].should eql('Solo') end end end diff --git a/spec/controllers/respond_with_users_controller_spec.rb b/spec/controllers/respond_with_users_controller_spec.rb index 8c4b9de..cbf2246 100644 --- a/spec/controllers/respond_with_users_controller_spec.rb +++ b/spec/controllers/respond_with_users_controller_spec.rb @@ -1,8 +1,4 @@ require 'spec_helper' -# -# RSpec.configure do |config| -# config.include SharedEngine::Engine.routes.url_helpers -# end describe SharedEngine::RespondWithUsersController, type: :controller do routes { SharedEngine::Engine.routes } @@ -12,131 +8,114 @@ end after(:each) do - clean_up_models + clean_up_models end # see spec/support/controller_examples.rb - it_behaves_like "a controller with ActsAsApi responses" - - describe "default ActionController::Responder behavior" do + it_behaves_like 'a controller with ActsAsApi responses' + describe 'default ActionController::Responder behavior' do context 'json responses' do - - context "creating valid models" do - + context 'creating valid models' do before(:each) do - post :create, format: 'json', params: { user: { first_name: "Luke", last_name: "Skywalker" }, api_template: :name_only } + post :create, format: 'json', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only } end - it "should return HTTP 201 status" do - response.code.should == "201" + it 'should return HTTP 201 status' do + response.code.should == '201' end - it "should contain the specified attributes" do - response_body_json["user"].should have_key("first_name") - response_body_json["user"].should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['user'].should have_key('first_name') + response_body_json['user'].should have_key('last_name') end - it "should contain the specified values" do - response_body_json["user"]["first_name"].should eql("Luke") - response_body_json["user"]["last_name"].should eql("Skywalker") + it 'should contain the specified values' do + response_body_json['user']['first_name'].should eql('Luke') + response_body_json['user']['last_name'].should eql('Skywalker') end end - context "creating invalid models" do - + context 'creating invalid models' do before(:each) do post :create, format: 'json', params: { user: { first_name: 'Luke' }, api_template: :name_only } end - it "should return HTTP 422 status" do - response.code.should == "422" + it 'should return HTTP 422 status' do + response.code.should == '422' end - it "should return errors as json" do - response_body_json['errors']['last_name'].should include("can't be blank") + it 'should return errors as json' do + response_body_json['errors']['last_name'].should include('can\'t be blank') end - end - context "returning all models without default root and no order" do - + context 'returning all models without default root and no order' do before(:each) do get :index_no_root_no_order, format: 'json', params: { api_template: :name_only } end - it "should return HTTP 200 status" do - response.code.should == "200" + it 'should return HTTP 200 status' do + response.code.should == '200' end - it "should contain the specified attributes" do - response_body_json["users"].each do |user| - user.should have_key( "first_name" ) - user.should have_key( "last_name" ) + it 'should contain the specified attributes' do + response_body_json['users'].each do |user| + user.should have_key('first_name') + user.should have_key('last_name') end end - end - end context 'xml responses' do - - context "creating valid models" do - + context 'creating valid models' do before(:each) do - post :create, format: 'xml', params: { user: { first_name: "Luke", last_name: "Skywalker" }, api_template: :name_only } + post :create, format: 'xml', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only } end - it "should return HTTP 201 status" do - response.code.should == "201" + it 'should return HTTP 201 status' do + response.code.should == '201' end - it "should include HTTP Location header" do - response.headers["Location"].should match "/shared/users/#{User.last.id}" + it 'should include HTTP Location header' do + response.headers['Location'].should match "/shared/users/#{User.last.id}" end - it "should contain the specified attributes" do - response_body.should have_selector("user > first-name") - response_body.should have_selector("user > last-name") + it 'should contain the specified attributes' do + response_body.should have_selector('user > first-name') + response_body.should have_selector('user > last-name') end - end - context "creating invalid models" do - + context 'creating invalid models' do before(:each) do - post :create, :format => 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only } + post :create, format: 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only } end - it "should return HTTP 422 status" do - response.code.should == "422" + it 'should return HTTP 422 status' do + response.code.should == '422' end - it "should return errors as xml" do - response_body.should have_selector("errors > error") + it 'should return errors as xml' do + response_body.should have_selector('errors > error') end - end - context "returning all models without default root and no order" do - + context 'returning all models without default root and no order' do before(:each) do get :index_no_root_no_order, format: 'xml', params: { api_template: :name_only } end - it "should return HTTP 200 status" do - response.code.should == "200" + it 'should return HTTP 200 status' do + response.code.should == '200' end - it "should contain the specified attributes" do - response_body.should have_selector( "users > user > first-name", :count => 3 ) - response_body.should have_selector( "users > user > last-name", :count => 3 ) + it 'should contain the specified attributes' do + response_body.should have_selector('users > user > first-name', count: 3) + response_body.should have_selector('users > user > last-name', count: 3) end - end end - end - end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index d85a1b2..de47b34 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,15 +1,14 @@ require 'spec_helper' describe SharedEngine::UsersController, type: :controller do - before(:each) do setup_models end after(:each) do - clean_up_models + clean_up_models end # see spec/support/controller_examples.rb - it_behaves_like "a controller with ActsAsApi responses" + it_behaves_like 'a controller with ActsAsApi responses' end diff --git a/spec/models/model_spec.rb b/spec/models/model_spec.rb index 58c636c..621d468 100644 --- a/spec/models/model_spec.rb +++ b/spec/models/model_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' -describe "Models" do - +describe 'Models' do before(:each) do setup_models end @@ -9,23 +8,22 @@ after(:each) do clean_up_models end - + describe :act_as_api do - it_supports "including an association in the api template" - it_supports "calling a closure in the api template" - it_supports "conditional if statements" - it_supports "conditional unless statements" - it_supports "acts_as_api is enabled" - it_supports "extending a given api template" - it_supports "calling a method in the api template" - it_supports "renaming" - it_supports "listing attributes in the api template" - it_supports "creating a sub hash in the api template" - it_supports "trying to render an api template that is not defined" + it_supports 'including an association in the api template' + it_supports 'calling a closure in the api template' + it_supports 'conditional if statements' + it_supports 'conditional unless statements' + it_supports 'acts_as_api is enabled' + it_supports 'extending a given api template' + it_supports 'calling a method in the api template' + it_supports 'renaming' + it_supports 'listing attributes in the api template' + it_supports 'creating a sub hash in the api template' + it_supports 'trying to render an api template that is not defined' # deactivated for vanilla ruby as acts_as_api won't get mixed into any class - it_supports "untouched models" - it_supports "defining a model callback" - it_supports "options" + it_supports 'untouched models' + it_supports 'defining a model callback' + it_supports 'options' end - -end \ No newline at end of file +end diff --git a/spec/mongoid_dummy/Gemfile b/spec/mongoid_dummy/Gemfile index 6b8a25a..444a621 100644 --- a/spec/mongoid_dummy/Gemfile +++ b/spec/mongoid_dummy/Gemfile @@ -5,12 +5,11 @@ gem 'rails', '5.0.0.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' - -gem "bson_ext" +gem 'bson_ext' gem 'mongoid', '>= 6.0.2' -gem 'shared_engine', :path => '../shared_engine' -gem 'acts_as_api', :path => '../../' +gem 'shared_engine', path: '../shared_engine' +gem 'acts_as_api', path: '../../' group :test do gem 'rspec-rails', '>= 2.5.0' diff --git a/spec/mongoid_dummy/app/models/.#profile.rb b/spec/mongoid_dummy/app/models/.#profile.rb new file mode 120000 index 0000000..2aae377 --- /dev/null +++ b/spec/mongoid_dummy/app/models/.#profile.rb @@ -0,0 +1 @@ +fabrik42@roflbot.local.65098 \ No newline at end of file diff --git a/spec/mongoid_dummy/app/models/profile.rb b/spec/mongoid_dummy/app/models/profile.rb index 497c0a7..4ec18f5 100644 --- a/spec/mongoid_dummy/app/models/profile.rb +++ b/spec/mongoid_dummy/app/models/profile.rb @@ -1,10 +1,10 @@ class Profile include Mongoid::Document - field :avatar, :type => String - field :homepage, :type => String - field :created_at, :type => DateTime - field :updated_at, :type => DateTime + field :avatar, type: String + field :homepage, type: String + field :created_at, type: DateTime + field :updated_at, type: DateTime - embedded_in :user, :class_name => "User", :inverse_of => :profile -end \ No newline at end of file + embedded_in :user, class_name: 'User', inverse_of: :profile +end diff --git a/spec/mongoid_dummy/app/models/task.rb b/spec/mongoid_dummy/app/models/task.rb index a0415c1..8c68612 100644 --- a/spec/mongoid_dummy/app/models/task.rb +++ b/spec/mongoid_dummy/app/models/task.rb @@ -1,12 +1,12 @@ class Task include Mongoid::Document - - field :heading, :type => String - field :description, :type => String - field :time_spent, :type => Integer - field :done, :type => Boolean - field :created_at, :type => DateTime - field :updated_at, :type => DateTime - - embedded_in :user, :class_name => "User", :inverse_of => :task -end \ No newline at end of file + + field :heading, type: String + field :description, type: String + field :time_spent, type: Integer + field :done, type: Boolean + field :created_at, type: DateTime + field :updated_at, type: DateTime + + embedded_in :user, class_name: 'User', inverse_of: :task +end diff --git a/spec/mongoid_dummy/app/models/untouched.rb b/spec/mongoid_dummy/app/models/untouched.rb index 1e5e044..ccb2846 100644 --- a/spec/mongoid_dummy/app/models/untouched.rb +++ b/spec/mongoid_dummy/app/models/untouched.rb @@ -1,7 +1,7 @@ class Untouched include Mongoid::Document - - field :nothing, :type => String - field :created_at, :type => DateTime - field :updated_at, :type => DateTime + + field :nothing, type: String + field :created_at, type: DateTime + field :updated_at, type: DateTime end diff --git a/spec/mongoid_dummy/app/models/user.rb b/spec/mongoid_dummy/app/models/user.rb index ccf80d7..cbc061c 100644 --- a/spec/mongoid_dummy/app/models/user.rb +++ b/spec/mongoid_dummy/app/models/user.rb @@ -1,18 +1,17 @@ class User - include Mongoid::Document - field :first_name, :type => String - field :last_name, :type => String - field :age, :type => Integer - field :active, :type => Boolean - field :created_at, :type => DateTime - field :updated_at, :type => DateTime + field :first_name, type: String + field :last_name, type: String + field :age, type: Integer + field :active, type: Boolean + field :created_at, type: DateTime + field :updated_at, type: DateTime - embeds_one :profile, :class_name => "Profile", :inverse_of => :user - embeds_many :tasks, :class_name => "Task", :inverse_of => :user + embeds_one :profile, class_name: 'Profile', inverse_of: :user + embeds_many :tasks, class_name: 'Task', inverse_of: :user - validates :first_name, :last_name, :presence => true + validates :first_name, :last_name, presence: true acts_as_api @@ -35,14 +34,13 @@ def full_name end def say_something - "something" + 'something' end def sub_hash { - :foo => "bar", - :hello => "world" + foo: 'bar', + hello: 'world' } end - end diff --git a/spec/mongoid_dummy/config.ru b/spec/mongoid_dummy/config.ru index ed5f1f4..bb9481c 100644 --- a/spec/mongoid_dummy/config.ru +++ b/spec/mongoid_dummy/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run MongoidDummy::Application diff --git a/spec/mongoid_dummy/config/application.rb b/spec/mongoid_dummy/config/application.rb index cf3d907..2c621ab 100644 --- a/spec/mongoid_dummy/config/application.rb +++ b/spec/mongoid_dummy/config/application.rb @@ -1,15 +1,15 @@ require File.expand_path('../boot', __FILE__) # Pick the frameworks you want: -# require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/railtie" -require "sprockets/railtie" -require "rails/test_unit/railtie" +# require 'active_record/railtie' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'sprockets/railtie' +require 'rails/test_unit/railtie' if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) + Bundler.require(*Rails.groups(assets: %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end @@ -39,7 +39,7 @@ class Application < Rails::Application # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" + config.encoding = 'utf-8' # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] diff --git a/spec/mongoid_dummy/config/boot.rb b/spec/mongoid_dummy/config/boot.rb index 4489e58..f2830ae 100644 --- a/spec/mongoid_dummy/config/boot.rb +++ b/spec/mongoid_dummy/config/boot.rb @@ -3,4 +3,4 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/spec/mongoid_dummy/config/environments/development.rb b/spec/mongoid_dummy/config/environments/development.rb index 677b38b..0fc7e9f 100644 --- a/spec/mongoid_dummy/config/environments/development.rb +++ b/spec/mongoid_dummy/config/environments/development.rb @@ -22,7 +22,6 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - # Do not compress assets config.assets.compress = false diff --git a/spec/mongoid_dummy/config/environments/production.rb b/spec/mongoid_dummy/config/environments/production.rb index 42f64e7..6ab0db8 100644 --- a/spec/mongoid_dummy/config/environments/production.rb +++ b/spec/mongoid_dummy/config/environments/production.rb @@ -60,5 +60,4 @@ # Send deprecation notices to registered listeners config.active_support.deprecation = :notify - end diff --git a/spec/mongoid_dummy/config/environments/test.rb b/spec/mongoid_dummy/config/environments/test.rb index 167a975..e707bee 100644 --- a/spec/mongoid_dummy/config/environments/test.rb +++ b/spec/mongoid_dummy/config/environments/test.rb @@ -14,14 +14,14 @@ config.whiny_nils = true # Show full error reports and disable caching - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb b/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb index 5852c8c..ca844af 100644 --- a/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +++ b/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb @@ -1,3 +1,3 @@ if defined?(Mongoid::Document) Mongoid::Document.send :include, ActsAsApi::Adapters::Mongoid -end \ No newline at end of file +end diff --git a/spec/mongoid_dummy/config/initializers/session_store.rb b/spec/mongoid_dummy/config/initializers/session_store.rb index 1665444..46c9725 100644 --- a/spec/mongoid_dummy/config/initializers/session_store.rb +++ b/spec/mongoid_dummy/config/initializers/session_store.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -MongoidDummy::Application.config.session_store :cookie_store, :key => '_mongoid_dummy_session' +MongoidDummy::Application.config.session_store :cookie_store, key: '_mongoid_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/spec/mongoid_dummy/config/initializers/wrap_parameters.rb b/spec/mongoid_dummy/config/initializers/wrap_parameters.rb index 5fe232e..c2f744d 100644 --- a/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +++ b/spec/mongoid_dummy/config/initializers/wrap_parameters.rb @@ -5,6 +5,5 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters :format => [:json] + wrap_parameters format: [:json] end - diff --git a/spec/mongoid_dummy/config/routes.rb b/spec/mongoid_dummy/config/routes.rb index 588629e..8fe9e6b 100644 --- a/spec/mongoid_dummy/config/routes.rb +++ b/spec/mongoid_dummy/config/routes.rb @@ -1,59 +1,3 @@ MongoidDummy::Application.routes.draw do - mount SharedEngine::Engine => "/shared", :as => "shared" - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id))(.:format)' + mount SharedEngine::Engine => '/shared', :as => 'shared' end diff --git a/spec/mongoid_dummy/script/rails b/spec/mongoid_dummy/script/rails index f8da2cf..bd79dce 100755 --- a/spec/mongoid_dummy/script/rails +++ b/spec/mongoid_dummy/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/shared_engine/Gemfile b/spec/shared_engine/Gemfile index 30b9549..c233d1a 100644 --- a/spec/shared_engine/Gemfile +++ b/spec/shared_engine/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source 'http://rubygems.org' # Declare your gem's dependencies in shared_engine.gemspec. # Bundler will treat runtime dependencies like base dependencies, and diff --git a/spec/shared_engine/Rakefile b/spec/shared_engine/Rakefile index 8302331..237d19b 100644 --- a/spec/shared_engine/Rakefile +++ b/spec/shared_engine/Rakefile @@ -20,10 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path("../active_record_dummy/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path('../active_record_dummy/Rakefile', __FILE__) load 'rails/tasks/engine.rake' - - Bundler::GemHelper.install_tasks - diff --git a/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb b/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb index b3f46f9..4f7685d 100644 --- a/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +++ b/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb @@ -6,8 +6,8 @@ def index @users = [@han, @luke, @leia] respond_to do |format| - format.xml { render_for_api params[:api_template].to_sym, :xml => @users } - format.json { render_for_api params[:api_template].to_sym, :json => @users } + format.xml { render_for_api params[:api_template].to_sym, xml: @users } + format.json { render_for_api params[:api_template].to_sym, json: @users } end end end diff --git a/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb b/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb index 10a9d16..5965d2d 100644 --- a/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +++ b/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb @@ -1,42 +1,41 @@ module SharedEngine class RespondWithUsersController < SharedEngine::ApplicationController - respond_to :json, :xml self.responder = ActsAsApi::Responder def index @users = User.all.sort_by(&:first_name) - respond_with @users, :api_template => params[:api_template].to_sym, :root => :users + respond_with @users, api_template: params[:api_template].to_sym, root: :users end def index_no_root_no_order @users = User.all.to_a - respond_with @users, :api_template => params[:api_template].to_sym + respond_with @users, api_template: params[:api_template].to_sym end def index_meta @users = User.all.to_a - meta_hash = { :page => 1, :total => 999 } - respond_with @users, :api_template => params[:api_template].to_sym, :root => :users, :meta => meta_hash + meta_hash = { page: 1, total: 999 } + respond_with @users, api_template: params[:api_template].to_sym, root: :users, meta: meta_hash end def index_relation @users = User.limit(100).sort_by(&:first_name) - respond_with @users, :api_template => params[:api_template].to_sym + respond_with @users, api_template: params[:api_template].to_sym end def show @user = User.find(params[:id]) - # :root => :user is only used here because we need it for the node name of the MongoUser model - respond_with @user, :api_template => params[:api_template].to_sym, :root => :user + # root: :user is only used here because we need it for the node name of the MongoUser model + respond_with @user, api_template: params[:api_template].to_sym, root: :user end def show_meta @user = User.find(params[:id]) - meta_hash = { :page => 1, :total => 999 } - # :root => :user is only used here because we need it for the node name of the MongoUser model - respond_with @user, :api_template => params[:api_template].to_sym, :root => :user, :meta => meta_hash + meta_hash = { page: 1, total: 999 } + # root: :user is only used here because we need it for the node name of the MongoUser model + respond_with @user, api_template: params[:api_template].to_sym, root: :user, meta: meta_hash end def show_default @@ -46,19 +45,18 @@ def show_default def show_prefix_postfix @user = User.find(params[:id]) - # :root => :user is only used here because we need it for the node name of the MongoUser model - respond_with @user, :api_template => {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]}, :root => :user + # root: :user is only used here because we need it for the node name of the MongoUser model + respond_with @user, api_template: { template: params[:api_template], prefix: params[:api_prefix], postfix: params[:api_postfix] }, root: :user end def create @user = User.new(params[:user].permit!) if @user.save - respond_with @user, :api_template => params[:api_template] + respond_with @user, api_template: params[:api_template] else respond_with @user end end - end end diff --git a/spec/shared_engine/app/controllers/shared_engine/users_controller.rb b/spec/shared_engine/app/controllers/shared_engine/users_controller.rb index 7ba7a1d..5d9d584 100644 --- a/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +++ b/spec/shared_engine/app/controllers/shared_engine/users_controller.rb @@ -1,22 +1,21 @@ module SharedEngine class UsersController < SharedEngine::ApplicationController - def index @users = User.all.sort_by(&:first_name) respond_to do |format| - format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users } - format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users } + format.xml { render_for_api params[:api_template].to_sym, xml: @users, root: :users } + format.json { render_for_api params[:api_template].to_sym, json: @users, root: :users } end end def index_meta @users = User.all.to_a - meta_hash = { :page => 1, :total => 999 } + meta_hash = { page: 1, total: 999 } respond_to do |format| - format.xml { render_for_api params[:api_template].to_sym, :xml => @users, :root => :users, :meta => meta_hash } - format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash } + format.xml { render_for_api params[:api_template].to_sym, xml: @users, root: :users, meta: meta_hash } + format.json { render_for_api params[:api_template].to_sym, json: @users, root: :users, meta: meta_hash } end end @@ -28,8 +27,8 @@ def index_relation end respond_to do |format| - format.xml { render_for_api params[:api_template].to_sym, :xml => @users } - format.json { render_for_api params[:api_template].to_sym, :json => @users } + format.xml { render_for_api params[:api_template].to_sym, xml: @users } + format.json { render_for_api params[:api_template].to_sym, json: @users } end end @@ -38,38 +37,37 @@ def show respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model - format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user } - format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user } + format.xml { render_for_api params[:api_template].to_sym, xml: @user, root: :user } + format.json { render_for_api params[:api_template].to_sym, json: @user, root: :user } end end def show_meta @user = User.find(params[:id]) - meta_hash = { :page => 1, :total => 999 } + meta_hash = { page: 1, total: 999 } respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model - format.xml { render_for_api params[:api_template].to_sym, :xml => @user, :root => :user } - format.json { render_for_api params[:api_template].to_sym, :json => @user, :root => :user, :meta => meta_hash } + format.xml { render_for_api params[:api_template].to_sym, xml: @user, root: :user } + format.json { render_for_api params[:api_template].to_sym, json: @user, root: :user, meta: meta_hash } end end def show_default @user = User.find(params[:id]) respond_to do |format| - format.xml { render :xml => @user } - format.json { render :json => @user } + format.xml { render xml: @user } + format.json { render json: @user } end end def show_prefix_postfix @user = User.find(params[:id]) - template = {:template => params[:api_template], :prefix => params[:api_prefix], :postfix => params[:api_postfix]} + template = { template: params[:api_template], prefix: params[:api_prefix], postfix: params[:api_postfix] } respond_to do |format| # :root => :user is only used here because we need it for the node name of the MongoUser model - format.xml { render_for_api template, :xml => @user, :root => :user } - format.json { render_for_api template, :json => @user, :root => :user } + format.xml { render_for_api template, xml: @user, root: :user } + format.json { render_for_api template, json: @user, root: :user } end end - end end diff --git a/spec/shared_engine/app/models/plain_object.rb b/spec/shared_engine/app/models/plain_object.rb index 7aac2a8..4df1c99 100644 --- a/spec/shared_engine/app/models/plain_object.rb +++ b/spec/shared_engine/app/models/plain_object.rb @@ -1,6 +1,8 @@ -class PlainObject < Struct.new(:first_name, :last_name, :age, :active) +class PlainObject extend ActsAsApi::Base + attr_accessor :first_name, :last_name, :age, :active + def initialize(opts) opts.each do |k, v| send("#{k}=", v) diff --git a/spec/shared_engine/app/models/user_template.rb b/spec/shared_engine/app/models/user_template.rb index f6e812e..c838172 100644 --- a/spec/shared_engine/app/models/user_template.rb +++ b/spec/shared_engine/app/models/user_template.rb @@ -12,11 +12,11 @@ module UserTemplate end api_accessible :rename_last_name do |t| - t.add :last_name, :as => :family_name + t.add :last_name, as: :family_name end api_accessible :rename_full_name do |t| - t.add :full_name, :as => :other_full_name + t.add :full_name, as: :other_full_name end api_accessible :with_former_value do |t| @@ -24,19 +24,19 @@ module UserTemplate t.add :last_name end - api_accessible :age_and_first_name, :extend => :with_former_value do |t| + api_accessible :age_and_first_name, extend: :with_former_value do |t| t.add :age t.remove :last_name end api_accessible :calling_a_proc do |t| - t.add Proc.new{|model| model.full_name.upcase }, :as => :all_caps_name - t.add Proc.new{|model| Time.now.class.to_s }, :as => :without_param + t.add proc { |model| model.full_name.upcase }, as: :all_caps_name + t.add proc { |_| Time.now.class.to_s }, as: :without_param end api_accessible :calling_a_lambda do |t| - t.add lambda{|model| model.full_name.upcase }, :as => :all_caps_name - t.add lambda{|model| Time.now.class.to_s }, :as => :without_param + t.add ->(model) { model.full_name.upcase }, as: :all_caps_name + t.add ->(_) { Time.now.class.to_s }, as: :without_param end api_accessible :include_tasks do |t| t.add :tasks @@ -48,19 +48,19 @@ module UserTemplate api_accessible :other_sub_template do |t| t.add :first_name - t.add :tasks, :template => :other_template + t.add :tasks, template: :other_template end api_accessible :include_completed_tasks do |t| - t.add "tasks.completed.all", :as => :completed_tasks + t.add 'tasks.completed.all', as: :completed_tasks end api_accessible :sub_node do |t| - t.add Hash[:foo => :say_something], :as => :sub_nodes + t.add Hash[foo: :say_something], as: :sub_nodes end api_accessible :nested_sub_node do |t| - t.add Hash[:foo, Hash[:bar, :last_name]], :as => :sub_nodes + t.add Hash[:foo, Hash[:bar, :last_name]], as: :sub_nodes end api_accessible :nested_sub_hash do |t| @@ -69,46 +69,46 @@ module UserTemplate api_accessible :if_over_thirty do |t| t.add :first_name - t.add :last_name, :if => :over_thirty? + t.add :last_name, if: :over_thirty? end api_accessible :if_returns_nil do |t| t.add :first_name - t.add :last_name, :if => :return_nil + t.add :last_name, if: :return_nil end api_accessible :if_over_thirty_proc do |t| t.add :first_name - t.add :last_name, :if => lambda{|u| u.over_thirty? } + t.add :last_name, if: ->(model) { model.over_thirty? } end api_accessible :if_returns_nil_proc do |t| t.add :first_name - t.add :last_name, :if => lambda{|u| nil } + t.add :last_name, if: ->(_) { nil } end api_accessible :unless_under_thirty do |t| t.add :first_name - t.add :last_name, :unless => :under_thirty? + t.add :last_name, unless: :under_thirty? end api_accessible :unless_returns_nil do |t| t.add :first_name - t.add :last_name, :unless => :return_nil + t.add :last_name, unless: :return_nil end api_accessible :unless_under_thirty_proc do |t| t.add :first_name - t.add :last_name, :unless => lambda{|u| u.under_thirty? } + t.add :last_name, unless: ->(model) { model.under_thirty? } end api_accessible :unless_returns_nil_proc do |t| t.add :first_name - t.add :last_name, :unless => lambda{|u| nil } + t.add :last_name, unless: ->(_) { nil } end api_accessible :with_prefix_name_only do |t| - t.add lambda{|model| 'true' }, :as => :prefix + t.add ->(_) { 'true' }, as: :prefix t.add :first_name t.add :last_name end @@ -116,17 +116,17 @@ module UserTemplate api_accessible :name_only_with_postfix do |t| t.add :first_name t.add :last_name - t.add lambda{|model| 'true' }, :as => :postfix + t.add ->(_) { 'true' }, as: :postfix end api_accessible :with_prefix_name_only_with_postfix do |t| - t.add lambda{|model| 'true' }, :as => :prefix + t.add ->(_) { 'true' }, as: :prefix t.add :first_name t.add :last_name - t.add lambda{|model| 'true' }, :as => :postfix + t.add ->(_) { 'true' }, as: :postfix end - def before_api_response(api_response) + def before_api_response(_api_response) @before_api_response_called = true end @@ -134,7 +134,7 @@ def before_api_response_called? !!@before_api_response_called end - def after_api_response(api_response) + def after_api_response(_api_response) @after_api_response_called = true end @@ -146,9 +146,8 @@ def skip_api_response=(should_skip) @skip_api_response = should_skip end - def around_api_response(api_response) - @skip_api_response ? { :skipped => true } : yield + def around_api_response(_api_response) + @skip_api_response ? { skipped: true } : yield end - end -end \ No newline at end of file +end diff --git a/spec/shared_engine/dummy/config.ru b/spec/shared_engine/dummy/config.ru index 1989ed8..cbd7415 100644 --- a/spec/shared_engine/dummy/config.ru +++ b/spec/shared_engine/dummy/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run Dummy::Application diff --git a/spec/shared_engine/dummy/config/application.rb b/spec/shared_engine/dummy/config/application.rb index eb7f553..f6ff3a4 100644 --- a/spec/shared_engine/dummy/config/application.rb +++ b/spec/shared_engine/dummy/config/application.rb @@ -1,15 +1,15 @@ require File.expand_path('../boot', __FILE__) # Pick the frameworks you want: -require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/railtie" -require "active_resource/railtie" -require "sprockets/railtie" +require 'active_record/railtie' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'active_resource/railtie' +require 'sprockets/railtie' # require "rails/test_unit/railtie" Bundler.require -require "shared_engine" +require 'shared_engine' module Dummy class Application < Rails::Application @@ -36,7 +36,7 @@ class Application < Rails::Application # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" + config.encoding = 'utf-8' # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] @@ -53,4 +53,3 @@ class Application < Rails::Application config.assets.version = '1.0' end end - diff --git a/spec/shared_engine/dummy/config/boot.rb b/spec/shared_engine/dummy/config/boot.rb index eba0681..f8f29cd 100644 --- a/spec/shared_engine/dummy/config/boot.rb +++ b/spec/shared_engine/dummy/config/boot.rb @@ -7,4 +7,4 @@ Bundler.setup end -$:.unshift File.expand_path('../../../../lib', __FILE__) \ No newline at end of file +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/shared_engine/dummy/config/environments/test.rb b/spec/shared_engine/dummy/config/environments/test.rb index 5abc006..9d728b5 100644 --- a/spec/shared_engine/dummy/config/environments/test.rb +++ b/spec/shared_engine/dummy/config/environments/test.rb @@ -14,14 +14,14 @@ config.whiny_nils = true # Show full error reports and disable caching - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/spec/shared_engine/dummy/config/initializers/session_store.rb b/spec/shared_engine/dummy/config/initializers/session_store.rb index aa2f512..952473f 100644 --- a/spec/shared_engine/dummy/config/initializers/session_store.rb +++ b/spec/shared_engine/dummy/config/initializers/session_store.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session' +Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb b/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb index da4fb07..999df20 100644 --- a/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +++ b/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb @@ -5,7 +5,7 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters :format => [:json] + wrap_parameters format: [:json] end # Disable root element in JSON by default. diff --git a/spec/shared_engine/dummy/config/routes.rb b/spec/shared_engine/dummy/config/routes.rb index 0c4e8e4..0985649 100644 --- a/spec/shared_engine/dummy/config/routes.rb +++ b/spec/shared_engine/dummy/config/routes.rb @@ -1,4 +1,3 @@ Rails.application.routes.draw do - - mount SharedEngine::Engine => "/shared_engine" + mount SharedEngine::Engine => '/shared_engine' end diff --git a/spec/shared_engine/dummy/script/rails b/spec/shared_engine/dummy/script/rails index f8da2cf..bd79dce 100755 --- a/spec/shared_engine/dummy/script/rails +++ b/spec/shared_engine/dummy/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/shared_engine/lib/shared_engine.rb b/spec/shared_engine/lib/shared_engine.rb index 17f4417..04b1d72 100644 --- a/spec/shared_engine/lib/shared_engine.rb +++ b/spec/shared_engine/lib/shared_engine.rb @@ -1,4 +1,4 @@ -require "shared_engine/engine" +require 'shared_engine/engine' module SharedEngine end diff --git a/spec/shared_engine/lib/shared_engine/version.rb b/spec/shared_engine/lib/shared_engine/version.rb index bad538f..fd86518 100644 --- a/spec/shared_engine/lib/shared_engine/version.rb +++ b/spec/shared_engine/lib/shared_engine/version.rb @@ -1,3 +1,3 @@ module SharedEngine - VERSION = "0.0.1" + VERSION = '0.0.1'.freeze end diff --git a/spec/shared_engine/shared_engine.gemspec b/spec/shared_engine/shared_engine.gemspec index b42e63a..006a17f 100644 --- a/spec/shared_engine/shared_engine.gemspec +++ b/spec/shared_engine/shared_engine.gemspec @@ -1,21 +1,19 @@ -$:.push File.expand_path("../lib", __FILE__) +$LOAD_PATH.push File.expand_path('../lib', __FILE__) # Maintain your gem's version: -require "shared_engine/version" +require 'shared_engine/version' # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "shared_engine" + s.name = 'shared_engine' s.version = SharedEngine::VERSION - s.authors = ["Your name"] - s.email = ["Your email"] - s.summary = "Summary of SharedEngine." - s.description = "Description of SharedEngine." + s.authors = ['Your name'] + s.email = ['Your email'] + s.summary = 'Summary of SharedEngine.' + s.description = 'Description of SharedEngine.' - s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] + s.files = Dir['{app,config,db,lib}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.rdoc'] - s.add_dependency "rails", "~> 5.0.0.1" - # s.add_dependency "jquery-rails" - - s.add_development_dependency "sqlite3" + s.add_dependency 'rails', '~> 5.0.0.1' + s.add_development_dependency 'sqlite3' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 77d3353..62edaa7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,23 +1,19 @@ -ENV["RAILS_ENV"] = "test" +ENV['RAILS_ENV'] = 'test' if ENV['ACTS_AS_API_ORM'] == 'active_record' - require "active_record_dummy/config/environment" + require 'active_record_dummy/config/environment' - load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default + load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default # ActiveRecord::Migrator.up('db/migrate') # use migrations - - elsif ENV['ACTS_AS_API_ORM'] == 'mongoid' - - require "mongoid_dummy/config/environment" - + require 'mongoid_dummy/config/environment' end require 'rspec/rails' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file } +Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |file| require file } RSpec.configure do |config| config.expect_with(:rspec) { |c| c.syntax = :should } diff --git a/spec/support/api_test_helpers.rb b/spec/support/api_test_helpers.rb index b4004a1..72b6a33 100644 --- a/spec/support/api_test_helpers.rb +++ b/spec/support/api_test_helpers.rb @@ -1,5 +1,4 @@ module ApiTestHelpers - def response_body response.body.strip end @@ -15,7 +14,6 @@ def response_body_jsonp(callback) def jsonp_callback(callback) /\A#{callback}\((.*),\s+\d{3}\)\z/ end - end RSpec.configure do |c| diff --git a/spec/support/controller_examples.rb b/spec/support/controller_examples.rb index 51021ae..5747014 100644 --- a/spec/support/controller_examples.rb +++ b/spec/support/controller_examples.rb @@ -1,128 +1,115 @@ -shared_examples_for "a controller with ActsAsApi responses" do +shared_examples_for 'a controller with ActsAsApi responses' do include ApiTestHelpers routes { SharedEngine::Engine.routes } describe 'xml responses' do - describe 'get all users' do - before(:each) do get :index, format: 'xml', params: { api_template: :name_only } end - it "should have a root node named users" do - response_body.should have_selector("users") + it 'should have a root node named users' do + response_body.should have_selector('users') end - it "should contain all users" do - response_body.should have_selector("users > user") do |users| + it 'should contain all users' do + response_body.should have_selector('users > user') do |users| users.size.should eql(3) end end - it "should contain the specified attributes" do - response_body.should have_selector("users > user > first-name") - response_body.should have_selector("users > user > last-name") + it 'should contain the specified attributes' do + response_body.should have_selector('users > user > first-name') + response_body.should have_selector('users > user > last-name') end - end describe 'get a single user' do - before(:each) do get :show, format: 'xml', params: { api_template: :name_only, id: @luke.id } end - it "should have a root node named user" do - response_body.should have_selector("user") + it 'should have a root node named user' do + response_body.should have_selector('user') end - it "should contain the specified attributes" do - response_body.should have_selector("user > first-name") - response_body.should have_selector("user > last-name") + it 'should contain the specified attributes' do + response_body.should have_selector('user > first-name') + response_body.should have_selector('user > last-name') end - end end describe 'json responses' do - describe 'get all users' do - before(:each) do get :index, format: 'json', params: { api_template: :name_only } end - it "should have a root node named users" do - response_body_json.should have_key("users") + it 'should have a root node named users' do + response_body_json.should have_key('users') end - it "should contain all users" do - response_body_json["users"].should be_a(Array) + it 'should contain all users' do + response_body_json['users'].should be_a(Array) end - it "should contain the specified attributes" do - response_body_json["users"].first.should have_key("first_name") - response_body_json["users"].first.should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['users'].first.should have_key('first_name') + response_body_json['users'].first.should have_key('last_name') end - it "should contain the specified values" do - response_body_json["users"].first["first_name"].should eql("Han") - response_body_json["users"].first["last_name"].should eql("Solo") + it 'should contain the specified values' do + response_body_json['users'].first['first_name'].should eql('Han') + response_body_json['users'].first['last_name'].should eql('Solo') end - end describe 'get all users as a ActiveRecord::Relation (or similar chained) object, autodetecting the root node name' do - before(:each) do get :index_relation, format: 'json', params: { api_template: :name_only } end - it "should have a root node named users" do - response_body_json.should have_key("users") + it 'should have a root node named users' do + response_body_json.should have_key('users') end - it "should contain all users" do - response_body_json["users"].should be_a(Array) + it 'should contain all users' do + response_body_json['users'].should be_a(Array) end - it "should contain the specified attributes" do - response_body_json["users"].first.should have_key("first_name") - response_body_json["users"].first.should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['users'].first.should have_key('first_name') + response_body_json['users'].first.should have_key('last_name') end - it "should contain the specified values" do - response_body_json["users"].first["first_name"].should eql("Han") - response_body_json["users"].first["last_name"].should eql("Solo") + it 'should contain the specified values' do + response_body_json['users'].first['first_name'].should eql('Han') + response_body_json['users'].first['last_name'].should eql('Solo') end - end describe 'get a single user' do - before(:each) do get :show, format: 'json', params: { api_template: :name_only, id: @luke.id } end - it "should have a root node named user" do - response_body_json.should have_key("user") + it 'should have a root node named user' do + response_body_json.should have_key('user') end - it "should contain the specified attributes" do - response_body_json["user"].should have_key("first_name") - response_body_json["user"].should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['user'].should have_key('first_name') + response_body_json['user'].should have_key('last_name') end - it "should contain the specified values" do - response_body_json["user"]["first_name"].should eql("Luke") - response_body_json["user"]["last_name"].should eql("Skywalker") + it 'should contain the specified values' do + response_body_json['user']['first_name'].should eql('Luke') + response_body_json['user']['last_name'].should eql('Skywalker') end - end describe 'get a single user with a nil profile' do - before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| @@ -133,41 +120,36 @@ get :show, format: 'json', params: { api_template: :include_profile, id: @han.id } end - it "should have a root node named user" do - response_body_json.should have_key("user") + it 'should have a root node named user' do + response_body_json.should have_key('user') end - it "should contain the specified attributes" do - response_body_json["user"].should have(1).keys - response_body_json["user"].should have_key("profile") + it 'should contain the specified attributes' do + response_body_json['user'].should have(1).keys + response_body_json['user'].should have_key('profile') end - it "should contain the specified values" do - response_body_json["user"]["profile"].should be_nil + it 'should contain the specified values' do + response_body_json['user']['profile'].should be_nil end - end describe 'get a user without specifying an api template' do - before(:each) do get :show_default, format: 'json', params: { id: @luke.id } end - it "should respond with HTTP 200" do - response.code.should == "200" + it 'should respond with HTTP 200' do + response.code.should == '200' end - it "should render the model with to_json" do + it 'should render the model with to_json' do response.body.should == @luke.to_json end - end - end describe 'Rails 3 default style json responses' do - before(:each) do @org_include_root_in_json_collections = ActsAsApi::Config.include_root_in_json_collections ActsAsApi::Config.include_root_in_json_collections = true @@ -178,70 +160,64 @@ end describe 'get all users' do - before(:each) do get :index, format: 'json', params: { api_template: :name_only } end - it "should have a root node named users" do - response_body_json.should have_key("users") + it 'should have a root node named users' do + response_body_json.should have_key('users') end - it "should contain all users" do - response_body_json["users"].should be_a(Array) + it 'should contain all users' do + response_body_json['users'].should be_a(Array) end - it "should contain the specified attributes" do - response_body_json["users"].first["user"].should have_key("first_name") - response_body_json["users"].first["user"].should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['users'].first['user'].should have_key('first_name') + response_body_json['users'].first['user'].should have_key('last_name') end - it "contains the user root nodes" do - response_body_json["users"].collect(&:keys).flatten.uniq.should eql(["user"]) + it 'contains the user root nodes' do + response_body_json['users'].collect(&:keys).flatten.uniq.should eql(['user']) end - it "should contain the specified values" do - response_body_json["users"].first["user"]["first_name"].should eql("Han") - response_body_json["users"].first["user"]["last_name"].should eql("Solo") + it 'should contain the specified values' do + response_body_json['users'].first['user']['first_name'].should eql('Han') + response_body_json['users'].first['user']['last_name'].should eql('Solo') end - end describe 'get a single user' do - before(:each) do get :show, format: 'json', params: { api_template: :name_only, id: @luke.id } end - it "should have a root node named user" do - response_body_json.should have_key("user") + it 'should have a root node named user' do + response_body_json.should have_key('user') end - it "should contain the specified attributes" do - response_body_json["user"].should have_key("first_name") - response_body_json["user"].should have_key("last_name") + it 'should contain the specified attributes' do + response_body_json['user'].should have_key('first_name') + response_body_json['user'].should have_key('last_name') end - it "should contain the specified values" do - response_body_json["user"]["first_name"].should eql("Luke") - response_body_json["user"]["last_name"].should eql("Skywalker") + it 'should contain the specified values' do + response_body_json['user']['first_name'].should eql('Luke') + response_body_json['user']['last_name'].should eql('Skywalker') end end - end describe 'jsonp responses with callback' do - - it "should be disabled by default" do - @callback = "mycallback" + it 'should be disabled by default' do + @callback = 'mycallback' get :index, format: 'json', params: { api_template: :name_only, callback: @callback } response_body_jsonp(@callback).should be_nil end - describe "enabled jsonp callbacks" do - + describe 'enabled jsonp callbacks' do before(:each) do - @callback = "mycallback" + @callback = 'mycallback' User.acts_as_api do |config| config.allow_jsonp_callback = true @@ -256,27 +232,23 @@ end describe 'get all users' do - before(:each) do get :index, format: 'json', params: { api_template: :name_only, callback: @callback } end - it "should wrap the response in the callback" do + it 'should wrap the response in the callback' do response_body_jsonp(@callback).should_not be_nil end - end describe 'get a single user' do - before(:each) do get :show, format: 'json', params: { api_template: :name_only, id: @luke.id, callback: @callback } end - it "should wrap the response in the callback" do + it 'should wrap the response in the callback' do response_body_jsonp(@callback).should_not be_nil end - end describe 'Requesting the JSONP content as JavaScript' do @@ -284,7 +256,7 @@ get :index, format: :json, params: { api_template: :name_only, callback: @callback } end - it "should set the content type to JavaScript" do + it 'should set the content type to JavaScript' do response.content_type.should == Mime[:js] end end @@ -306,7 +278,7 @@ get :index, format: 'json', params: { api_template: :name_only, callback: @callback } end - its "response has no named root node" do + its 'response has no named root node' do response_body_json.should be_an(Array) end end @@ -316,32 +288,31 @@ get :show, format: 'json', params: { api_template: :name_only, id: @luke.id } end - its "response has no named root node" do + its 'response has no named root node' do response_body_json.should be_a(Hash) - response_body_json.should have_key("first_name") + response_body_json.should have_key('first_name') end end end describe 'pass meta information on rendering' do - describe 'get all users' do before(:each) do get :index_meta, format: 'json', params: { api_template: :name_only } end - it "shows model response fields" do + it 'shows model response fields' do response_body_json.should be_a(Hash) - response_body_json.should have_key("users") - response_body_json["users"].should be_an(Array) + response_body_json.should have_key('users') + response_body_json['users'].should be_an(Array) end - it "shows page field" do - response_body_json.should have_key("page") + it 'shows page field' do + response_body_json.should have_key('page') end - it "shows total field" do - response_body_json.should have_key("total") + it 'shows total field' do + response_body_json.should have_key('total') end end @@ -350,97 +321,81 @@ get :show_meta, format: 'json', params: { api_template: :name_only, id: @luke.id } end - it "shows model response fields" do + it 'shows model response fields' do response_body_json.should be_a(Hash) - response_body_json.should have_key("user") + response_body_json.should have_key('user') end - it "shows page field" do - response_body_json.should have_key("page") + it 'shows page field' do + response_body_json.should have_key('page') end - it "shows total field" do - response_body_json.should have_key("total") + it 'shows total field' do + response_body_json.should have_key('total') end - end end - describe 'api prefix' do - describe 'get single user' do - before(:each) do get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, id: @luke.id } - end - it "should have a root node named user" do - response_body.should have_selector("user") + it 'should have a root node named user' do + response_body.should have_selector('user') end - it "should contain the specified attributes" do - response_body.should have_selector("user > prefix") - response_body.should have_selector("user > first-name") - response_body.should have_selector("user > last-name") + it 'should contain the specified attributes' do + response_body.should have_selector('user > prefix') + response_body.should have_selector('user > first-name') + response_body.should have_selector('user > last-name') end - it "should not contain the specified attributes" do - response_body.should_not have_selector("user > postfix") + it 'should not contain the specified attributes' do + response_body.should_not have_selector('user > postfix') end - end - end describe 'api postfix' do - describe 'get single user' do - before(:each) do get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_postfix: :with_postfix, id: @luke.id } end - it "should have a root node named user" do - response_body.should have_selector("user") + it 'should have a root node named user' do + response_body.should have_selector('user') end - it "should contain the specified attributes" do - response_body.should have_selector("user > first-name") - response_body.should have_selector("user > last-name") - response_body.should have_selector("user > postfix") + it 'should contain the specified attributes' do + response_body.should have_selector('user > first-name') + response_body.should have_selector('user > last-name') + response_body.should have_selector('user > postfix') end - it "should not contain the specified attributes" do - response_body.should_not have_selector("user > prefix") + it 'should not contain the specified attributes' do + response_body.should_not have_selector('user > prefix') end - end - end describe 'api prefix and api postfix' do - describe 'get single user' do - before(:each) do - get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, api_postfix: :with_postfix, :id => @luke.id } + get :show_prefix_postfix, format: 'xml', params: { api_template: :name_only, api_prefix: :with_prefix, api_postfix: :with_postfix, id: @luke.id } end - it "should have a root node named user" do - response_body.should have_selector("user") + it 'should have a root node named user' do + response_body.should have_selector('user') end - it "should contain the specified attributes" do - response_body.should have_selector("user > prefix") - response_body.should have_selector("user > first-name") - response_body.should have_selector("user > last-name") - response_body.should have_selector("user > postfix") + it 'should contain the specified attributes' do + response_body.should have_selector('user > prefix') + response_body.should have_selector('user > first-name') + response_body.should have_selector('user > last-name') + response_body.should have_selector('user > postfix') end - end - end - end diff --git a/spec/support/it_supports.rb b/spec/support/it_supports.rb index d3d8918..12074b5 100644 --- a/spec/support/it_supports.rb +++ b/spec/support/it_supports.rb @@ -1,3 +1,3 @@ RSpec.configure do |c| c.alias_it_should_behave_like_to :it_supports, 'supports:' -end \ No newline at end of file +end diff --git a/spec/support/model_examples/associations.rb b/spec/support/model_examples/associations.rb index 8ea1c2c..423064b 100644 --- a/spec/support/model_examples/associations.rb +++ b/spec/support/model_examples/associations.rb @@ -1,37 +1,33 @@ -shared_examples_for "including an association in the api template" do - - describe "which doesn't acts_as_api" do - +shared_examples_for 'including an association in the api template' do + describe 'which does not acts_as_api' do before(:each) do @response = @luke.as_api_response(:include_tasks) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end - it "should contain the associated sub models" do + it 'should contain the associated sub models' do @response[:tasks].should include(@destroy_deathstar, @study_with_yoda, @win_rebellion) end end - describe "which does acts_as_api" do - - context "has_many" do - + describe 'which does acts_as_api' do + context 'has_many' do before(:each) do Task.acts_as_api Task.api_accessible :include_tasks do |t| @@ -41,38 +37,37 @@ @response = @luke.as_api_response(:include_tasks) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end - it "contains the associated child models with the determined api template" do + it 'contains the associated child models with the determined api template' do @response[:tasks].each do |task| task.keys.should include(:heading, :done) task.keys.should have(2).attributes end end - it "contains the correct data of the child models" do - task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :done => t.done, :heading => t.heading } } + it 'contains the correct data of the child models' do + task_hash = [@destroy_deathstar, @study_with_yoda, @win_rebellion].collect { |t| { done: t.done, heading: t.heading } } @response[:tasks].should eql task_hash end end - context "has_one" do - + context 'has_one' do before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| @@ -82,37 +77,35 @@ @response = @luke.as_api_response(:include_profile) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:profile) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:profile].should be_a Hash @response[:profile].should have(2).attributes end - it "contains the associated child models with the determined api template" do + it 'contains the associated child models with the determined api template' do @response[:profile].keys.should include(:avatar, :homepage) end - it "contains the correct data of the child models" do - profile_hash = { :avatar => @luke.profile.avatar, :homepage => @luke.profile.homepage } + it 'contains the correct data of the child models' do + profile_hash = { avatar: @luke.profile.avatar, homepage: @luke.profile.homepage } @response[:profile].should eql profile_hash end - end end - describe "which does acts_as_api, but with using another template name" do - + describe 'which does acts_as_api, but with using another template name' do before(:each) do Task.acts_as_api Task.api_accessible :other_template do |t| @@ -122,51 +115,49 @@ @response = @luke.as_api_response(:other_sub_template) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:first_name) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.should include(@luke.first_name) end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end - it "contains the associated child models with the determined api template" do + it 'contains the associated child models with the determined api template' do @response[:tasks].each do |task| task.keys.should include(:description, :time_spent) task.keys.should have(2).attributes end end - it "contains the correct data of the child models" do - task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } } + it 'contains the correct data of the child models' do + task_hash = [@destroy_deathstar, @study_with_yoda, @win_rebellion].collect { |t| { description: t.description, time_spent: t.time_spent } } @response[:tasks].should eql task_hash end end - describe "that is scoped" do - + describe 'that is scoped' do before(:each) do # extend task model with scope - #class Task < ActiveRecord::Base Task.class_eval do - scope :completed, -> { where(:done => true) } + scope :completed, -> { where(done: true) } end Task.acts_as_api Task.api_accessible :include_completed_tasks do |t| @@ -177,40 +168,38 @@ @response = @luke.as_api_response(:include_completed_tasks) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:completed_tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:completed_tasks].should be_an Array @response[:completed_tasks].should have(2).tasks end - it "contains the associated child models with the determined api template" do + it 'contains the associated child models with the determined api template' do @response[:completed_tasks].each do |task| task.keys.should include(:heading, :done) task.keys.should have(2).attributes end end - it "contains the correct data of the child models" do - task_hash = [ @destroy_deathstar, @study_with_yoda ].collect{|t| { :done => t.done, :heading => t.heading } } + it 'contains the correct data of the child models' do + task_hash = [@destroy_deathstar, @study_with_yoda].collect { |t| { done: t.done, heading: t.heading } } @response[:completed_tasks].should eql task_hash end end - describe "handling nil values" do - - context "has_many" do - + describe 'handling nil values' do + context 'has_many' do before(:each) do Task.acts_as_api Task.api_accessible :include_tasks do |t| @@ -220,29 +209,28 @@ @response = @han.as_api_response(:include_tasks) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:tasks].should be_kind_of(Array) end - it "contains no associated child models" do + it 'contains no associated child models' do @response[:tasks].should have(0).items end - end - context "has one" do + context 'has one' do before(:each) do Profile.acts_as_api Profile.api_accessible :include_profile do |t| @@ -252,19 +240,19 @@ @response = @han.as_api_response(:include_profile) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:profile) end - it "returns nil for the association" do + it 'returns nil for the association' do @response[:profile].should be_nil end end diff --git a/spec/support/model_examples/callbacks.rb b/spec/support/model_examples/callbacks.rb index 5fd4d2d..a4bb499 100644 --- a/spec/support/model_examples/callbacks.rb +++ b/spec/support/model_examples/callbacks.rb @@ -1,38 +1,28 @@ -shared_examples_for "defining a model callback" do - - describe "for a" do - - describe "around_api_response" do - - it "skips rendering if not yielded" do +shared_examples_for 'defining a model callback' do + describe 'for a' do + describe 'around_api_response' do + it 'skips rendering if not yielded' do @luke.skip_api_response = true @luke.as_api_response(:name_only).keys.should include(:skipped) end - - it "renders if yielded" do + + it 'renders if yielded' do @luke.as_api_response(:name_only).keys.should_not include(:skipped) end - end - - describe "before_api_response" do - - it "is called properly" do + + describe 'before_api_response' do + it 'is called properly' do @luke.as_api_response(:name_only) @luke.before_api_response_called?.should eql(true) end - end - - describe "after_api_response" do - - it "is called properly" do + + describe 'after_api_response' do + it 'is called properly' do @luke.as_api_response(:name_only) @luke.after_api_response_called?.should eql(true) end - end - end - -end \ No newline at end of file +end diff --git a/spec/support/model_examples/closures.rb b/spec/support/model_examples/closures.rb index e1e606c..fa2af7c 100644 --- a/spec/support/model_examples/closures.rb +++ b/spec/support/model_examples/closures.rb @@ -1,49 +1,45 @@ -shared_examples_for "calling a closure in the api template" do - - describe "i.e. a proc (the record is passed as only parameter)" do - +shared_examples_for 'calling a closure in the api template' do + describe 'i.e. a proc (the record is passed as only parameter)' do before(:each) do @response = @luke.as_api_response(:calling_a_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param]) end - it "returns the correct values for the specified fields" do - @response.values.sort.should eql(["LUKE SKYWALKER", "Time"]) + it 'returns the correct values for the specified fields' do + @response.values.sort.should eql(['LUKE SKYWALKER', 'Time']) end end - describe "i.e. a lambda (the record is passed as only parameter)" do - + describe 'i.e. a lambda (the record is passed as only parameter)' do before(:each) do @response = @luke.as_api_response(:calling_a_lambda) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.sort_by(&:to_s).should eql([:all_caps_name, :without_param]) end - it "returns the correct values for the specified fields" do - @response.values.sort.should eql(["LUKE SKYWALKER", "Time"]) + it 'returns the correct values for the specified fields' do + @response.values.sort.should eql(['LUKE SKYWALKER', 'Time']) end - end end diff --git a/spec/support/model_examples/conditional_if.rb b/spec/support/model_examples/conditional_if.rb index 6fa5229..c33eef0 100644 --- a/spec/support/model_examples/conditional_if.rb +++ b/spec/support/model_examples/conditional_if.rb @@ -1,165 +1,145 @@ -shared_examples_for "conditional if statements" do - - describe "using the :if option" do - - describe "passing a symbol" do - - describe "that returns false" do - +shared_examples_for 'conditional if statements' do + describe 'using the :if option' do + describe 'passing a symbol' do + describe 'that returns false' do before(:each) do @response = @luke.as_api_response(:if_over_thirty) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns nil" do - + describe 'that returns nil' do before(:each) do @response = @luke.as_api_response(:if_returns_nil) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns true" do - + describe 'that returns true' do before(:each) do @response = @han.as_api_response(:if_over_thirty) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@han.first_name, @han.last_name) end - end - end - end - describe "passing a proc" do - - describe "that returns false" do - + describe 'passing a proc' do + describe 'that returns false' do before(:each) do @response = @luke.as_api_response(:if_over_thirty_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns nil" do - + describe 'that returns nil' do before(:each) do @response = @luke.as_api_response(:if_returns_nil_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns true" do - + describe 'that returns true' do before(:each) do @response = @han.as_api_response(:if_over_thirty_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@han.first_name, @han.last_name) end - end - end end - diff --git a/spec/support/model_examples/conditional_unless.rb b/spec/support/model_examples/conditional_unless.rb index 59a0cb1..b345455 100644 --- a/spec/support/model_examples/conditional_unless.rb +++ b/spec/support/model_examples/conditional_unless.rb @@ -1,165 +1,145 @@ -shared_examples_for "conditional unless statements" do - - describe "using the :unless option" do - - describe "passing a symbol" do - - describe "that returns false" do - +shared_examples_for 'conditional unless statements' do + describe 'using the :unless option' do + describe 'passing a symbol' do + describe 'that returns false' do before(:each) do @response = @luke.as_api_response(:unless_under_thirty) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns nil" do - + describe 'that returns nil' do before(:each) do @response = @luke.as_api_response(:unless_returns_nil) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name, @luke.last_name) end - end - describe "that returns true" do - + describe 'that returns true' do before(:each) do @response = @han.as_api_response(:unless_under_thirty) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@han.first_name, @han.last_name) end - end - end - end - describe "passing a proc" do - - describe "that returns false" do - + describe 'passing a proc' do + describe 'that returns false' do before(:each) do @response = @luke.as_api_response(:unless_under_thirty_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns nil" do - + describe 'that returns nil' do before(:each) do @response = @luke.as_api_response(:if_returns_nil_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should_not include(:full_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@luke.first_name) end - end - describe "that returns true" do - + describe 'that returns true' do before(:each) do @response = @han.as_api_response(:unless_under_thirty_proc) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "won't add the conditional field but all others" do + it 'will not add the conditional field but all others' do @response.keys.should include(:first_name) @response.keys.should include(:last_name) end - it "the other specified fields have the correct value" do + it 'the other specified fields have the correct value' do @response.values.should include(@han.first_name, @han.last_name) end - end - end - end diff --git a/spec/support/model_examples/enabled.rb b/spec/support/model_examples/enabled.rb index 4a88771..5f3d387 100644 --- a/spec/support/model_examples/enabled.rb +++ b/spec/support/model_examples/enabled.rb @@ -1,10 +1,9 @@ -shared_examples_for "acts_as_api is enabled" do - - it "indicates that acts_as_api is enabled" do +shared_examples_for 'acts_as_api is enabled' do + it 'indicates that acts_as_api is enabled' do User.acts_as_api?.should == true end - it "does respond to api_accessible" do + it 'does respond to api_accessible' do User.should respond_to :api_accessible end end diff --git a/spec/support/model_examples/extending.rb b/spec/support/model_examples/extending.rb index 1352fa5..244a261 100644 --- a/spec/support/model_examples/extending.rb +++ b/spec/support/model_examples/extending.rb @@ -1,112 +1,105 @@ -shared_examples_for "extending a given api template" do - - describe "multiple times" do - +shared_examples_for 'extending a given api template' do + describe 'multiple times' do before(:each) do User.api_accessible :public do |t| t.add :first_name end - User.api_accessible :for_buddies, :extend => :public do |t| + User.api_accessible :for_buddies, extend: :public do |t| t.add :age end - User.api_accessible :private, :extend => :for_buddies do |t| + User.api_accessible :private, extend: :for_buddies do |t| t.add :last_name end @response = @luke.as_api_response(:private) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(3).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.sort_by(&:to_s).should eql([:age, :first_name, :last_name]) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.sort_by(&:to_s).should eql([@luke.age, @luke.first_name, @luke.last_name].sort_by(&:to_s)) end - end - describe "and removing a former added value" do - + describe 'and removing a former added value' do before(:each) do @response = @luke.as_api_response(:age_and_first_name) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.sort_by(&:to_s).should eql([:first_name, :age].sort_by(&:to_s)) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.sort_by(&:to_s).should eql([@luke.first_name, @luke.age].sort_by(&:to_s)) end - end - describe "and inherit a field using another template name", :meow => true do - + describe 'and inherit a field using another template name' do before(:each) do Task.acts_as_api Task.api_accessible :other_template do |t| t.add :description t.add :time_spent end - User.api_accessible :extending_other_template, :extend => :other_sub_template + User.api_accessible :extending_other_template, extend: :other_sub_template @response = @luke.as_api_response(:extending_other_template) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:first_name) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.should include(@luke.first_name) end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:tasks) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:tasks].should be_an Array @response[:tasks].should have(3).tasks end - it "contains the associated child models with the determined api template" do + it 'contains the associated child models with the determined api template' do @response[:tasks].each do |task| task.keys.should include(:description, :time_spent) task.keys.should have(2).attributes end end - it "contains the correct data of the child models" do - task_hash = [ @destroy_deathstar, @study_with_yoda, @win_rebellion ].collect{|t| { :description => t.description, :time_spent => t.time_spent } } + it 'contains the correct data of the child models' do + task_hash = [@destroy_deathstar, @study_with_yoda, @win_rebellion].collect { |t| { description: t.description, time_spent: t.time_spent } } @response[:tasks].should eql task_hash end end - -end \ No newline at end of file +end diff --git a/spec/support/model_examples/methods.rb b/spec/support/model_examples/methods.rb index b5d4ec6..ce876e8 100644 --- a/spec/support/model_examples/methods.rb +++ b/spec/support/model_examples/methods.rb @@ -1,23 +1,21 @@ -shared_examples_for "calling a method in the api template" do - +shared_examples_for 'calling a method in the api template' do before(:each) do @response = @luke.as_api_response(:only_full_name) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields by name" do + it 'returns all specified fields by name' do @response.keys.should include(:full_name) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.should include(@luke.full_name) end - -end \ No newline at end of file +end diff --git a/spec/support/model_examples/options.rb b/spec/support/model_examples/options.rb index 6f93153..571b8fd 100644 --- a/spec/support/model_examples/options.rb +++ b/spec/support/model_examples/options.rb @@ -1,53 +1,49 @@ -shared_examples_for "options" do - - describe "options in the api template" do - +shared_examples_for 'options' do + describe 'options in the api template' do before :each do User.api_accessible :with_options do |t| - t.add lambda{|model,options| options }, :as => :options + t.add ->(_, options) { options }, as: :options t.add :profile - t.add :first_name, :if => lambda{|m,options| options[:with_name] } + t.add :first_name, if: ->(_, options) { options[:with_name] } end Profile.acts_as_api Profile.api_accessible :with_options do |t| - t.add lambda{|model,options| options }, :as => :options + t.add ->(_, options) { options }, as: :options end Task.acts_as_api Task.api_accessible :other_template do |t| t.add :description t.add :time_spent - t.add lambda{|model,options| options }, :as => :options + t.add ->(_, options) { options }, as: :options end end - context "as_api_response accept options" do - before :each do - @response = @luke.as_api_response(:with_options, :loc => [12, 13]) + context 'as_api_response accept options' do + before :each do + @response = @luke.as_api_response(:with_options, loc: [12, 13]) end - it "returns the options field as specified" do - @response[:options][:loc].should == [12, 13] + it 'returns the options field as specified' do + @response[:options][:loc].should == [12, 13] end - it "returns the option for the associations " do - @response[:profile][:options][:loc].should == [12, 13] + it 'returns the option for the associations ' do + @response[:profile][:options][:loc].should == [12, 13] end - end - context "allowed_to_render accept options" do - it "should not contains first_name when options[:with_name] is false" do - @response = @luke.as_api_response(:with_options, :with_name => false) - @response.should_not include(:first_name) + context 'allowed_to_render accept options' do + it 'should not contains first_name when options[:with_name] is false' do + @response = @luke.as_api_response(:with_options, with_name: false) + @response.should_not include(:first_name) end - it "should contains first_name when options[:with_name] is true" do - @response = @luke.as_api_response(:with_options, :with_name => true) - @response[:first_name].should == 'Luke' + it 'should contains first_name when options[:with_name] is true' do + @response = @luke.as_api_response(:with_options, with_name: true) + @response[:first_name].should == 'Luke' end end - end end diff --git a/spec/support/model_examples/renaming.rb b/spec/support/model_examples/renaming.rb index 656212c..e19a7b9 100644 --- a/spec/support/model_examples/renaming.rb +++ b/spec/support/model_examples/renaming.rb @@ -1,50 +1,45 @@ -shared_examples_for "renaming" do - - describe "an attribute in the api template" do - +shared_examples_for 'renaming' do + describe 'an attribute in the api template' do before(:each) do @response = @luke.as_api_response(:rename_last_name) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:family_name) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.should include(@luke.last_name) end - end - describe "the node/key of a method in the api template" do - + describe 'the node/key of a method in the api template' do before(:each) do @response = @luke.as_api_response(:rename_full_name) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:other_full_name) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response.values.should include(@luke.full_name) end - end end diff --git a/spec/support/model_examples/simple.rb b/spec/support/model_examples/simple.rb index 2c988ff..b57d2b0 100644 --- a/spec/support/model_examples/simple.rb +++ b/spec/support/model_examples/simple.rb @@ -1,23 +1,21 @@ -shared_examples_for "listing attributes in the api template" do - +shared_examples_for 'listing attributes in the api template' do before(:each) do @response = @luke.as_api_response(:name_only) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(2).keys end - it "returns the specified fields only" do + it 'returns the specified fields only' do @response.keys.should include(:first_name, :last_name) end - it "the specified fields have the correct value" do + it 'the specified fields have the correct value' do @response.values.should include(@luke.first_name, @luke.last_name) end - end diff --git a/spec/support/model_examples/sub_nodes.rb b/spec/support/model_examples/sub_nodes.rb index 17d56c4..f23fd23 100644 --- a/spec/support/model_examples/sub_nodes.rb +++ b/spec/support/model_examples/sub_nodes.rb @@ -1,105 +1,99 @@ -shared_examples_for "creating a sub hash in the api template" do - - describe "and putting an attribute in it" do - +shared_examples_for 'creating a sub hash in the api template' do + describe 'and putting an attribute in it' do before(:each) do @response = @luke.as_api_response(:sub_node) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:sub_nodes) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:sub_nodes].should be_a Hash end - it "provides the correct number of sub nodes" do + it 'provides the correct number of sub nodes' do @response[:sub_nodes].should have(1).keys end - it "provides the correct sub nodes values" do - @response[:sub_nodes][:foo].should eql("something") + it 'provides the correct sub nodes values' do + @response[:sub_nodes][:foo].should eql('something') end end - describe "multiple times and putting an attribute in it" do - + describe 'multiple times and putting an attribute in it' do before(:each) do @response = @luke.as_api_response(:nested_sub_node) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:sub_nodes) end - it "returns the correct values for the specified fields" do + it 'returns the correct values for the specified fields' do @response[:sub_nodes].should be_a Hash end - it "provides the correct number of sub nodes" do + it 'provides the correct number of sub nodes' do @response[:sub_nodes].should have(1).keys end - it "provides the correct number of sub nodes in the second level" do + it 'provides the correct number of sub nodes in the second level' do @response[:sub_nodes][:foo].should have(1).keys end - it "provides the correct sub nodes values" do + it 'provides the correct sub nodes values' do @response[:sub_nodes][:foo].tap do |foo| foo[:bar].tap do |bar| bar.should eql(@luke.last_name) end end end - end - describe "using a method" do - + describe 'using a method' do before(:each) do @response = @luke.as_api_response(:nested_sub_hash) end - it "returns a hash" do + it 'returns a hash' do @response.should be_kind_of(Hash) end - it "returns the correct number of fields" do + it 'returns the correct number of fields' do @response.should have(1).keys end - it "returns all specified fields" do + it 'returns all specified fields' do @response.keys.should include(:sub_hash) end - it "provides the correct number of sub nodes" do + it 'provides the correct number of sub nodes' do @response[:sub_hash].should have(2).keys end - it "provides the correct sub nodes" do + it 'provides the correct sub nodes' do @response[:sub_hash].keys.should include(:foo, :hello) end - it "provides the correct values in its sub nodes" do - @response[:sub_hash].values.should include("bar", "world") + it 'provides the correct values in its sub nodes' do + @response[:sub_hash].values.should include('bar', 'world') end - end -end \ No newline at end of file +end diff --git a/spec/support/model_examples/undefined.rb b/spec/support/model_examples/undefined.rb index 1ca7353..a043d52 100644 --- a/spec/support/model_examples/undefined.rb +++ b/spec/support/model_examples/undefined.rb @@ -1,7 +1,5 @@ -shared_examples_for "trying to render an api template that is not defined" do - - it "raises an descriptive error" do - lambda{ @luke.as_api_response(:does_not_exist) }.should raise_error(ActsAsApi::TemplateNotFoundError) +shared_examples_for 'trying to render an api template that is not defined' do + it 'raises an descriptive error' do + -> { @luke.as_api_response(:does_not_exist) }.should raise_error(ActsAsApi::TemplateNotFoundError) end - -end \ No newline at end of file +end diff --git a/spec/support/model_examples/untouched.rb b/spec/support/model_examples/untouched.rb index 0ff6ae0..55fba7f 100644 --- a/spec/support/model_examples/untouched.rb +++ b/spec/support/model_examples/untouched.rb @@ -1,13 +1,11 @@ -shared_examples_for "untouched models" do - - describe "has disabled acts_as_api by default" do - it "indicates that acts_as_api is disabled" do +shared_examples_for 'untouched models' do + describe 'has disabled acts_as_api by default' do + it 'indicates that acts_as_api is disabled' do Untouched.acts_as_api?.should == false end - it "does not respond to api_accessible" do + it 'does not respond to api_accessible' do Untouched.should_not respond_to :api_accessible end end - end diff --git a/spec/support/simple_fixtures.rb b/spec/support/simple_fixtures.rb index a3b05bf..706f793 100644 --- a/spec/support/simple_fixtures.rb +++ b/spec/support/simple_fixtures.rb @@ -1,16 +1,15 @@ module SimpleFixtures - def setup_models - @luke = User.create({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) - @han = User.create({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) - @leia = User.create({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) + @luke = User.create(first_name: 'Luke', last_name: 'Skywalker', age: 25, active: true) + @han = User.create(first_name: 'Han', last_name: 'Solo', age: 35, active: true) + @leia = User.create(first_name: 'Princess', last_name: 'Leia', age: 25, active: false) - @luke.profile = Profile.new({ :avatar => 'picard.jpg', :homepage => 'lukasarts.com' }) - @luke.profile.save + @luke.profile = Profile.new(avatar: 'picard.jpg', homepage: 'lukasarts.com') + @luke.profile.save! - @destroy_deathstar = @luke.tasks.create({ :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true }) - @study_with_yoda = @luke.tasks.create({ :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true }) - @win_rebellion = @luke.tasks.create({ :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false }) + @destroy_deathstar = @luke.tasks.create(heading: 'Destroy Deathstar', description: 'XWing, Shoot, BlowUp', time_spent: 30, done: true) + @study_with_yoda = @luke.tasks.create(heading: 'Study with Yoda', description: 'Jedi Stuff, ya know', time_spent: 60, done: true) + @win_rebellion = @luke.tasks.create(heading: 'Win Rebellion', description: 'no idea yet...', time_spent: 180, done: false) @luke.save! @han.save! @@ -22,38 +21,12 @@ def clean_up_models end def setup_objects - @luke = PlainObject.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) - @han = PlainObject.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) - @leia = PlainObject.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) + @luke = PlainObject.new(first_name: 'Luke', last_name: 'Skywalker', age: 25, active: true) + @han = PlainObject.new(first_name: 'Han', last_name: 'Solo', age: 35, active: true) + @leia = PlainObject.new(first_name: 'Princess', last_name: 'Leia', age: 25, active: false) end - - # def setup_roflscale_models - # @orm_for_testing = :vanilla - # @user_model = VanillaUser - # @task_model = VanillaTask - # @profile_model = VanillaProfile - # @untouched_model = VanillaUntouched - # - # @luke = @user_model.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true }) - # @han = @user_model.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true }) - # @leia = @user_model.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false }) - # - # @luke.profile = @profile_model.new({ :user => @luke, :avatar => 'picard.jpg', :homepage => 'lukasarts.com' }) - # - # @destroy_deathstar = @task_model.new({ :user => @luke, :heading => "Destroy Deathstar", :description => "XWing, Shoot, BlowUp", :time_spent => 30, :done => true }) - # @study_with_yoda = @task_model.new({ :user => @luke, :heading => "Study with Yoda", :description => "Jedi Stuff, ya know", :time_spent => 60, :done => true }) - # @win_rebellion = @task_model.new({ :user => @luke, :heading => "Win Rebellion", :description => "no idea yet...", :time_spent => 180, :done => false }) - # - # @luke.tasks << @destroy_deathstar << @study_with_yoda << @win_rebellion - # end - # - # def clean_up_roflscale_models - # # nothing to do ;) - # end - end - RSpec.configure do |c| c.include SimpleFixtures end