added 260907 version of worker toolkit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
require "rails_helper"
|
||||
require "cancan/matchers"
|
||||
|
||||
RSpec.describe Ability do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
subject { Ability.new(user) }
|
||||
|
||||
context "for conditions" do
|
||||
let!(:global_condition) { create(:condition) }
|
||||
let!(:personal_condition) { create(:user_condition, user: user).condition }
|
||||
let!(:another_user_condition) { create(:user_condition).condition }
|
||||
let!(:popular_condition) { create(:condition, :personal) }
|
||||
before { create_list(:user_condition, Flaredown.config.trackables_min_popularity, condition: popular_condition) }
|
||||
|
||||
context "index" do
|
||||
it "allow to index personal condition" do
|
||||
is_expected.to be_able_to(:index, personal_condition)
|
||||
end
|
||||
|
||||
it "allow to index global conditions" do
|
||||
is_expected.to be_able_to(:index, global_condition)
|
||||
end
|
||||
|
||||
it "don't allow to index another user's personal condition" do
|
||||
is_expected.not_to be_able_to(:index, another_user_condition)
|
||||
end
|
||||
end
|
||||
|
||||
context "show" do
|
||||
it "allow to show global conditions" do
|
||||
is_expected.to be_able_to(:show, global_condition)
|
||||
end
|
||||
it "allow to show personal conditions" do
|
||||
is_expected.to be_able_to(:show, personal_condition)
|
||||
end
|
||||
it "allow to show popular conditions" do
|
||||
is_expected.to be_able_to(:show, popular_condition)
|
||||
end
|
||||
it "allow to show another user's personal condition" do
|
||||
is_expected.to be_able_to(:show, another_user_condition)
|
||||
end
|
||||
end
|
||||
|
||||
context "manage" do
|
||||
it "allow to manage user's personal conditions" do
|
||||
is_expected.to be_able_to(:manage, personal_condition)
|
||||
end
|
||||
it "don't allow to manage another user's personal conditions" do
|
||||
is_expected.not_to be_able_to(:manage, another_user_condition)
|
||||
end
|
||||
end
|
||||
|
||||
context "create" do
|
||||
let(:new_condition) { Condition.new(global: false) }
|
||||
let(:new_global_condition) { Condition.new }
|
||||
it "allow to create non-global conditions" do
|
||||
is_expected.to be_able_to(:create, new_condition)
|
||||
end
|
||||
it "don't allow to create global conditions" do
|
||||
is_expected.not_to be_able_to(:create, new_global_condition)
|
||||
end
|
||||
end
|
||||
|
||||
context "popular conditions" do
|
||||
before { create_list(:user_condition, Flaredown.config.trackables_min_popularity, condition: popular_condition) }
|
||||
let(:popular_condition_ids) { Ability.new(user).send(:popular_trackable_ids, "Condition") }
|
||||
|
||||
it { expect(popular_condition_ids).to eq([popular_condition.id]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
require "rails_helper"
|
||||
require "cancan/matchers"
|
||||
|
||||
RSpec.describe Ability do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
subject { Ability.new(user) }
|
||||
|
||||
context "for foods" do
|
||||
let!(:global_food) { create(:food) }
|
||||
let!(:personal_food) { create(:user_food, user: user).food }
|
||||
let!(:another_user_food) { create(:user_food).food }
|
||||
let!(:popular_food) { create(:food, :personal) }
|
||||
|
||||
before { create_list(:user_food, Flaredown.config.trackables_min_popularity, food: popular_food) }
|
||||
|
||||
context "index" do
|
||||
it "allow to index personal food" do
|
||||
is_expected.to be_able_to(:index, personal_food)
|
||||
end
|
||||
it "allow to index global food" do
|
||||
is_expected.to be_able_to(:index, global_food)
|
||||
end
|
||||
it "don't allow to index another user's personal food" do
|
||||
is_expected.not_to be_able_to(:index, another_user_food)
|
||||
end
|
||||
end
|
||||
|
||||
context "show" do
|
||||
it "allow to show global food" do
|
||||
is_expected.to be_able_to(:show, global_food)
|
||||
end
|
||||
it "allow to show personal food" do
|
||||
is_expected.to be_able_to(:show, personal_food)
|
||||
end
|
||||
it "allow to show another user's personal food" do
|
||||
is_expected.to be_able_to(:show, another_user_food)
|
||||
end
|
||||
end
|
||||
|
||||
context "manage" do
|
||||
it "allow to manage user's personal food" do
|
||||
is_expected.to be_able_to(:manage, personal_food)
|
||||
end
|
||||
it "don't allow to manage another user's personal food" do
|
||||
is_expected.not_to be_able_to(:manage, another_user_food)
|
||||
end
|
||||
end
|
||||
|
||||
context "create" do
|
||||
let(:new_food) { Food.new(global: false) }
|
||||
let(:new_global_food) { Food.new }
|
||||
it "allow to create non-global food" do
|
||||
is_expected.to be_able_to(:create, new_food)
|
||||
end
|
||||
it "don't allow to create global food" do
|
||||
is_expected.not_to be_able_to(:create, new_global_food)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,72 @@
|
||||
require "rails_helper"
|
||||
require "cancan/matchers"
|
||||
|
||||
RSpec.describe Ability do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
subject { Ability.new(user) }
|
||||
|
||||
context "for symptoms" do
|
||||
let!(:global_symptom) { create(:symptom) }
|
||||
let!(:personal_symptom) { create(:user_symptom, user: user).symptom }
|
||||
let!(:another_user_symptom) { create(:user_symptom).symptom }
|
||||
let!(:popular_symptom) { create(:symptom, :personal) }
|
||||
before { create_list(:user_symptom, Flaredown.config.trackables_min_popularity, symptom: popular_symptom) }
|
||||
|
||||
context "index" do
|
||||
it "allow to index personal symptom" do
|
||||
is_expected.to be_able_to(:index, personal_symptom)
|
||||
end
|
||||
|
||||
it "allow to index global symptoms" do
|
||||
is_expected.to be_able_to(:index, global_symptom)
|
||||
end
|
||||
|
||||
it "don't allow to index another user's personal symptom" do
|
||||
is_expected.not_to be_able_to(:index, another_user_symptom)
|
||||
end
|
||||
end
|
||||
|
||||
context "show" do
|
||||
it "allow to show global symptoms" do
|
||||
is_expected.to be_able_to(:show, global_symptom)
|
||||
end
|
||||
it "allow to show personal symptoms" do
|
||||
is_expected.to be_able_to(:show, personal_symptom)
|
||||
end
|
||||
it "allow to show popular symptoms" do
|
||||
is_expected.to be_able_to(:show, popular_symptom)
|
||||
end
|
||||
it "allow to show another user's personal symptoms" do
|
||||
is_expected.to be_able_to(:show, another_user_symptom)
|
||||
end
|
||||
end
|
||||
|
||||
context "manage" do
|
||||
it "allow to manage user's personal symptoms" do
|
||||
is_expected.to be_able_to(:manage, personal_symptom)
|
||||
end
|
||||
it "don't allow to manage another user's personal symptoms" do
|
||||
is_expected.not_to be_able_to(:manage, another_user_symptom)
|
||||
end
|
||||
end
|
||||
|
||||
context "create" do
|
||||
let(:new_symptom) { Symptom.new(global: false) }
|
||||
let(:new_global_symptom) { Symptom.new }
|
||||
it "allow to create non-global symptoms" do
|
||||
is_expected.to be_able_to(:create, new_symptom)
|
||||
end
|
||||
it "don't allow to create global symptoms" do
|
||||
is_expected.not_to be_able_to(:create, new_global_symptom)
|
||||
end
|
||||
end
|
||||
|
||||
context "popular symptoms" do
|
||||
before { create_list(:user_symptom, Flaredown.config.trackables_min_popularity, symptom: popular_symptom) }
|
||||
let(:popular_symptom_ids) { Ability.new(user).send(:popular_trackable_ids, "Symptom") }
|
||||
|
||||
it { expect(popular_symptom_ids).to eq([popular_symptom.id]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
require "rails_helper"
|
||||
require "cancan/matchers"
|
||||
|
||||
RSpec.describe Ability do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
subject { Ability.new(user) }
|
||||
|
||||
context "for tags" do
|
||||
let!(:global_tag) { create(:tag) }
|
||||
let!(:personal_tag) { create(:user_tag, user: user).tag }
|
||||
let!(:another_user_tag) { create(:user_tag).tag }
|
||||
let!(:popular_tag) { create(:tag, :personal) }
|
||||
|
||||
before { create_list(:user_tag, Flaredown.config.trackables_min_popularity, tag: popular_tag) }
|
||||
|
||||
context "index" do
|
||||
it "allow to index personal tag" do
|
||||
is_expected.to be_able_to(:index, personal_tag)
|
||||
end
|
||||
it "allow to index global tag" do
|
||||
is_expected.to be_able_to(:index, global_tag)
|
||||
end
|
||||
it "don't allow to index another user's personal tag" do
|
||||
is_expected.not_to be_able_to(:index, another_user_tag)
|
||||
end
|
||||
end
|
||||
|
||||
context "show" do
|
||||
it "allow to show global tags" do
|
||||
is_expected.to be_able_to(:show, global_tag)
|
||||
end
|
||||
it "allow to show personal tag" do
|
||||
is_expected.to be_able_to(:show, personal_tag)
|
||||
end
|
||||
it "allow to show another user's personal tag" do
|
||||
is_expected.to be_able_to(:show, another_user_tag)
|
||||
end
|
||||
end
|
||||
|
||||
context "manage" do
|
||||
it "allow to manage user's personal tag" do
|
||||
is_expected.to be_able_to(:manage, personal_tag)
|
||||
end
|
||||
it "don't allow to manage another user's personal tag" do
|
||||
is_expected.not_to be_able_to(:manage, another_user_tag)
|
||||
end
|
||||
end
|
||||
|
||||
context "create" do
|
||||
let(:new_tag) { Tag.new(global: false) }
|
||||
let(:new_global_tag) { Tag.new }
|
||||
it "allow to create non-global tag" do
|
||||
is_expected.to be_able_to(:create, new_tag)
|
||||
end
|
||||
it "don't allow to create global tag" do
|
||||
is_expected.not_to be_able_to(:create, new_global_tag)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,72 @@
|
||||
require "rails_helper"
|
||||
require "cancan/matchers"
|
||||
|
||||
RSpec.describe Ability do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
subject { Ability.new(user) }
|
||||
|
||||
context "for treatments" do
|
||||
let!(:global_treatment) { create(:treatment) }
|
||||
let!(:personal_treatment) { create(:user_treatment, user: user).treatment }
|
||||
let!(:another_user_treatment) { create(:user_treatment).treatment }
|
||||
let!(:popular_treatment) { create(:treatment, :personal) }
|
||||
before { create_list(:user_treatment, Flaredown.config.trackables_min_popularity, treatment: popular_treatment) }
|
||||
|
||||
context "index" do
|
||||
it "allow to index personal treatments" do
|
||||
is_expected.to be_able_to(:index, personal_treatment)
|
||||
end
|
||||
|
||||
it "allow to index global treatments" do
|
||||
is_expected.to be_able_to(:index, global_treatment)
|
||||
end
|
||||
|
||||
it "don't allow to index another user's personal treatment" do
|
||||
is_expected.not_to be_able_to(:index, another_user_treatment)
|
||||
end
|
||||
end
|
||||
|
||||
context "show" do
|
||||
it "allow to show global treatments" do
|
||||
is_expected.to be_able_to(:show, global_treatment)
|
||||
end
|
||||
it "allow to show personal treatments" do
|
||||
is_expected.to be_able_to(:show, personal_treatment)
|
||||
end
|
||||
it "allow to show popular treatments" do
|
||||
is_expected.to be_able_to(:show, popular_treatment)
|
||||
end
|
||||
it "allow to show another user's personal treatments" do
|
||||
is_expected.to be_able_to(:show, another_user_treatment)
|
||||
end
|
||||
end
|
||||
|
||||
context "manage" do
|
||||
it "allow to manage user's personal treatments" do
|
||||
is_expected.to be_able_to(:manage, personal_treatment)
|
||||
end
|
||||
it "don't allow to manage another user's personal treatments" do
|
||||
is_expected.not_to be_able_to(:manage, another_user_treatment)
|
||||
end
|
||||
end
|
||||
|
||||
context "create" do
|
||||
let(:new_treatment) { Treatment.new(global: false) }
|
||||
let(:new_global_treatment) { Treatment.new }
|
||||
it "allow to create non-global treatments" do
|
||||
is_expected.to be_able_to(:create, new_treatment)
|
||||
end
|
||||
it "don't allow to create global treatments" do
|
||||
is_expected.not_to be_able_to(:create, new_global_treatment)
|
||||
end
|
||||
end
|
||||
|
||||
context "popular treatmnets" do
|
||||
before { create_list(:user_treatment, Flaredown.config.trackables_min_popularity, treatment: popular_treatment) }
|
||||
let(:popular_treatment_ids) { Ability.new(user).send(:popular_trackable_ids, "Treatment") }
|
||||
|
||||
it { expect(popular_treatment_ids).to eq([popular_treatment.id]) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Checkin::Condition, type: :model do
|
||||
include Mongoid::Matchers
|
||||
|
||||
it_behaves_like "fiveable"
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to belong_to(:checkin) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Checkin::Symptom, type: :model do
|
||||
include Mongoid::Matchers
|
||||
|
||||
it_behaves_like "fiveable"
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to belong_to(:checkin) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Checkin::Treatment, type: :model do
|
||||
include Mongoid::Matchers
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to belong_to(:checkin) }
|
||||
end
|
||||
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:value) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Checkin, type: :model do
|
||||
include Mongoid::Matchers
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to have_many(:conditions) }
|
||||
it { is_expected.to have_many(:symptoms) }
|
||||
it { is_expected.to have_many(:treatments) }
|
||||
it { is_expected.to have_one(:harvey_bradshaw_index) }
|
||||
it { is_expected.to have_one(:promotion_rate) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:date) }
|
||||
it { is_expected.to validate_presence_of(:encrypted_user_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Comment do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:body) }
|
||||
it { is_expected.to validate_presence_of(:encrypted_user_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: conditions
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# global :boolean default(TRUE)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# trackable_usages_count :integer default(0)
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Condition do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:name) }
|
||||
end
|
||||
|
||||
describe "Translations" do
|
||||
before { I18n.locale = locale }
|
||||
subject { create(:condition) }
|
||||
|
||||
context "with 'en' as current locale" do
|
||||
let(:locale) { :en }
|
||||
it "stores name with 'en' locale" do
|
||||
t = subject.translations.to_a
|
||||
expect(t.size).to eq 1
|
||||
expect(t[0].locale).to eq locale
|
||||
end
|
||||
end
|
||||
|
||||
context "with 'it' as current locale" do
|
||||
let(:locale) { :it }
|
||||
it "stores name with 'it' locale" do
|
||||
t = subject.translations.to_a
|
||||
expect(t.size).to eq 1
|
||||
expect(t[0].locale).to eq locale
|
||||
end
|
||||
end
|
||||
|
||||
after { I18n.locale = :en }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Food do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:long_desc) }
|
||||
it { is_expected.to respond_to(:shrt_desc) }
|
||||
it { is_expected.to respond_to(:comname) }
|
||||
it { is_expected.to respond_to(:sciname) }
|
||||
end
|
||||
|
||||
describe "class methods" do
|
||||
let!(:global_food) { create(:food, long_desc: "TestFood") }
|
||||
let!(:same_food_1) { create(:food, long_desc: "TestFood #{FFaker::Lorem.word}") }
|
||||
let!(:same_food_2) { create(:food, long_desc: "TestFood #{FFaker::Lorem.word}") }
|
||||
|
||||
let!(:personal_food) { create(:food, :personal, long_desc: "TestFood") }
|
||||
let!(:user_food) { create(:user_food, food: personal_food) }
|
||||
|
||||
let(:query) { {name: "TestFood"} }
|
||||
|
||||
MAX_ROWS = 2
|
||||
|
||||
describe "fts" do
|
||||
it "return same global foods" do
|
||||
another_user = create(:user)
|
||||
result = Food.send(:fts, query[:name], MAX_ROWS, another_user.id)
|
||||
|
||||
expect(result).to eq [global_food, same_food_1]
|
||||
expect(result.count).to eq MAX_ROWS
|
||||
expect(result.count).to_not eq Food.where(global: true).count
|
||||
expect(result.include?(personal_food)).to be false
|
||||
end
|
||||
|
||||
it "retrun local and global foods for author" do
|
||||
expect(Food.send(:fts, query[:name], MAX_ROWS, user_food.user_id)).to eq [global_food, personal_food]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe HarveyBradshawIndex do
|
||||
include Mongoid::Matchers
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to belong_to(:checkin) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:checkin) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:stools) }
|
||||
it { is_expected.to validate_presence_of(:well_being) }
|
||||
it { is_expected.to validate_presence_of(:abdominal_mass) }
|
||||
it { is_expected.to validate_presence_of(:abdominal_pain) }
|
||||
|
||||
it { is_expected.to validate_uniqueness_of(:checkin_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Notification do
|
||||
let(:alice) { create(:user) }
|
||||
let(:bob) { create(:user) }
|
||||
|
||||
let(:first_post) { create(:post) }
|
||||
let(:second_post) { create(:post) }
|
||||
|
||||
let(:comment_for_first_post) { create(:comment, post: first_post) }
|
||||
let(:comment_for_second_post) { create(:comment, post: second_post) }
|
||||
|
||||
context "#count_by_types" do
|
||||
it "should count all by kind" do
|
||||
# The following are valid possibilities for (kind, notificateable_type):
|
||||
# - ("comment", "Comment"): commenting on a post
|
||||
# - ("mention", "Comment"): users can only mention other users who have commented in a post
|
||||
# - ("reaction", "Post")
|
||||
# - ("reaction", "Comment")
|
||||
|
||||
alice_id = alice.encrypted_id
|
||||
bob_id = bob.encrypted_id
|
||||
|
||||
create(:notification, kind: "comment", notificateable: comment_for_first_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
create(:notification, kind: "comment", notificateable: comment_for_second_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
|
||||
create(:notification, kind: "mention", notificateable: comment_for_first_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
create(:notification, kind: "mention", notificateable: comment_for_second_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
|
||||
create(:notification, kind: "reaction", notificateable: first_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
create(:notification, kind: "reaction", notificateable: second_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
create(:notification, kind: "reaction", notificateable: comment_for_first_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
create(:notification, kind: "reaction", notificateable: comment_for_second_post, encrypted_user_id: alice_id, encrypted_notify_user_id: bob_id)
|
||||
|
||||
expect(Notification.all.count_by_types).to eq({
|
||||
"comment" => 2,
|
||||
"mention" => 2,
|
||||
"reaction" => 4
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Position do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:postal_code) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Post do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:body) }
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:encrypted_user_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: profiles
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# country_id :string
|
||||
# birth_date :date
|
||||
# sex_id :string
|
||||
# onboarding_step_id :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# ethnicity_ids_string :string
|
||||
# day_habit_id :string
|
||||
# education_level_id :string
|
||||
# day_walking_hours :integer
|
||||
# most_recent_doses :hstore
|
||||
# screen_name :string
|
||||
# most_recent_conditions_positions :hstore
|
||||
# most_recent_symptoms_positions :hstore
|
||||
# most_recent_treatments_positions :hstore
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Profile do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
end
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_inclusion_of(:country_id).in_array(Country.codes) }
|
||||
it { is_expected.to validate_inclusion_of(:sex_id).in_array(Sex.all_ids) }
|
||||
end
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:birth_date) }
|
||||
context "most recent trackables positions" do
|
||||
it { is_expected.to respond_to(:set_most_recent_trackable_position).with(2).arguments }
|
||||
it { is_expected.to respond_to(:most_recent_trackable_position_for).with(1).argument }
|
||||
it { is_expected.to respond_to(:set_most_recent_condition_position).with(2).arguments }
|
||||
it { is_expected.to respond_to(:most_recent_condition_position_for).with(1).argument }
|
||||
it { is_expected.to respond_to(:set_most_recent_symptom_position).with(2).arguments }
|
||||
it { is_expected.to respond_to(:most_recent_symptom_position_for).with(1).argument }
|
||||
it { is_expected.to respond_to(:set_most_recent_treatment_position).with(2).arguments }
|
||||
it { is_expected.to respond_to(:most_recent_treatment_position_for).with(1).argument }
|
||||
end
|
||||
end
|
||||
describe "ethnicities" do
|
||||
context "get" do
|
||||
before { subject.ethnicity_ids_string = "latino,white" }
|
||||
it "transforms to array" do
|
||||
expect(subject.ethnicity_ids).to eq %w[latino white]
|
||||
end
|
||||
end
|
||||
context "set" do
|
||||
before { subject.ethnicity_ids = %w[latino white] }
|
||||
it "transforms to string" do
|
||||
expect(subject.ethnicity_ids_string).to eq "latino,white"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe PromotionRate do
|
||||
include Mongoid::Matchers
|
||||
|
||||
describe "Relations" do
|
||||
it { is_expected.to belong_to(:checkin) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:checkin) }
|
||||
it { is_expected.to validate_uniqueness_of(:checkin_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
require "rails_helper"
|
||||
|
||||
class MockClassSkeleton < RankedEnum
|
||||
end
|
||||
|
||||
class MockClassOverride < RankedEnum
|
||||
class << self
|
||||
def all_ids
|
||||
%w[one two three]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.describe RankedEnum do
|
||||
describe MockClassSkeleton do
|
||||
it "yields all IDs associated with the class" do
|
||||
all_ids = MockClassSkeleton.all_ids
|
||||
|
||||
expect(all_ids).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
describe MockClassOverride do
|
||||
it "yields all IDs associated with the class" do
|
||||
all_ids = MockClassOverride.all_ids
|
||||
|
||||
expect(all_ids).to eq ["one", "two", "three"]
|
||||
end
|
||||
|
||||
it "searches for a specific ID" do
|
||||
searched_id = MockClassOverride.find("two")
|
||||
|
||||
expect(searched_id.id).to eq "two"
|
||||
end
|
||||
|
||||
# TODO: Actually make this test grab the cache
|
||||
it "prints out all IDs from cache" do
|
||||
all_ids = MockClassOverride.all
|
||||
|
||||
expect(all_ids.size).to eq 3
|
||||
expect(all_ids.last.id).to eq "three"
|
||||
end
|
||||
|
||||
it "creates a translatable name (that does not exist in the code base) for a ranked enum model instance" do
|
||||
mock = MockClassOverride.new("some-id", "some-rank")
|
||||
|
||||
expect(mock.name).to eq "Translation missing: en.mock_class_override.some-id"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Reaction do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:value) }
|
||||
it { is_expected.to validate_presence_of(:encrypted_user_id) }
|
||||
end
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:other_user) { create(:user) }
|
||||
|
||||
context "#values_count_with_participated" do
|
||||
it "should indicate counts and when the given user has already used the requested reaction" do
|
||||
reaction = create(:reaction, encrypted_user_id: user.encrypted_id, value: ":smile:")
|
||||
create(:reaction, encrypted_user_id: other_user.encrypted_id, value: ":smile:")
|
||||
create(:reaction, encrypted_user_id: other_user.encrypted_id, value: ":smirk:")
|
||||
|
||||
expect(subject.class.values_count_with_participated(user.encrypted_id)).to match_array([
|
||||
hash_including({
|
||||
# A real reaction ID is only required/meaningful when the current user has reacted.
|
||||
# Otherwise the value is meaningless.
|
||||
id: reaction.id.to_s,
|
||||
value: ":smile:",
|
||||
count: 2,
|
||||
participated: true
|
||||
}),
|
||||
hash_including({
|
||||
# id is not relevant here because the user did not react
|
||||
value: ":smirk:",
|
||||
count: 1,
|
||||
participated: false
|
||||
})
|
||||
])
|
||||
end
|
||||
|
||||
it "should work with a filtered set" do
|
||||
create(:reaction, encrypted_user_id: user.encrypted_id)
|
||||
create(:reaction, encrypted_user_id: other_user.encrypted_id)
|
||||
create(:reaction, encrypted_user_id: other_user.encrypted_id, value: ":smirk:")
|
||||
|
||||
filtered = Reaction.where(value: ":smirk:")
|
||||
|
||||
expect(filtered.values_count_with_participated(user.encrypted_id)).to match([
|
||||
hash_including({
|
||||
value: ":smirk:",
|
||||
count: 1,
|
||||
participated: false
|
||||
})
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Registration do
|
||||
subject { Registration.create!(params) }
|
||||
|
||||
let(:params) do
|
||||
ActionController::Parameters.new(
|
||||
registration: {
|
||||
email: "user@example.com",
|
||||
password: "secret123",
|
||||
password_confirmation: "secret123",
|
||||
screen_name: "user",
|
||||
captcha_response: "dummy-captcha-response"
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
before { allow(Google::RecaptchaVerifier).to receive(:exec).and_return(true) }
|
||||
|
||||
context "with blank screen_name" do
|
||||
before { params[:registration][:screen_name] = "" }
|
||||
it "raises record invalid exception with proper error" do
|
||||
expect { subject }.to raise_error do |e|
|
||||
expect(e).to be_a(ActiveRecord::RecordInvalid)
|
||||
expect(e.record.errors[:screen_name]).to eq ["can't be blank"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with blank captcha_response" do
|
||||
before { params[:registration][:captcha_response] = "" }
|
||||
it "raises record invalid exception with proper error" do
|
||||
expect { subject }.to raise_error do |e|
|
||||
expect(e).to be_a(ActiveRecord::RecordInvalid)
|
||||
expect(e.record.errors[:captcha_response]).to eq ["can't be blank"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid captcha_response" do
|
||||
before { allow(Google::RecaptchaVerifier).to receive(:exec).and_return(false) }
|
||||
it "raises record invalid exception with proper error" do
|
||||
expect { subject }.to raise_error do |e|
|
||||
expect(e).to be_a(ActiveRecord::RecordInvalid)
|
||||
expect(e.record.errors[:captcha_response]).to eq ["verification failed or response expired"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with blank email" do
|
||||
before { params[:registration][:email] = "" }
|
||||
it "raises record invalid exception with proper error" do
|
||||
expect { subject }.to raise_error do |e|
|
||||
expect(e).to be_a(ActiveRecord::RecordInvalid)
|
||||
expect(e.record.errors[:email]).to eq ["can't be blank"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with blank password" do
|
||||
before { params[:registration][:password] = "" }
|
||||
it "raises record invalid exception with proper error" do
|
||||
expect { subject }.to raise_error do |e|
|
||||
expect(e).to be_a(ActiveRecord::RecordInvalid)
|
||||
expect(e.record.errors[:password]).to eq ["can't be blank"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with all valid params" do
|
||||
it "returns registration object wrapping new user created" do
|
||||
user = subject.user
|
||||
expect(user).to be_a User
|
||||
expect(user.email).to eq params[:registration][:email]
|
||||
expect(user.profile.screen_name).to eq params[:registration][:screen_name]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,38 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Search::ForDose, type: :model do
|
||||
let!(:checkins) { create_list(:checkin, 3) }
|
||||
let!(:treatment) { create(:checkin_treatment, checkin: checkins[0], is_taken: true, value: "2 x 10 mg") }
|
||||
let(:all_treatment_doses) { [treatment.value] + [other_dose_1.value, other_dose_2.value] }
|
||||
let(:params) { {resource: "dose", query: {treatment_id: treatment.treatment_id, name: "2 x"}} }
|
||||
|
||||
let!(:other_dose_1) do
|
||||
create(:checkin_treatment, checkin: checkins[1], is_taken: true, treatment_id: treatment.treatment_id)
|
||||
end
|
||||
|
||||
let!(:other_dose_2) do
|
||||
create(:checkin_treatment, checkin: checkins[2], is_taken: true, treatment_id: treatment.treatment_id)
|
||||
end
|
||||
|
||||
subject { Search::ForDose.new(params) }
|
||||
|
||||
context "without treatment_id param" do
|
||||
before { params[:query].delete(:treatment_id) }
|
||||
it { is_expected.not_to be_valid }
|
||||
end
|
||||
|
||||
context "without name param" do
|
||||
before { params[:query].delete(:name) }
|
||||
it "returns all doses for the requested treatment" do
|
||||
returned_doses = subject.searchables.map(&:name)
|
||||
expect(returned_doses.to_set).to eq all_treatment_doses.compact.to_set
|
||||
end
|
||||
end
|
||||
|
||||
context "with name param" do
|
||||
it "returns matching doses for the requested treatment" do
|
||||
returned_doses = subject.searchables.map(&:name)
|
||||
expect(returned_doses).to include treatment.value
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Search, type: :model do
|
||||
let(:user) { create(:user) }
|
||||
let(:treatment) { create(:user_treatment, user: user).treatment }
|
||||
let(:query) { {name: "terra"} }
|
||||
|
||||
before { treatment.update!(name: "Mediterranean Diet") }
|
||||
|
||||
subject { Search.new(resource: "treatment", query: query, user: user) }
|
||||
|
||||
context "success" do
|
||||
context "when search text is more than 3 characters" do
|
||||
it "returns string containing search text" do
|
||||
returned_treatment_names = subject.searchables.map(&:name)
|
||||
expect(returned_treatment_names).to include treatment.name
|
||||
end
|
||||
end
|
||||
|
||||
context "when search text is less than 3 characters" do
|
||||
before { query[:name] = "me" }
|
||||
|
||||
it "returns string starting with search text" do
|
||||
returned_treatment_names = subject.searchables.map(&:name)
|
||||
expect(returned_treatment_names).to include treatment.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "failure" do
|
||||
context "when search text is more than 3 characters" do
|
||||
before { query[:name] = "teran" }
|
||||
|
||||
it "returns no results" do
|
||||
expect(subject.searchables).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "when search text is less than 3 characters" do
|
||||
before { query[:name] = "te" }
|
||||
it "returns no results" do
|
||||
expect(subject.searchables).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: symptoms
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# global :boolean default(TRUE)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# trackable_usages_count :integer default(0)
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Symptom, type: :model do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:name) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: tags
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Tag, type: :model do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:name) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe TopicFollowing do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:encrypted_user_id) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: trackable_usages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# trackable_id :integer
|
||||
# trackable_type :string
|
||||
# count :integer default(1)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe TrackableUsage, type: :model do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:count) }
|
||||
end
|
||||
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:trackable) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_numericality_of(:count).is_greater_than(0) }
|
||||
end
|
||||
|
||||
describe "Callbacks" do
|
||||
before(:all) do
|
||||
@condition = create(:condition, :personal)
|
||||
create_list(:trackable_usage,
|
||||
Flaredown.config.trackables_min_popularity - 1,
|
||||
trackable_type: @condition.class.to_s,
|
||||
trackable_id: @condition.id)
|
||||
end
|
||||
|
||||
subject { TrackableUsage.last }
|
||||
|
||||
context "for small amount of tracks doesn't switch topic to global" do
|
||||
before(:each) { subject.run_callbacks(:commit) }
|
||||
|
||||
it { expect(subject.trackable.reload.global?).to be false }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,72 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: trackings
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# trackable_id :integer
|
||||
# trackable_type :string
|
||||
# start_at :date
|
||||
# end_at :date
|
||||
# color_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Tracking, type: :model do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:start_at) }
|
||||
it { is_expected.to validate_presence_of(:user) }
|
||||
it { is_expected.to validate_presence_of(:trackable) }
|
||||
it { is_expected.to validate_inclusion_of(:trackable_type).in_array(%w[Condition Symptom Treatment]) }
|
||||
|
||||
context "without foreign key checks" do
|
||||
subject { create :tracking, :for_condition, :active }
|
||||
|
||||
before { disable_foreign_key_checks("trackings") }
|
||||
after { enable_foreign_key_checks("trackings") }
|
||||
|
||||
it do
|
||||
is_expected.to(
|
||||
validate_uniqueness_of(:user_id)
|
||||
.scoped_to([:trackable_id, :trackable_type, :start_at])
|
||||
.with_message("is already tracking this trackable")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "ensure_color_id" do
|
||||
context "when have a parent" do
|
||||
let(:parent) { create(:tracking, :for_condition, :inactive) }
|
||||
|
||||
subject { create(:tracking, :active, trackable: parent.trackable, user: parent.user) }
|
||||
|
||||
it "has the same color previous Tracking" do
|
||||
expect(subject.color_id).to be_equal(parent.color_id)
|
||||
end
|
||||
end
|
||||
|
||||
context "when have a nil color" do
|
||||
subject { create(:tracking, :active, :for_condition) }
|
||||
|
||||
it "has the random color" do
|
||||
expect(subject.color_id).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "when have a color" do
|
||||
subject { create(:tracking, :active, :for_condition, color_id: 10) }
|
||||
|
||||
it "has the assigned color" do
|
||||
expect(subject.color_id).to be_equal(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: treatments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# global :boolean default(TRUE)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# trackable_usages_count :integer default(0)
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Treatment, type: :model do
|
||||
describe "Respond to" do
|
||||
it { is_expected.to respond_to(:name) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: user_conditions
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# condition_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe UserCondition do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:condition) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,71 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# email :string default(""), not null
|
||||
# encrypted_password :string default(""), not null
|
||||
# reset_password_token :string
|
||||
# reset_password_sent_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# sign_in_count :integer default(0), not null
|
||||
# current_sign_in_at :datetime
|
||||
# last_sign_in_at :datetime
|
||||
# current_sign_in_ip :string
|
||||
# last_sign_in_ip :string
|
||||
# authentication_token :string not null
|
||||
# invitation_token :string
|
||||
# invitation_created_at :datetime
|
||||
# invitation_sent_at :datetime
|
||||
# invitation_accepted_at :datetime
|
||||
# invitation_limit :integer
|
||||
# invited_by_id :integer
|
||||
# invited_by_type :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe User do
|
||||
describe "Associations" do
|
||||
it { is_expected.to have_one(:profile) }
|
||||
it { is_expected.to have_many(:conditions).through(:user_conditions) }
|
||||
it { is_expected.to have_many(:symptoms).through(:user_symptoms) }
|
||||
end
|
||||
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_presence_of(:email) }
|
||||
it { is_expected.to validate_presence_of(:password) }
|
||||
end
|
||||
|
||||
describe "Callbacks" do
|
||||
subject { create(:user) }
|
||||
context "before_create" do
|
||||
it "generates authentication token" do
|
||||
expect(subject.reload.authentication_token).to be_present
|
||||
end
|
||||
end
|
||||
context "after_create" do
|
||||
it "creates profile" do
|
||||
profile = subject.reload.profile
|
||||
expect(profile).to be_present
|
||||
expect(profile.id).to be_present
|
||||
expect(profile.user.id).to eq subject.id
|
||||
expect(profile.onboarding_step_id).to eq "onboarding-personal"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#last_checkin" do
|
||||
it "sees most recent checkin as more recent than less recent checkin when they are on the same day" do
|
||||
date = "2020-01-02"
|
||||
user = create(:user)
|
||||
create(:checkin, date: Date.parse(date) - 5.days, user_id: user.id)
|
||||
last = create(:checkin, date: Date.parse(date) + 2.hours, user_id: user.id)
|
||||
create(:checkin, date: Date.parse(date), user_id: user.id)
|
||||
create(:checkin, date: Date.parse(date) + 1.hour, user_id: user.id)
|
||||
expect(user.last_checkin).to eq(last)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: user_symptoms
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# symptom_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe UserSymptom, type: :model do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:symptom) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: user_treatments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# treatment_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe UserTreatment, type: :model do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to belong_to(:treatment) }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Weather do
|
||||
describe "Validations" do
|
||||
it { is_expected.to validate_uniqueness_of(:date).scoped_to(:position_id) }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user