From b7b3460fd3241cf19742ab7f2a3803a48ffc9ec3 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Fri, 18 Apr 2014 23:55:15 +0200 Subject: [PATCH 1/3] Update to rails 4.1 --- .env.example | 1 + Gemfile | 19 ++- Gemfile.lock | 154 +++++++++--------- app/models/agent.rb | 6 +- app/models/user.rb | 4 +- bin/bundle | 3 + bin/rails | 4 + bin/rake | 4 + config/application.rb | 11 +- config/environments/development.rb | 15 +- config/environments/production.rb | 38 +++-- config/environments/test.rb | 10 +- config/initializers/devise.rb | 18 +- config/initializers/secret_token.rb | 2 +- config/routes.rb | 8 +- lib/rdbms_functions.rb | 4 +- spec/lib/utils_spec.rb | 2 +- spec/models/agents/hipchat_agent_spec.rb | 2 +- .../agents/public_transport_agent_spec.rb | 33 ++-- spec/spec_helper.rb | 1 + 20 files changed, 191 insertions(+), 148 deletions(-) create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake diff --git a/.env.example b/.env.example index cc04f047..fb0747bc 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ # Replace the following with the output from "rake secret" APP_SECRET_TOKEN=REPLACE_ME_NOW! +DEVISE_SECRET_TOKEN=REPLACE_ME_NOW! # This is the domain where your Huginn instance will be running. The default should work # for development, but it needs to be changed to your Huginn domain when you deploy to a diff --git a/Gemfile b/Gemfile index 3fbbdf2e..7a17a1a6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,14 @@ source 'https://rubygems.org' -gem 'rails', '3.2.17' +gem 'protected_attributes', '~>1.0.7' + +gem 'rails', '4.1.0' gem 'mysql2', '~> 0.3.13' -gem 'devise', '~> 3.0.0' +gem 'devise', '~> 3.2.4' gem 'kaminari', '~> 0.14.1' gem 'bootstrap-kaminari-views', '~> 0.0.2' gem 'rufus-scheduler', '~> 3.0.7', require: false -gem 'json', '>= 1.7.7' +gem 'json', '~> 1.8.1' gem 'jsonpath', '~> 0.5.3' gem 'twilio-ruby', '~> 3.10.0' gem 'ruby-growl', '~> 4.1.0' @@ -20,17 +22,17 @@ gem 'daemons', '~> 1.1.9' gem 'foreman', '~> 0.63.0' -gem 'sass-rails', '~> 3.2.3' -gem 'coffee-rails', '~> 3.2.1' -gem 'uglifier', '>= 1.0.3' -gem 'select2-rails', '~> 3.4.3' +gem 'sass-rails', '~> 4.0.0' +gem 'coffee-rails', '~> 4.0.0' +gem 'uglifier', '>= 1.3.0' +gem 'select2-rails', '~> 3.5.4' gem 'jquery-rails', '~> 3.0.4' gem 'ace-rails-ap', '~> 2.0.1' # geokit-rails doesn't work with geokit 1.8.X but it specifies ~> 1.5 # in its own Gemfile. gem 'geokit', '~> 1.6.7' -gem 'geokit-rails3', '~> 0.1.5' +gem 'geokit-rails', '~> 2.0.0' gem 'kramdown', '~> 1.1.0' gem 'typhoeus', '~> 0.6.3' @@ -60,6 +62,7 @@ group :development, :test do gem 'rspec' gem 'shoulda-matchers' gem 'rr' + gem 'delorean' gem 'webmock', require: false gem 'coveralls', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index cf932d43..09dbd764 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,38 +12,35 @@ GEM remote: https://rubygems.org/ specs: ace-rails-ap (2.0.1) - actionmailer (3.2.17) - actionpack (= 3.2.17) + actionmailer (4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) mail (~> 2.5.4) - actionpack (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) + actionpack (4.1.0) + actionview (= 4.1.0) + activesupport (= 4.1.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) - activerecord (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - activesupport (3.2.17) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) + activemodel (4.1.0) + activesupport (= 4.1.0) + builder (~> 3.1) + activerecord (4.1.0) + activemodel (= 4.1.0) + activesupport (= 4.1.0) + arel (~> 5.0.0) + activesupport (4.1.0) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) addressable (2.3.6) - arel (3.0.3) + arel (5.0.1.20140414130214) bcrypt (3.1.7) - bcrypt-ruby (3.1.5) - bcrypt (>= 3.1.3) better_errors (1.1.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -53,11 +50,12 @@ GEM kaminari (>= 0.13) rails (>= 3.1) buftok (0.2.0) - builder (3.0.4) + builder (3.2.2) + chronic (0.10.2) coderay (1.1.0) - coffee-rails (3.2.2) + coffee-rails (4.0.1) coffee-script (>= 2.2.0) - railties (~> 3.2.0) + railties (>= 4.0.0, < 5.0) coffee-script (2.2.0) coffee-script-source execjs @@ -78,10 +76,13 @@ GEM delayed_job_active_record (4.0.1) activerecord (>= 3.0, < 4.2) delayed_job (>= 3.0, < 4.1) - devise (3.0.4) - bcrypt-ruby (~> 3.0) + delorean (2.1.0) + chronic + devise (3.2.4) + bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.2.5) docile (1.1.3) @@ -116,9 +117,9 @@ GEM thor (>= 0.13.6) geokit (1.6.7) multi_json (>= 1.3.2) - geokit-rails3 (0.1.5) + geokit-rails (2.0.1) geokit (~> 1.5) - rails (~> 3.0) + rails (>= 3.0) hashie (2.0.5) hike (1.2.3) hipchat (1.1.0) @@ -130,7 +131,6 @@ GEM json (~> 1.8) multi_xml (>= 0.5.2) i18n (0.6.9) - journey (1.0.4) jquery-rails (3.0.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) @@ -154,6 +154,7 @@ GEM method_source (0.8.2) mime-types (1.25.1) mini_portile (0.5.3) + minitest (5.3.3) multi_json (1.9.2) multi_xml (0.5.5) multipart-post (2.0.0) @@ -169,35 +170,31 @@ GEM rack (~> 1.2) orm_adapter (0.5.0) polyglot (0.3.4) + protected_attributes (1.0.7) + activemodel (>= 4.0.1, < 5.0) pry (0.9.12.6) coderay (~> 1.0) method_source (~> 0.8) slop (~> 3.4) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.4) - rack + rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (3.2.17) - actionmailer (= 3.2.17) - actionpack (= 3.2.17) - activerecord (= 3.2.17) - activeresource (= 3.2.17) - activesupport (= 3.2.17) - bundler (~> 1.0) - railties (= 3.2.17) - railties (3.2.17) - actionpack (= 3.2.17) - activesupport (= 3.2.17) - rack-ssl (~> 1.3.2) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + actionview (= 4.1.0) + activemodel (= 4.1.0) + activerecord (= 4.1.0) + activesupport (= 4.1.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.0) + sprockets-rails (~> 2.0) + railties (4.1.0) + actionpack (= 4.1.0) + activesupport (= 4.1.0) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.2.2) - rdoc (3.12.2) - json (~> 1.4) + thor (>= 0.18.1, < 2.0) + rake (10.3.1) ref (1.0.5) rest-client (1.6.7) mime-types (>= 1.16) @@ -227,13 +224,13 @@ GEM rufus-scheduler (3.0.7) tzinfo safe_yaml (1.0.2) - sass (3.3.5) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - select2-rails (3.4.9) - sass-rails + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) + select2-rails (3.5.4) thor (~> 0.14) shoulda-matchers (2.6.0) activesupport (>= 3.0.0) @@ -244,11 +241,15 @@ GEM simplecov-html (~> 0.8.0) simplecov-html (0.8.0) slop (3.5.0) - sprockets (2.2.2) + sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) systemu (2.6.4) term-ansicolor (1.3.0) tins (~> 1.0) @@ -279,7 +280,8 @@ GEM simple_oauth (~> 0.2.0) typhoeus (0.6.8) ethon (>= 0.7.0) - tzinfo (0.3.39) + tzinfo (1.1.0) + thread_safe (~> 0.1) uglifier (2.5.0) execjs (>= 0.3.0) json (>= 1.8.0) @@ -308,43 +310,45 @@ DEPENDENCIES better_errors binding_of_caller bootstrap-kaminari-views (~> 0.0.2) - coffee-rails (~> 3.2.1) + coffee-rails (~> 4.0.0) coveralls daemons (~> 1.1.9) delayed_job (~> 4.0.0) delayed_job_active_record (~> 4.0.0) - devise (~> 3.0.0) + delorean + devise (~> 3.2.4) dotenv-rails em-http-request (~> 1.1.2) forecast_io (~> 2.0.0) foreman (~> 0.63.0) geokit (~> 1.6.7) - geokit-rails3 (~> 0.1.5) + geokit-rails (~> 2.0.0) hipchat (~> 1.1.0) jquery-rails (~> 3.0.4) - json (>= 1.7.7) + json (~> 1.8.1) jsonpath (~> 0.5.3) kaminari (~> 0.14.1) kramdown (~> 1.1.0) mysql2 (~> 0.3.13) nokogiri (~> 1.6.0) + protected_attributes (~> 1.0.7) pry - rails (= 3.2.17) + rails (= 4.1.0) rr rspec rspec-rails rturk (~> 2.11.0) ruby-growl (~> 4.1.0) rufus-scheduler (~> 3.0.7) - sass-rails (~> 3.2.3) - select2-rails (~> 3.4.3) + sass-rails (~> 4.0.0) + select2-rails (~> 3.5.4) shoulda-matchers therubyracer (~> 0.12.1) twilio-ruby (~> 3.10.0) twitter (~> 5.7.1) twitter-stream! typhoeus (~> 0.6.3) - uglifier (>= 1.0.3) + uglifier (>= 1.3.0) webmock weibo_2 (~> 0.1.4) wunderground (~> 1.1.0) diff --git a/app/models/agent.rb b/app/models/agent.rb index bf528e71..df3fae6e 100644 --- a/app/models/agent.rb +++ b/app/models/agent.rb @@ -39,10 +39,10 @@ class Agent < ActiveRecord::Base after_save :possibly_update_event_expirations belongs_to :user, :inverse_of => :agents - has_many :events, :dependent => :delete_all, :inverse_of => :agent, :order => "events.id desc" + has_many :events, -> { order("events.id desc") }, :dependent => :delete_all, :inverse_of => :agent has_one :most_recent_event, :inverse_of => :agent, :class_name => "Event", :order => "events.id desc" - has_many :logs, :dependent => :delete_all, :inverse_of => :agent, :class_name => "AgentLog", :order => "agent_logs.id desc" - has_many :received_events, :through => :sources, :class_name => "Event", :source => :events, :order => "events.id desc" + has_many :logs, -> { order("agent_logs.id desc") }, :dependent => :delete_all, :inverse_of => :agent, :class_name => "AgentLog" + has_many :received_events, -> { order("events.id desc") }, :through => :sources, :class_name => "Event", :source => :events has_many :links_as_source, :dependent => :delete_all, :foreign_key => "source_id", :class_name => "Link", :inverse_of => :source has_many :links_as_receiver, :dependent => :delete_all, :foreign_key => "receiver_id", :class_name => "Link", :inverse_of => :receiver has_many :sources, :through => :links_as_receiver, :class_name => "Agent", :inverse_of => :receivers diff --git a/app/models/user.rb b/app/models/user.rb index b6970c65..c8fc02d9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,8 +23,8 @@ class User < ActiveRecord::Base validates_inclusion_of :invitation_code, :on => :create, :in => INVITATION_CODES, :message => "is not valid" has_many :user_credentials, :dependent => :destroy, :inverse_of => :user - has_many :events, :order => "events.created_at desc", :dependent => :delete_all, :inverse_of => :user - has_many :agents, :order => "agents.created_at desc", :dependent => :destroy, :inverse_of => :user + has_many :events, -> { order("events.created_at desc") }, :dependent => :delete_all, :inverse_of => :user + has_many :agents, -> { order("agents.created_at desc") }, :dependent => :destroy, :inverse_of => :user has_many :logs, :through => :agents, :class_name => "AgentLog" # Allow users to login via either email or username. diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..66e9889e --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 00000000..728cd85a --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 00000000..17240489 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/config/application.rb b/config/application.rb index 1d5cc7c1..00081131 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,12 +2,7 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - 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 +Bundler.require(:default, Rails.env) module Huginn class Application < Rails::Application @@ -18,10 +13,6 @@ module Huginn # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W(#{config.root}/lib) - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named. - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer diff --git a/config/environments/development.rb b/config/environments/development.rb index 243c8655..a7b199a1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -8,8 +8,11 @@ Huginn::Application.configure do # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = false # Show full error reports and disable caching config.consider_all_requests_local = true @@ -24,12 +27,8 @@ Huginn::Application.configure do # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 - - # Do not compress assets - config.assets.compress = false + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load # Expands the lines which load the assets config.assets.debug = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 05cc1c25..076b8c24 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -4,15 +4,27 @@ Huginn::Application.configure do # Code is not reloaded between requests config.cache_classes = true + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS - config.assets.compress = true + config.assets.js_compressor = :uglifier + config.assets.css_compressor = :sass # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false @@ -20,10 +32,10 @@ Huginn::Application.configure do # Generate digests for assets URLs config.assets.digest = true - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' - # Specifies the header that your server uses for sending files + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx @@ -50,19 +62,25 @@ Huginn::Application.configure do # Precompile additional assets (application.js.coffee.erb, application.css, and all non-JS/CSS are already added) config.assets.precompile += %w( graphing.js user_credentials.js ) - # Enable threaded mode - # config.threadsafe! + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) + # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] } config.action_mailer.asset_host = ENV['DOMAIN'] diff --git a/config/environments/test.rb b/config/environments/test.rb index abe2e4b9..6178bd8c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -7,13 +7,15 @@ Huginn::Application.configure do # and recreated between test runs. Don't rely on the data there! config.cache_classes = true + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -22,7 +24,7 @@ Huginn::Application.configure do 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/config/initializers/devise.rb b/config/initializers/devise.rb index 884b8249..ac32d00e 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,9 +1,15 @@ # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + config.secret_key = ENV['DEVISE_SECRET_TOKEN'] + # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, - # note that it will be overwritten if you use your own mailer class with default "from" parameter. + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" # Configure the class responsible to send e-mails. @@ -72,6 +78,12 @@ Devise.setup do |config| # passing :skip => :sessions to `devise_for` in your config/routes.rb config.skip_session_storage = [:http_auth] + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + # ==> Configuration for :database_authenticatable # For bcrypt, this is the cost for hashing the password and defaults to 10. If # using other encryptors, it sets how many times you want the password re-encrypted. @@ -174,10 +186,6 @@ Devise.setup do |config| # REST_AUTH_SITE_KEY to pepper) # config.encryptor = :sha512 - # ==> Configuration for :token_authenticatable - # Defines name of the authentication token params key - # config.token_authentication_key = :auth_token - # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index da3f8f99..af20c4d3 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Huginn::Application.config.secret_token = ENV['APP_SECRET_TOKEN'] +Huginn::Application.config.secret_key_base = ENV['APP_SECRET_TOKEN'] diff --git a/config/routes.rb b/config/routes.rb index 4b474b79..76131b0d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,18 +28,18 @@ Huginn::Application.routes.draw do resources :user_credentials, :except => :show - match "/worker_status" => "worker_status#show" + get "/worker_status" => "worker_status#show" post "/users/:user_id/update_location/:secret" => "user_location_updates#create" - match "/users/:user_id/web_requests/:agent_id/:secret" => "web_requests#handle_request", :as => :web_requests + match "/users/:user_id/web_requests/:agent_id/:secret" => "web_requests#handle_request", :as => :web_requests, :via => [:get, :post, :put, :delete] post "/users/:user_id/webhooks/:agent_id/:secret" => "web_requests#handle_request" # legacy # To enable DelayedJobWeb, see the 'Enable DelayedJobWeb' section of the README. -# match "/delayed_job" => DelayedJobWeb, :anchor => false +# get "/delayed_job" => DelayedJobWeb, :anchor => false devise_for :users, :sign_out_via => [ :post, :delete ] - match "/about" => "home#about" + get "/about" => "home#about" root :to => "home#index" end diff --git a/lib/rdbms_functions.rb b/lib/rdbms_functions.rb index 3de9e865..faa78456 100644 --- a/lib/rdbms_functions.rb +++ b/lib/rdbms_functions.rb @@ -1,10 +1,10 @@ module RDBMSFunctions def rdbms_date_add(source, unit, amount) - adapter_type = connection.adapter_name.downcase.to_sym + adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym case adapter_type when :mysql, :mysql2 "DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})" - when :postgresql + when :postgresql "(#{source} + INTERVAL '#{amount} #{unit}')" else raise NotImplementedError, "Unknown adapter type '#{adapter_type}'" diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index 4391aacb..d1b59974 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -97,7 +97,7 @@ describe Utils do it "escapes tags in the output JSON" do cleaned_json = Utils.jsonify(:foo => "bar", :xss => "") cleaned_json.should_not include("") - cleaned_json.should include("<\\/script>") + cleaned_json.should include('\\u003c/script\\u003e') end it "html_safes the output unless :skip_safe is passed in" do diff --git a/spec/models/agents/hipchat_agent_spec.rb b/spec/models/agents/hipchat_agent_spec.rb index 875a37ca..5c80b6b9 100644 --- a/spec/models/agents/hipchat_agent_spec.rb +++ b/spec/models/agents/hipchat_agent_spec.rb @@ -62,7 +62,7 @@ describe Agents::HipchatAgent do end it "should merge all options" do - @checker.send(:merge_options, @event).should == { + @checker.send(:merge_options, @event).deep_symbolize_keys.should == { :room_name => "test", :username => "Huggin user", :message => "Looks like its going to rain", diff --git a/spec/models/agents/public_transport_agent_spec.rb b/spec/models/agents/public_transport_agent_spec.rb index a6786697..086c4636 100644 --- a/spec/models/agents/public_transport_agent_spec.rb +++ b/spec/models/agents/public_transport_agent_spec.rb @@ -19,7 +19,6 @@ describe Agents::PublicTransportAgent do stub_request(:get, "http://webservices.nextbus.com/service/publicXMLFeed?a=sf-muni&command=predictionsForMultiStops&stops=N%7C5215"). with(:headers => {'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}). to_return(:status => 200, :body => File.read(Rails.root.join("spec/data_fixtures/public_transport_agent.xml")), :headers => {}) - stub(Time).now {"2014-01-14 20:21:30 +0500".to_time} end it "should create 4 events" do @@ -27,15 +26,18 @@ describe Agents::PublicTransportAgent do end it "should add 4 items to memory" do - @agent.memory.should == {} - @agent.check - @agent.memory.should == {"existing_routes" => [ - {"stopTag"=>"5221", "tripTag"=>"5840324", "epochTime"=>"1389706393991", "currentTime"=>"2014-01-14 20:21:30 +0500"}, - {"stopTag"=>"5221", "tripTag"=>"5840083", "epochTime"=>"1389706512784", "currentTime"=>"2014-01-14 20:21:30 +0500"}, - {"stopTag"=>"5215", "tripTag"=>"5840324", "epochTime"=>"1389706282012", "currentTime"=>"2014-01-14 20:21:30 +0500"}, - {"stopTag"=>"5215", "tripTag"=>"5840083", "epochTime"=>"1389706400805", "currentTime"=>"2014-01-14 20:21:30 +0500"} - ] - } + time_travel_to Time.parse("2014-01-14 20:21:30 +0500") do + @agent.memory.should == {} + @agent.check + @agent.save + @agent.reload.memory.should == {"existing_routes" => [ + {"stopTag"=>"5221", "tripTag"=>"5840324", "epochTime"=>"1389706393991", "currentTime"=>Time.now.to_s}, + {"stopTag"=>"5221", "tripTag"=>"5840083", "epochTime"=>"1389706512784", "currentTime"=>Time.now.to_s}, + {"stopTag"=>"5215", "tripTag"=>"5840324", "epochTime"=>"1389706282012", "currentTime"=>Time.now.to_s}, + {"stopTag"=>"5215", "tripTag"=>"5840083", "epochTime"=>"1389706400805", "currentTime"=>Time.now.to_s} + ] + } + end end it "should not create events twice" do @@ -44,10 +46,13 @@ describe Agents::PublicTransportAgent do end it "should reset memory after 2 hours" do - lambda { @agent.check }.should change {@agent.events.count}.by(4) - stub(Time).now {"2014-01-14 20:21:30 +0500".to_time + 3.hours} - @agent.cleanup_old_memory - lambda { @agent.check }.should change {@agent.events.count}.by(4) + time_travel_to Time.parse("2014-01-14 20:21:30 +0500") do + lambda { @agent.check }.should change {@agent.events.count}.by(4) + end + time_travel_to "2014-01-14 23:21:30 +0500".to_time do + @agent.cleanup_old_memory + lambda { @agent.check }.should change {@agent.events.count}.by(4) + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f65b89cd..4172abd5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,4 +42,5 @@ RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.include SpecHelpers + config.include Delorean end From 335acdb8998846c94d60704e6344d00865964ed6 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Sat, 19 Apr 2014 22:57:23 +0200 Subject: [PATCH 2/3] Updated gems, fixed issue with flash messages In rails4 the flash hash keys differentiate between "notice" and :notice, thus we need to typecast the key before comparing it --- Gemfile | 16 ++++++++-------- Gemfile.lock | 26 +++++++++++++------------- app/views/layouts/_messages.html.erb | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 7a17a1a6..6ccd954b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,9 @@ source 'https://rubygems.org' gem 'protected_attributes', '~>1.0.7' gem 'rails', '4.1.0' -gem 'mysql2', '~> 0.3.13' +gem 'mysql2', '~> 0.3.15' gem 'devise', '~> 3.2.4' -gem 'kaminari', '~> 0.14.1' +gem 'kaminari', '~> 0.15.1' gem 'bootstrap-kaminari-views', '~> 0.0.2' gem 'rufus-scheduler', '~> 3.0.7', require: false gem 'json', '~> 1.8.1' @@ -26,19 +26,19 @@ gem 'sass-rails', '~> 4.0.0' gem 'coffee-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0' gem 'select2-rails', '~> 3.5.4' -gem 'jquery-rails', '~> 3.0.4' +gem 'jquery-rails', '~> 3.1.0' gem 'ace-rails-ap', '~> 2.0.1' # geokit-rails doesn't work with geokit 1.8.X but it specifies ~> 1.5 # in its own Gemfile. -gem 'geokit', '~> 1.6.7' -gem 'geokit-rails', '~> 2.0.0' +gem 'geokit', '~> 1.8.4' +gem 'geokit-rails', '~> 2.0.1' -gem 'kramdown', '~> 1.1.0' +gem 'kramdown', '~> 1.3.3' gem 'typhoeus', '~> 0.6.3' -gem 'nokogiri', '~> 1.6.0' +gem 'nokogiri', '~> 1.6.1' -gem 'wunderground', '~> 1.1.0' +gem 'wunderground', '~> 1.2.0' gem 'forecast_io', '~> 2.0.0' gem 'rturk', '~> 2.11.0' diff --git a/Gemfile.lock b/Gemfile.lock index 09dbd764..a9bd8284 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,7 +115,7 @@ GEM foreman (0.63.0) dotenv (>= 0.7) thor (>= 0.13.6) - geokit (1.6.7) + geokit (1.8.4) multi_json (>= 1.3.2) geokit-rails (2.0.1) geokit (~> 1.5) @@ -131,7 +131,7 @@ GEM json (~> 1.8) multi_xml (>= 0.5.2) i18n (0.6.9) - jquery-rails (3.0.4) + jquery-rails (3.1.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) @@ -139,10 +139,10 @@ GEM multi_json jwt (0.1.11) multi_json (>= 1.5) - kaminari (0.14.1) + kaminari (0.15.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - kramdown (1.1.0) + kramdown (1.3.3) libv8 (3.16.14.3) macaddr (1.7.1) systemu (~> 2.6.2) @@ -297,7 +297,7 @@ GEM multi_json (~> 1) oauth2 (~> 0.9.1) rest-client (~> 1.6.7) - wunderground (1.1.0) + wunderground (1.2.0) addressable httparty (> 0.6.0) json (> 1.4.0) @@ -321,16 +321,16 @@ DEPENDENCIES em-http-request (~> 1.1.2) forecast_io (~> 2.0.0) foreman (~> 0.63.0) - geokit (~> 1.6.7) - geokit-rails (~> 2.0.0) + geokit (~> 1.8.4) + geokit-rails (~> 2.0.1) hipchat (~> 1.1.0) - jquery-rails (~> 3.0.4) + jquery-rails (~> 3.1.0) json (~> 1.8.1) jsonpath (~> 0.5.3) - kaminari (~> 0.14.1) - kramdown (~> 1.1.0) - mysql2 (~> 0.3.13) - nokogiri (~> 1.6.0) + kaminari (~> 0.15.1) + kramdown (~> 1.3.3) + mysql2 (~> 0.3.15) + nokogiri (~> 1.6.1) protected_attributes (~> 1.0.7) pry rails (= 4.1.0) @@ -351,4 +351,4 @@ DEPENDENCIES uglifier (>= 1.3.0) webmock weibo_2 (~> 0.1.4) - wunderground (~> 1.1.0) + wunderground (~> 1.2.0) diff --git a/app/views/layouts/_messages.html.erb b/app/views/layouts/_messages.html.erb index 08930433..15cdc388 100644 --- a/app/views/layouts/_messages.html.erb +++ b/app/views/layouts/_messages.html.erb @@ -1,7 +1,7 @@ <% if flash.keys.length > 0 %>
<% flash.each do |name, msg| %> -
"> +
"> × <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
From 460e940c8a65a404a8d50d27f61e4edb5d2aa40f Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Sun, 20 Apr 2014 00:00:55 +0200 Subject: [PATCH 3/3] Removed unneeded config options, added gemnasium --- .env.example | 1 - README.md | 2 +- config/application.rb | 3 --- config/environments/production.rb | 3 --- config/initializers/devise.rb | 5 ----- 5 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.env.example b/.env.example index fb0747bc..cc04f047 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,6 @@ # Replace the following with the output from "rake secret" APP_SECRET_TOKEN=REPLACE_ME_NOW! -DEVISE_SECRET_TOKEN=REPLACE_ME_NOW! # This is the domain where your Huginn instance will be running. The default should work # for development, but it needs to be changed to your Huginn domain when you deploy to a diff --git a/README.md b/README.md index b815ad35..2f4f1636 100644 --- a/README.md +++ b/README.md @@ -104,5 +104,5 @@ Huginn is a work in progress and is hopefully just getting started. Please get Please fork, add specs, and send pull requests! -[![Build Status](https://travis-ci.org/cantino/huginn.png)](https://travis-ci.org/cantino/huginn) [![Coverage Status](https://coveralls.io/repos/cantino/huginn/badge.png)](https://coveralls.io/r/cantino/huginn) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/cantino/huginn/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![Build Status](https://travis-ci.org/cantino/huginn.png)](https://travis-ci.org/cantino/huginn) [![Coverage Status](https://coveralls.io/repos/cantino/huginn/badge.png)](https://coveralls.io/r/cantino/huginn) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/cantino/huginn/trend.png)](https://bitdeli.com/free "Bitdeli Badge") [![Dependency Status](https://gemnasium.com/cantino/huginn.svg)](https://gemnasium.com/cantino/huginn) diff --git a/config/application.rb b/config/application.rb index 00081131..aa4e45be 100644 --- a/config/application.rb +++ b/config/application.rb @@ -47,8 +47,5 @@ module Huginn # Enable the asset pipeline config.assets.enabled = true config.assets.initialize_on_precompile = false - - # Version of your assets, change this if you want to expire all your assets - config.assets.version = '1.0' end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 076b8c24..ca2bb1ff 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -32,9 +32,6 @@ Huginn::Application.configure do # Generate digests for assets URLs config.assets.digest = true - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ac32d00e..ddea7f6b 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,11 +1,6 @@ # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| - # The secret key used by Devise. Devise uses this key to generate - # random tokens. Changing this key will render invalid all existing - # confirmation, reset password and unlock tokens in the database. - config.secret_key = ENV['DEVISE_SECRET_TOKEN'] - # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class