Skip to content

Commit

Permalink
Add initial rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simukappu committed Jul 16, 2016
1 parent c1500b9 commit 85f6e5a
Show file tree
Hide file tree
Showing 55 changed files with 1,387 additions and 15 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,4 +52,7 @@ build-iPhoneSimulator/
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

*~
coverage/*
*.sqlite3
.project
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--require spec_helper
--format documentation
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 1 addition & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
171 changes: 171 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
7 changes: 6 additions & 1 deletion activity_notification.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/activity_notification.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails'
#require 'active_support'
#require 'action_view'
require 'active_support'
require 'action_view'

module ActivityNotification
extend ActiveSupport::Concern
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :article do
user
end
end
7 changes: 7 additions & 0 deletions spec/factories/notifications.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryGirl.define do
factory :user do
end
end
38 changes: 38 additions & 0 deletions spec/models/notification_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/rails_app/Rakefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/rails_app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Empty file.
2 changes: 2 additions & 0 deletions spec/rails_app/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file.
Empty file added spec/rails_app/app/models/.keep
Empty file.
15 changes: 15 additions & 0 deletions spec/rails_app/app/models/article.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions spec/rails_app/app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -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
Empty file.
7 changes: 7 additions & 0 deletions spec/rails_app/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 85f6e5a

Please sign in to comment.