From 85f6e5aef8aef2f34b08e4c9e0020bda0e6c3ebf Mon Sep 17 00:00:00 2001 From: simukappu Date: Sat, 16 Jul 2016 12:39:52 +0900 Subject: [PATCH] Add initial rspec tests --- .coveralls.yml | 1 + .gitignore | 6 + .rspec | 3 + .travis.yml | 28 ++ Gemfile | 12 +- Gemfile.lock | 171 +++++++++++ README.md | 2 +- activity_notification.gemspec | 7 +- lib/activity_notification.rb | 4 +- spec/factories/articles.rb | 5 + spec/factories/notifications.rb | 7 + spec/factories/users.rb | 4 + spec/models/notification_spec.rb | 38 +++ spec/rails_app/Rakefile | 6 + .../app/controllers/application_controller.rb | 5 + spec/rails_app/app/controllers/concerns/.keep | 0 .../app/helpers/application_helper.rb | 2 + spec/rails_app/app/mailers/.keep | 0 spec/rails_app/app/models/.keep | 0 spec/rails_app/app/models/article.rb | 15 + spec/rails_app/app/models/comment.rb | 21 ++ spec/rails_app/app/models/concerns/.keep | 0 spec/rails_app/app/models/user.rb | 7 + .../app/views/layouts/application.html.erb | 14 + spec/rails_app/bin/bundle | 3 + spec/rails_app/bin/rails | 4 + spec/rails_app/bin/rake | 4 + spec/rails_app/bin/setup | 29 ++ spec/rails_app/config.ru | 4 + spec/rails_app/config/application.rb | 20 ++ spec/rails_app/config/boot.rb | 5 + spec/rails_app/config/database.yml | 25 ++ spec/rails_app/config/environment.rb | 12 + .../config/environments/development.rb | 44 +++ .../config/environments/production.rb | 79 +++++ spec/rails_app/config/environments/test.rb | 42 +++ spec/rails_app/config/initializers/assets.rb | 11 + .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/cookies_serializer.rb | 3 + spec/rails_app/config/initializers/devise.rb | 274 ++++++++++++++++++ .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 + .../config/initializers/mime_types.rb | 4 + .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 + spec/rails_app/config/routes.rb | 56 ++++ spec/rails_app/config/secrets.yml | 22 ++ .../20160715050420_create_notifications.rb | 18 ++ .../20160715050433_create_test_tables.rb | 36 +++ spec/rails_app/db/schema.rb | 73 +++++ spec/rails_app/public/404.html | 67 +++++ spec/rails_app/public/422.html | 67 +++++ spec/rails_app/public/500.html | 66 +++++ spec/rails_app/public/favicon.ico | 0 spec/spec_helper.rb | 32 ++ 55 files changed, 1387 insertions(+), 15 deletions(-) create mode 100644 .coveralls.yml create mode 100644 .rspec create mode 100644 .travis.yml create mode 100644 Gemfile.lock create mode 100644 spec/factories/articles.rb create mode 100644 spec/factories/notifications.rb create mode 100644 spec/factories/users.rb create mode 100644 spec/models/notification_spec.rb create mode 100644 spec/rails_app/Rakefile create mode 100644 spec/rails_app/app/controllers/application_controller.rb create mode 100644 spec/rails_app/app/controllers/concerns/.keep create mode 100644 spec/rails_app/app/helpers/application_helper.rb create mode 100644 spec/rails_app/app/mailers/.keep create mode 100644 spec/rails_app/app/models/.keep create mode 100644 spec/rails_app/app/models/article.rb create mode 100644 spec/rails_app/app/models/comment.rb create mode 100644 spec/rails_app/app/models/concerns/.keep create mode 100644 spec/rails_app/app/models/user.rb create mode 100644 spec/rails_app/app/views/layouts/application.html.erb create mode 100755 spec/rails_app/bin/bundle create mode 100755 spec/rails_app/bin/rails create mode 100755 spec/rails_app/bin/rake create mode 100755 spec/rails_app/bin/setup create mode 100644 spec/rails_app/config.ru create mode 100644 spec/rails_app/config/application.rb create mode 100644 spec/rails_app/config/boot.rb create mode 100644 spec/rails_app/config/database.yml create mode 100644 spec/rails_app/config/environment.rb create mode 100644 spec/rails_app/config/environments/development.rb create mode 100644 spec/rails_app/config/environments/production.rb create mode 100644 spec/rails_app/config/environments/test.rb create mode 100644 spec/rails_app/config/initializers/assets.rb create mode 100644 spec/rails_app/config/initializers/backtrace_silencers.rb create mode 100644 spec/rails_app/config/initializers/cookies_serializer.rb create mode 100644 spec/rails_app/config/initializers/devise.rb create mode 100644 spec/rails_app/config/initializers/filter_parameter_logging.rb create mode 100644 spec/rails_app/config/initializers/inflections.rb create mode 100644 spec/rails_app/config/initializers/mime_types.rb create mode 100644 spec/rails_app/config/initializers/session_store.rb create mode 100644 spec/rails_app/config/initializers/wrap_parameters.rb create mode 100644 spec/rails_app/config/routes.rb create mode 100644 spec/rails_app/config/secrets.yml create mode 100644 spec/rails_app/db/migrate/20160715050420_create_notifications.rb create mode 100644 spec/rails_app/db/migrate/20160715050433_create_test_tables.rb create mode 100644 spec/rails_app/db/schema.rb create mode 100644 spec/rails_app/public/404.html create mode 100644 spec/rails_app/public/422.html create mode 100644 spec/rails_app/public/500.html create mode 100644 spec/rails_app/public/favicon.ico create mode 100644 spec/spec_helper.rb diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 00000000..91600595 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +service_name: travis-ci diff --git a/.gitignore b/.gitignore index 2cddba32..ab2da131 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,12 @@ /pkg/ /spec/reports/ /spec/examples.txt +/spec/rails_app/log/* +/spec/rails_app/tmp/* /test/tmp/ /test/version_tmp/ /tmp/ +/log/ # Used by dotenv library to load environment variables. # .env @@ -49,4 +52,7 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +*~ +coverage/* +*.sqlite3 .project diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..43ae2036 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--require spec_helper +--format documentation diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ddb02bf0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +language: ruby + +rvm: + - 2.1.9 + - 2.2.5 + - 2.3.1 + - ruby-head + +gemfile: + - Gemfile + +matrix: + allow_failures: + - rvm: ruby-head + fast_finish: true + +sudo: false + +cache: bundler + +before_install: "rm ${BUNDLE_GEMFILE}.lock" + +before_script: "bundle update" + +script: bundle exec rspec + +notifications: + email: true diff --git a/Gemfile b/Gemfile index 2c4b8ecc..c5f0b68a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,5 @@ source 'https://rubygems.org' -# Declare your gem's dependencies in activity_notification.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. gemspec -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. - -# To use a debugger -# gem 'byebug', group: [:development, :test] - +gem 'coveralls', require: false, group: :test diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..f90d2b9a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,171 @@ +PATH + remote: . + specs: + activity_notification (0.0.2) + activerecord (>= 3.0) + rails (~> 4.2.5) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.7) + actionview (= 4.2.7) + activesupport (= 4.2.7) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.7) + activesupport (= 4.2.7) + globalid (>= 0.3.0) + activemodel (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + activerecord (4.2.7) + activemodel (= 4.2.7) + activesupport (= 4.2.7) + arel (~> 6.0) + activesupport (4.2.7) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.3) + bcrypt (3.1.11) + builder (3.2.2) + concurrent-ruby (1.0.2) + coveralls (0.8.14) + json (>= 1.8, < 3) + simplecov (~> 0.12.0) + term-ansicolor (~> 1.3) + thor (~> 0.19.1) + tins (~> 1.6.0) + devise (4.2.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) + diff-lcs (1.2.5) + docile (1.1.5) + erubis (2.7.0) + factory_girl (4.7.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.7.0) + factory_girl (~> 4.7.0) + railties (>= 3.0.0) + globalid (0.3.6) + activesupport (>= 4.1.0) + i18n (0.7.0) + json (1.8.3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.0) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + orm_adapter (0.5.0) + pkg-config (1.1.7) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.7) + actionmailer (= 4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + activemodel (= 4.2.7) + activerecord (= 4.2.7) + activesupport (= 4.2.7) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.7) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.7) + actionpack (= 4.2.7) + activesupport (= 4.2.7) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.2.2) + responders (2.2.0) + railties (>= 4.2.0, < 5.1) + rspec-core (3.5.1) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-rails (3.5.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + simplecov (0.12.0) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + sprockets (3.6.3) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.1.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.11) + term-ansicolor (1.3.2) + tins (~> 1.0) + thor (0.19.1) + thread_safe (0.3.5) + tins (1.6.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + warden (1.2.6) + rack (>= 1.0) + +PLATFORMS + ruby + +DEPENDENCIES + activity_notification! + coveralls + devise + factory_girl_rails + rspec-rails + simplecov + sqlite3 + +BUNDLED WITH + 1.12.5 diff --git a/README.md b/README.md index ff5d7534..ae3767a9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ActivityNotification -Build Status is under construction +[![Code Climate](https://codeclimate.com/github/simukappu/activity_notification/badges/gpa.svg)](https://codeclimate.com/github/simukappu/activity_notification) `activity_notification` provides integrated user activity notifications for Rails. You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc. diff --git a/activity_notification.gemspec b/activity_notification.gemspec index 0c20e02a..77b0aeee 100644 --- a/activity_notification.gemspec +++ b/activity_notification.gemspec @@ -15,10 +15,15 @@ Gem::Specification.new do |s| s.description = "Integrated user activity notifications for Rails. Provides functions to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc." s.license = "MIT" - s.files = Dir["{lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.files = Dir["{lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.test_files = Dir["spec/**/*"] s.add_dependency "rails", "~> 4.2.5" s.add_dependency 'activerecord', '>= 3.0' + s.add_development_dependency 'sqlite3' + s.add_development_dependency "rspec-rails" + s.add_development_dependency "factory_girl_rails" + s.add_development_dependency 'simplecov' s.add_development_dependency "devise" end diff --git a/lib/activity_notification.rb b/lib/activity_notification.rb index d8eac3ae..d291abfe 100644 --- a/lib/activity_notification.rb +++ b/lib/activity_notification.rb @@ -1,6 +1,6 @@ require 'rails' -#require 'active_support' -#require 'action_view' +require 'active_support' +require 'action_view' module ActivityNotification extend ActiveSupport::Concern diff --git a/spec/factories/articles.rb b/spec/factories/articles.rb new file mode 100644 index 00000000..7c5c8eec --- /dev/null +++ b/spec/factories/articles.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :article do + user + end +end diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb new file mode 100644 index 00000000..f581bcae --- /dev/null +++ b/spec/factories/notifications.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :notification, class: ActivityNotification::Notification do + association :target, factory: :user + association :notifiable, factory: :article + key "default.default" + end +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 00000000..c81bd3a7 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,4 @@ +FactoryGirl.define do + factory :user do + end +end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb new file mode 100644 index 00000000..8608e2e2 --- /dev/null +++ b/spec/models/notification_spec.rb @@ -0,0 +1,38 @@ +RSpec.describe ActivityNotification::Notification, type: :model do + + # --- Validation --- + describe "with validation" do + before { @notification = build(:notification) } + + it "is valid with target, notifiable and key" do + expect(@notification).to be_valid + end + + it "is invalid with blank target" do + @notification.target = nil + expect(@notification).to be_invalid + expect(@notification.errors[:target].size).to eq(1) + end + + it "is invalid with blank notifiable" do + @notification.notifiable = nil + expect(@notification).to be_invalid + expect(@notification.errors[:notifiable].size).to eq(1) + end + + it "is invalid with blank key" do + @notification.key = nil + expect(@notification).to be_invalid + expect(@notification.errors[:key].size).to eq(1) + end + end + + describe "with association" do + it "belongs to notification as group_owner" do + group_owner = create(:notification, group_owner: nil) + group_member = create(:notification, group_owner: group_owner) + expect(group_member.group_owner).to eq(group_owner) + end + end + +end diff --git a/spec/rails_app/Rakefile b/spec/rails_app/Rakefile new file mode 100644 index 00000000..ba6b733d --- /dev/null +++ b/spec/rails_app/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/spec/rails_app/app/controllers/application_controller.rb b/spec/rails_app/app/controllers/application_controller.rb new file mode 100644 index 00000000..d83690e1 --- /dev/null +++ b/spec/rails_app/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/spec/rails_app/app/controllers/concerns/.keep b/spec/rails_app/app/controllers/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/rails_app/app/helpers/application_helper.rb b/spec/rails_app/app/helpers/application_helper.rb new file mode 100644 index 00000000..de6be794 --- /dev/null +++ b/spec/rails_app/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/rails_app/app/mailers/.keep b/spec/rails_app/app/mailers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/rails_app/app/models/.keep b/spec/rails_app/app/models/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/rails_app/app/models/article.rb b/spec/rails_app/app/models/article.rb new file mode 100644 index 00000000..5d057180 --- /dev/null +++ b/spec/rails_app/app/models/article.rb @@ -0,0 +1,15 @@ +class Article < ActiveRecord::Base + include ActivityNotification::Notifiable + acts_as_notifiable :users, + targets: ->(issue, key) { + [user] + }, + notifier: :user, + email_allowed: ->(article, target_user, key) { + true + }#, + #notifiable_path: ->(article) { concept_issue_path(issue.concept, issue) } + + belongs_to :user + has_many :comments, dependent: :delete_all +end diff --git a/spec/rails_app/app/models/comment.rb b/spec/rails_app/app/models/comment.rb new file mode 100644 index 00000000..665bb236 --- /dev/null +++ b/spec/rails_app/app/models/comment.rb @@ -0,0 +1,21 @@ +class Comment < ActiveRecord::Base + belongs_to :article + belongs_to :user + + include ActivityNotification::Notifiable + acts_as_notifiable :users, + targets: :custom_notification_users, + group: :article, + notifier: :user, + email_allowed: :custom_notification_email_to_users_allowed?#, + #notifiable_path: :custom_notifiable_path + + def custom_notification_users(key) + User.where(id: self.article.comments.pluck(:user_id)) + end + + def custom_notification_email_to_users_allowed?(user, key) + true + end + +end diff --git a/spec/rails_app/app/models/concerns/.keep b/spec/rails_app/app/models/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/spec/rails_app/app/models/user.rb b/spec/rails_app/app/models/user.rb new file mode 100644 index 00000000..523b2a57 --- /dev/null +++ b/spec/rails_app/app/models/user.rb @@ -0,0 +1,7 @@ +class User < ActiveRecord::Base + # devise :database_authenticatable, :registerable, :confirmable + + include ActivityNotification::Target + acts_as_target email: :email, email_allowed: :confirmed_at + +end diff --git a/spec/rails_app/app/views/layouts/application.html.erb b/spec/rails_app/app/views/layouts/application.html.erb new file mode 100644 index 00000000..593a778b --- /dev/null +++ b/spec/rails_app/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/spec/rails_app/bin/bundle b/spec/rails_app/bin/bundle new file mode 100755 index 00000000..66e9889e --- /dev/null +++ b/spec/rails_app/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/spec/rails_app/bin/rails b/spec/rails_app/bin/rails new file mode 100755 index 00000000..5191e692 --- /dev/null +++ b/spec/rails_app/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/spec/rails_app/bin/rake b/spec/rails_app/bin/rake new file mode 100755 index 00000000..17240489 --- /dev/null +++ b/spec/rails_app/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/spec/rails_app/bin/setup b/spec/rails_app/bin/setup new file mode 100755 index 00000000..acdb2c13 --- /dev/null +++ b/spec/rails_app/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/spec/rails_app/config.ru b/spec/rails_app/config.ru new file mode 100644 index 00000000..bd83b254 --- /dev/null +++ b/spec/rails_app/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb new file mode 100644 index 00000000..0c6acc5b --- /dev/null +++ b/spec/rails_app/config/application.rb @@ -0,0 +1,20 @@ +require File.expand_path('../boot', __FILE__) + +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "sprockets/railtie" +# require "rails/test_unit/railtie" + +Bundler.require(*Rails.groups) +require "activity_notification" + +module Dummy + class Application < Rails::Application + # Do not swallow errors in after_commit/after_rollback callbacks. + config.active_record.raise_in_transactional_callbacks = true + end +end + diff --git a/spec/rails_app/config/boot.rb b/spec/rails_app/config/boot.rb new file mode 100644 index 00000000..6266cfc5 --- /dev/null +++ b/spec/rails_app/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/rails_app/config/database.yml b/spec/rails_app/config/database.yml new file mode 100644 index 00000000..584a3592 --- /dev/null +++ b/spec/rails_app/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: ":memory:" + +production: + adapter: sqlite3 + database: ":memory:" diff --git a/spec/rails_app/config/environment.rb b/spec/rails_app/config/environment.rb new file mode 100644 index 00000000..612a23a4 --- /dev/null +++ b/spec/rails_app/config/environment.rb @@ -0,0 +1,12 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! + +# Load database schema +if Rails.env.test? + silence_stream(STDOUT) do + load "#{Rails.root}/db/schema.rb" + end +end \ No newline at end of file diff --git a/spec/rails_app/config/environments/development.rb b/spec/rails_app/config/environments/development.rb new file mode 100644 index 00000000..9a198b8a --- /dev/null +++ b/spec/rails_app/config/environments/development.rb @@ -0,0 +1,44 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # For devise and notification email + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } +end diff --git a/spec/rails_app/config/environments/production.rb b/spec/rails_app/config/environments/production.rb new file mode 100644 index 00000000..5c1b32e4 --- /dev/null +++ b/spec/rails_app/config/environments/production.rb @@ -0,0 +1,79 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # 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 serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # 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 + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # 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 cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # 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 +end diff --git a/spec/rails_app/config/environments/test.rb b/spec/rails_app/config/environments/test.rb new file mode 100644 index 00000000..1c19f08b --- /dev/null +++ b/spec/rails_app/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # 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 file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + 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 + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Randomize the order test cases are executed. + config.active_support.test_order = :random + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/spec/rails_app/config/initializers/assets.rb b/spec/rails_app/config/initializers/assets.rb new file mode 100644 index 00000000..01ef3e66 --- /dev/null +++ b/spec/rails_app/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/spec/rails_app/config/initializers/backtrace_silencers.rb b/spec/rails_app/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000..59385cdf --- /dev/null +++ b/spec/rails_app/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/rails_app/config/initializers/cookies_serializer.rb b/spec/rails_app/config/initializers/cookies_serializer.rb new file mode 100644 index 00000000..7f70458d --- /dev/null +++ b/spec/rails_app/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/rails_app/config/initializers/devise.rb b/spec/rails_app/config/initializers/devise.rb new file mode 100644 index 00000000..5ac1e66f --- /dev/null +++ b/spec/rails_app/config/initializers/devise.rb @@ -0,0 +1,274 @@ +# # 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. + # # Devise will use the `secret_key_base` as its `secret_key` + # # by default. You can change it below and use your own secret key. + # config.secret_key = 'e6f62a5ffa4bd32a1c36f12c77f3ba071e2f7de683ef0f20f91e0fe53fbf5eda4a8600800250460280a816d151fdab45fe044ef7f0dae0e18b5cac241cfebaef' +# + # # ==> 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. + # config.mailer_sender = 'please-change-me@example.com' +# + # # Configure the class responsible to send e-mails. + # # config.mailer = 'Devise::Mailer' +# + # # Configure the parent class responsible to send e-mails. + # # config.parent_mailer = 'ActionMailer::Base' +# + # # ==> ORM configuration + # # Load and configure the ORM. Supports :active_record (default) and + # # :mongoid (bson_ext recommended) by default. Other ORMs may be + # # available as additional gems. + # require 'devise/orm/active_record' +# + # # ==> Configuration for any authentication mechanism + # # Configure which keys are used when authenticating a user. The default is + # # just :email. You can configure it to use [:username, :subdomain], so for + # # authenticating a user, both parameters are required. Remember that those + # # parameters are used only when authenticating and not when retrieving from + # # session. If you need permissions, you should implement that in a before filter. + # # You can also supply a hash where the value is a boolean determining whether + # # or not authentication should be aborted when the value is not present. + # # config.authentication_keys = [:email] +# + # # Configure parameters from the request object used for authentication. Each entry + # # given should be a request method and it will automatically be passed to the + # # find_for_authentication method and considered in your model lookup. For instance, + # # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # # The same considerations mentioned for authentication_keys also apply to request_keys. + # # config.request_keys = [] +# + # # Configure which authentication keys should be case-insensitive. + # # These keys will be downcased upon creating or modifying a user and when used + # # to authenticate or find a user. Default is :email. + # config.case_insensitive_keys = [:email] +# + # # Configure which authentication keys should have whitespace stripped. + # # These keys will have whitespace before and after removed upon creating or + # # modifying a user and when used to authenticate or find a user. Default is :email. + # config.strip_whitespace_keys = [:email] +# + # # Tell if authentication through request.params is enabled. True by default. + # # It can be set to an array that will enable params authentication only for the + # # given strategies, for example, `config.params_authenticatable = [:database]` will + # # enable it only for database (email + password) authentication. + # # config.params_authenticatable = true +# + # # Tell if authentication through HTTP Auth is enabled. False by default. + # # It can be set to an array that will enable http authentication only for the + # # given strategies, for example, `config.http_authenticatable = [:database]` will + # # enable it only for database authentication. The supported strategies are: + # # :database = Support basic authentication with authentication key + password + # # config.http_authenticatable = false +# + # # If 401 status code should be returned for AJAX requests. True by default. + # # config.http_authenticatable_on_xhr = true +# + # # The realm used in Http Basic Authentication. 'Application' by default. + # # config.http_authentication_realm = 'Application' +# + # # It will change confirmation, password recovery and other workflows + # # to behave the same regardless if the e-mail provided was right or wrong. + # # Does not affect registerable. + # # config.paranoid = true +# + # # By default Devise will store the user in session. You can skip storage for + # # particular strategies by setting this option. + # # Notice that if you are skipping storage for all authentication paths, you + # # may want to disable generating routes to Devise's sessions controller by + # # 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 +# + # # When false, Devise will not attempt to reload routes on eager load. + # # This can reduce the time taken to boot the app but if your application + # # requires the Devise mappings to be loaded during boot time the application + # # won't boot properly. + # # config.reload_routes = true +# + # # ==> Configuration for :database_authenticatable + # # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # # using other algorithms, it sets how many times you want the password to be hashed. + # # + # # Limiting the stretches to just one in testing will increase the performance of + # # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # # a value less than 10 in other environments. Note that, for bcrypt (the default + # # algorithm), the cost increases exponentially with the number of stretches (e.g. + # # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + # config.stretches = Rails.env.test? ? 1 : 11 +# + # # Set up a pepper to generate the hashed password. + # # config.pepper = 'cd724b7dbe7ac7688f5fb620d26b1a305594f4f025e42c279524254dec22e7ff16a501a2d788ffe8d0365b5dc4ea7474c7e694585a8dd132d76887fe1fca7969' +# + # # Send a notification email when the user's password is changed + # # config.send_password_change_notification = false +# + # # ==> Configuration for :confirmable + # # A period that the user is allowed to access the website even without + # # confirming their account. For instance, if set to 2.days, the user will be + # # able to access the website for two days without confirming their account, + # # access will be blocked just in the third day. Default is 0.days, meaning + # # the user cannot access the website without confirming their account. + # # config.allow_unconfirmed_access_for = 2.days +# + # # A period that the user is allowed to confirm their account before their + # # token becomes invalid. For example, if set to 3.days, the user can confirm + # # their account within 3 days after the mail was sent, but on the fourth day + # # their account can't be confirmed with the token any more. + # # Default is nil, meaning there is no restriction on how long a user can take + # # before confirming their account. + # # config.confirm_within = 3.days +# + # # If true, requires any email changes to be confirmed (exactly the same way as + # # initial account confirmation) to be applied. Requires additional unconfirmed_email + # # db field (see migrations). Until confirmed, new email is stored in + # # unconfirmed_email column, and copied to email column on successful confirmation. + # config.reconfirmable = true +# + # # Defines which key will be used when confirming an account + # # config.confirmation_keys = [:email] +# + # # ==> Configuration for :rememberable + # # The time the user will be remembered without asking for credentials again. + # # config.remember_for = 2.weeks +# + # # Invalidates all the remember me tokens when the user signs out. + # config.expire_all_remember_me_on_sign_out = true +# + # # If true, extends the user's remember period when remembered via cookie. + # # config.extend_remember_period = false +# + # # Options to be passed to the created cookie. For instance, you can set + # # secure: true in order to force SSL only cookies. + # # config.rememberable_options = {} +# + # # ==> Configuration for :validatable + # # Range for password length. + # config.password_length = 6..128 +# + # # Email regex used to validate email formats. It simply asserts that + # # one (and only one) @ exists in the given string. This is mainly + # # to give user feedback and not to assert the e-mail validity. + # config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ +# + # # ==> Configuration for :timeoutable + # # The time you want to timeout the user session without activity. After this + # # time the user will be asked for credentials again. Default is 30 minutes. + # # config.timeout_in = 30.minutes +# + # # ==> Configuration for :lockable + # # Defines which strategy will be used to lock an account. + # # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # # :none = No lock strategy. You should handle locking by yourself. + # # config.lock_strategy = :failed_attempts +# + # # Defines which key will be used when locking and unlocking an account + # # config.unlock_keys = [:email] +# + # # Defines which strategy will be used to unlock an account. + # # :email = Sends an unlock link to the user email + # # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # # :both = Enables both strategies + # # :none = No unlock strategy. You should handle unlocking by yourself. + # # config.unlock_strategy = :both +# + # # Number of authentication tries before locking an account if lock_strategy + # # is failed attempts. + # # config.maximum_attempts = 20 +# + # # Time interval to unlock the account if :time is enabled as unlock_strategy. + # # config.unlock_in = 1.hour +# + # # Warn on the last attempt before the account is locked. + # # config.last_attempt_warning = true +# + # # ==> Configuration for :recoverable + # # + # # Defines which key will be used when recovering the password for an account + # # config.reset_password_keys = [:email] +# + # # Time interval you can reset your password with a reset password key. + # # Don't put a too small interval or your users won't have the time to + # # change their passwords. + # config.reset_password_within = 6.hours +# + # # When set to false, does not sign a user in automatically after their password is + # # reset. Defaults to true, so a user is signed in automatically after a reset. + # # config.sign_in_after_reset_password = true +# + # # ==> Configuration for :encryptable + # # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # # You can use :sha1, :sha512 or algorithms from others authentication tools as + # # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # # for default behavior) and :restful_authentication_sha1 (then you should set + # # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # # + # # Require the `devise-encryptable` gem when using anything other than bcrypt + # # config.encryptor = :sha512 +# + # # ==> 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 + # # are using only default views. + # # config.scoped_views = false +# + # # Configure the default scope given to Warden. By default it's the first + # # devise role declared in your routes (usually :user). + # # config.default_scope = :user +# + # # Set this configuration to false if you want /users/sign_out to sign out + # # only the current scope. By default, Devise signs out all scopes. + # # config.sign_out_all_scopes = true +# + # # ==> Navigation configuration + # # Lists the formats that should be treated as navigational. Formats like + # # :html, should redirect to the sign in page when the user does not have + # # access, but formats like :xml or :json, should return 401. + # # + # # If you have any extra navigational formats, like :iphone or :mobile, you + # # should add them to the navigational formats lists. + # # + # # The "*/*" below is required to match Internet Explorer requests. + # # config.navigational_formats = ['*/*', :html] +# + # # The default HTTP method used to sign out a resource. Default is :delete. + # config.sign_out_via = :delete +# + # # ==> OmniAuth + # # Add a new OmniAuth provider. Check the wiki for more information on setting + # # up on your models and hooks. + # # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' +# + # # ==> Warden configuration + # # If you want to use other strategies, that are not supported by Devise, or + # # change the failure app, you can configure them inside the config.warden block. + # # + # # config.warden do |manager| + # # manager.intercept_401 = false + # # manager.default_strategies(scope: :user).unshift :some_external_strategy + # # end +# + # # ==> Mountable engine configurations + # # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # # is mountable, there are some extra configurations to be taken into account. + # # The following options are available, assuming the engine is mounted as: + # # + # # mount MyEngine, at: '/my_engine' + # # + # # The router that invoked `devise_for`, in the example above, would be: + # # config.router_name = :my_engine + # # + # # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # # so you need to do it manually. For the users scope, it would be: + # # config.omniauth_path_prefix = '/my_engine/users/auth' +# end diff --git a/spec/rails_app/config/initializers/filter_parameter_logging.rb b/spec/rails_app/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..4a994e1e --- /dev/null +++ b/spec/rails_app/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/spec/rails_app/config/initializers/inflections.rb b/spec/rails_app/config/initializers/inflections.rb new file mode 100644 index 00000000..ac033bf9 --- /dev/null +++ b/spec/rails_app/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/spec/rails_app/config/initializers/mime_types.rb b/spec/rails_app/config/initializers/mime_types.rb new file mode 100644 index 00000000..dc189968 --- /dev/null +++ b/spec/rails_app/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/spec/rails_app/config/initializers/session_store.rb b/spec/rails_app/config/initializers/session_store.rb new file mode 100644 index 00000000..e766b67b --- /dev/null +++ b/spec/rails_app/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/spec/rails_app/config/initializers/wrap_parameters.rb b/spec/rails_app/config/initializers/wrap_parameters.rb new file mode 100644 index 00000000..33725e95 --- /dev/null +++ b/spec/rails_app/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# 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] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/spec/rails_app/config/routes.rb b/spec/rails_app/config/routes.rb new file mode 100644 index 00000000..3f66539d --- /dev/null +++ b/spec/rails_app/config/routes.rb @@ -0,0 +1,56 @@ +Rails.application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/spec/rails_app/config/secrets.yml b/spec/rails_app/config/secrets.yml new file mode 100644 index 00000000..f5138570 --- /dev/null +++ b/spec/rails_app/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# 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. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: cf071f78f72641debc53a32f3076fde13ef7c4502a09c2b2f11b2c541707592e333a1ed21fe4edae9e60f5238c5de18f09767a42c5354cdd00a4083e4a2a5fb0 + +test: + secret_key_base: e52716d27db86faf90fbbf4fe4374a8e0bf28ec083aefc1d241ffaa46dee5534ba8fe9482c5be37509766540091dc97a7f054af2920696b27d45bbd0f0d20000 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/spec/rails_app/db/migrate/20160715050420_create_notifications.rb b/spec/rails_app/db/migrate/20160715050420_create_notifications.rb new file mode 100644 index 00000000..f9bddd5d --- /dev/null +++ b/spec/rails_app/db/migrate/20160715050420_create_notifications.rb @@ -0,0 +1,18 @@ +# Migration responsible for creating a table with notifications +class CreateNotifications < ActiveRecord::Migration + # Create table + def change + create_table :notifications do |t| + t.belongs_to :target, polymorphic: true, index: true, null: false + t.belongs_to :notifiable, polymorphic: true, index: true, null: false + t.string :key , null: false + t.belongs_to :group, polymorphic: true, index: true + t.integer :group_owner_id , index: true + t.belongs_to :notifier, polymorphic: true, index: true + t.text :parameters + t.datetime :opened_at + + t.timestamps + end + end +end diff --git a/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb b/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb new file mode 100644 index 00000000..ed2a88e7 --- /dev/null +++ b/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb @@ -0,0 +1,36 @@ +class CreateTestTables < ActiveRecord::Migration + def change + create_table :users do |t| + # Devise + ## Database authenticatable + t.string :email, null: false, default: "", index: true, unique: true + t.string :encrypted_password, null: false, default: "" + + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + + # Apps + t.string :name + + t.timestamps + end + + create_table :articles do |t| + t.references :user, index: true + t.string :title + t.string :body + + t.timestamps + end + + create_table :comments do |t| + t.references :user, index: true + t.references :article, index: true + t.string :body + + t.timestamps + end + end +end diff --git a/spec/rails_app/db/schema.rb b/spec/rails_app/db/schema.rb new file mode 100644 index 00000000..daa57556 --- /dev/null +++ b/spec/rails_app/db/schema.rb @@ -0,0 +1,73 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20160715050433) do + + create_table "articles", force: :cascade do |t| + t.integer "user_id" + t.string "title" + t.string "body" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "articles", ["user_id"], name: "index_articles_on_user_id" + + create_table "comments", force: :cascade do |t| + t.integer "user_id" + t.integer "article_id" + t.string "body" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "comments", ["article_id"], name: "index_comments_on_article_id" + add_index "comments", ["user_id"], name: "index_comments_on_user_id" + + create_table "notifications", force: :cascade do |t| + t.integer "target_id", null: false + t.string "target_type", null: false + t.integer "notifiable_id", null: false + t.string "notifiable_type", null: false + t.string "key", null: false + t.integer "group_id" + t.string "group_type" + t.integer "group_owner_id" + t.integer "notifier_id" + t.string "notifier_type" + t.text "parameters" + t.datetime "opened_at" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "notifications", ["group_owner_id"], name: "index_notifications_on_group_owner_id" + add_index "notifications", ["group_type", "group_id"], name: "index_notifications_on_group_type_and_group_id" + add_index "notifications", ["notifiable_type", "notifiable_id"], name: "index_notifications_on_notifiable_type_and_notifiable_id" + add_index "notifications", ["notifier_type", "notifier_id"], name: "index_notifications_on_notifier_type_and_notifier_id" + add_index "notifications", ["target_type", "target_id"], name: "index_notifications_on_target_type_and_target_id" + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "users", ["email"], name: "index_users_on_email" + +end diff --git a/spec/rails_app/public/404.html b/spec/rails_app/public/404.html new file mode 100644 index 00000000..b612547f --- /dev/null +++ b/spec/rails_app/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/rails_app/public/422.html b/spec/rails_app/public/422.html new file mode 100644 index 00000000..a21f82b3 --- /dev/null +++ b/spec/rails_app/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/rails_app/public/500.html b/spec/rails_app/public/500.html new file mode 100644 index 00000000..061abc58 --- /dev/null +++ b/spec/rails_app/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/rails_app/public/favicon.ico b/spec/rails_app/public/favicon.ico new file mode 100644 index 00000000..e69de29b diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..5c556790 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,32 @@ +ENV["RAILS_ENV"] ||= "test" + +require 'bundler/setup' +Bundler.setup + +#TODO set environment +#if ENV['COV'] + require 'simplecov' + SimpleCov.start do + add_filter '/spec/' + end +#elsif ENV["TRAVIS"] # in Travis-CI + require 'coveralls' + Coveralls.wear! +#end + +#require 'rails' +#require 'rspec-rails' +require 'activity_notification' +require "rails_app/config/environment" +require 'factory_girl_rails' +#require 'devise' + +# For active record ORM +require 'active_record' + +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + config.before(:all) do + FactoryGirl.reload + end +end \ No newline at end of file