repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/fitbit_account.rb | app/models/fitbit_account.rb | # == Schema Information
#
# Table name: fitbit_accounts
#
# id :integer not null, primary key
# uid :string(255)
# oauth_token :string(255)
# oauth_token_secret :string(255)
# user_id :integer
# created_at :datetime
# updated_at :datetime
# synced_at :datetime
# activated_at :datetime
#
class FitbitAccount < ActiveRecord::Base
include DataProvider
attr_accessible :uid, :oauth_token, :oauth_token_secret, :user
validates_presence_of :uid, :oauth_token, :oauth_token_secret
data_provider_for :weights, :sleeps
def weights options={}
if options[:import] == true && self.activated_at.present?
weights_since self.activated_at, options.except(:import)
return
elsif options[:sync] == true && self.synced_at.present?
weights_since self.synced_at, options.except(:sync)
return
end
# TODO: This needs to be wrapped in an external API rescue so that
# failures are handled gracefully
response = client.body_weight({ base_date: Date.current, period: "30d" }.merge(options).except(:sync, :import))
process_weights response["weight"]
end
def weights_since date, options={}
while date < Date.current
date += 30.days
weights({ base_date: date, period: "30d" }.merge(options))
end
end
def sleeps options={}
if options[:import] == true
sleeps_since Date.current, options.merge({ period: "max" })
elsif options[:sync] == true && self.synced_at.present?
sleeps_since self.synced_at, options.merge({ end_date: Date.current })
else
options = { base_date: Date.current}.merge(options)
response = client.sleep_on_date(options[:base_date])
process_sleeps response["sleep"]
end
end
def sleeps_since date, options={}
raise ArgumentError unless options[:period].present? || options[:end_date].present?
sleeps = client.data_by_time_range("/sleep/startTime", { base_date: date }.merge(options))
sleeps = sleeps["sleep-startTime"].select{|sleep| !sleep["value"].empty?}
sleeps.each do |sleep|
sleeps({ base_date: Date.parse(sleep["dateTime"]) }.merge(options).except(:sync, :import))
end
end
def time_zone
user_info["timezone"] if user_info.present?
end
private
def client
FitbitAccount.authenticated_user self.id
end
def self.authenticated_user id
user = FitbitAccount.find id
Fitgem::Client.new({
consumer_key: Settings.fitbit_oauth_key,
consumer_secret: Settings.fitbit_oauth_secret,
token: user.oauth_token,
secret: user.oauth_token_secret,
unit_system: Fitgem::ApiUnitSystem.METRIC
})
end
def process_weights weights
raise ArgumentError "weights must be an array" unless weights.is_a? Array || weights.nil?
weights.each do |weight|
next if user.weights.where("meta @> 'logId=>#{weight[:logId.to_s].to_s}'").first
user.weights.create(
value: weight["weight"],
date: Time.use_zone(time_zone) { Time.zone.parse("#{weight["date"]} #{weight["time"]}") }, #TODO: Timezone?
source: self.class.to_s,
meta: {
logId: weight["logId"],
response: weight
}
)
end
end
def process_sleeps sleeps
raise ArgumentError "sleeps must be an array" unless sleeps.is_a? Array || sleeps.nil?
sleeps.each do |sleep|
next if user.sleeps.where("meta @> 'logId=>#{sleep[:logId.to_s].to_s}'").first
start = Time.use_zone(time_zone) { Time.zone.parse(sleep["startTime"]) }
user.sleeps.create(
start: start,
end: start + sleep["timeInBed"].to_i.minutes,
source: self.class.to_s,
meta: {
logId: sleep["logId"],
response: sleep
}
)
end
end
def user_info
@user_info ||= client.user_info["user"]
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/journal_entry.rb | app/models/journal_entry.rb | # == Schema Information
#
# Table name: journal_entries
#
# id :integer not null, primary key
# feelings :text
# happiness :integer
# strategies :text
# created_at :datetime
# updated_at :datetime
# user_id :integer
# encrypted_happiness :string(255)
# encrypted_strategies :text
# encrypted_feelings :text
#
class JournalEntry < ActiveRecord::Base
belongs_to :user
attr_accessible :recorded_at,
:feelings,
:happiness,
:strategies
attr_encrypted :feelings,
random_iv: true,
compress: true,
type: :string
attr_encrypted :strategies,
random_iv: true,
compress: true,
type: :string
attr_encrypted :happiness,
random_iv: true,
type: :integer
validates :happiness, numericality: {
greater_than: 0,
less_than_or_equal_to: 10
}
def happiness=(val)
super(val.to_i)
end
private
# Why is this a method instead of regularly defined
# as a numericality validator?
#
# We're using a gem called symmetrical-encryption
# to enforce encryption on these fields. Basically, they
# come to us as :happiness and :strategies etc, but
# we immediately encrypt those values. So in other to validate,
# we need to cast to an int and then just run some checks
# ourselves
def encrypted_happiness_is_an_integer
unless h = happiness.to_i && h > 0 && h <= 10
errors[:happiness] = "is not a number"
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/foursquare_account.rb | app/models/foursquare_account.rb | # == Schema Information
#
# Table name: foursquare_accounts
#
# id :integer not null, primary key
# uid :string(255)
# oauth_token :string(255)
# activated_at :datetime
# synced_at :datetime
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
class FoursquareAccount < ActiveRecord::Base
include DataProvider
attr_accessible :uid, :oauth_token, :user
validates_presence_of :uid, :oauth_token
data_provider_for :places
def places options={}
if options[:import] == true && self.activated_at.present?
places_since self.activated_at, options.except(:import)
return
elsif options[:sync] == true && self.synced_at.present?
places_since self.synced_at, options.except(:sync)
return
end
# TODO: This needs to be wrapped in an external API rescue so that
# failures are handled gracefully
response = client.user_checkins options.except(:sync, :import)
process_places response["items"]
end
def places_since date=Date.current, options={}
date = date.to_i
count = client.user_checkins({afterTimestamp: date})["count"]
if count > 250
offset = 0
while count < offset
places({afterTimestamp: date, limit: 250, offset: offset}.merge(options))
offset += 250
end
else
places({afterTimestamp: date, limit: 250}.merge(options))
end
end
private
def client
FoursquareAccount.authenticated_user self.id
end
def self.authenticated_user id
user = FoursquareAccount.find id
Foursquare2::Client.new(oauth_token: user.oauth_token, api_version: '20140128')
end
def process_places places
raise ArgumentError "places must be an array" unless places.is_a? Array || places.nil?
places.each do |place|
# Proceed to next place if a version with the same meta id exists
next if user.places.where("meta @> 'id=>#{place[:id.to_s].to_s}'").first
# Proceed to next place if no venue data is available
next if !place["venue"].present?
user.places.create(
date: parse_created_at_with_time_zone_offset(place["createdAt"].to_i, place["timeZoneOffset"]),
lat: place["venue"]["location"]["lat"],
lng: place["venue"]["location"]["lng"],
source: self.class.to_s,
meta: {
id: place["id"]
},
response: place
)
end
end
def parse_created_at_with_time_zone_offset created_at, time_zone_offset
time = Time.use_zone("UTC") { Time.zone.at(created_at.to_i) }
time + (time_zone_offset / 60).hours
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/meal.rb | app/models/meal.rb | # == Schema Information
#
# Table name: meals
#
# id :integer not null, primary key
# date :date
# calories :integer
# carbohydrates :integer
# protein :integer
# fat :integer
# user_id :integer
# description :string(255)
# created_at :datetime
# updated_at :datetime
#
class Meal < ActiveRecord::Base
attr_accessible :date, :calories, :carbohydrates, :fat, :protein, :description
validates_presence_of :date, :calories
validates_numericality_of :calories
validates_numericality_of :carbohydrates, :fat, :protein
belongs_to :user
MACRO_NUTRIENTS = %w(carbohydrates fat protein)
def self.most_recent(count)
order("date DESC").limit(count)
end
def self.macro_nutrients
MACRO_NUTRIENTS
end
def unit
"grams"
end
def carbohydrates_percentage
return 0 if carbohydrates.nil?
percentage(:carbohydrates).round(1)
end
def fat_percentage
return 0 if fat.nil?
percentage(:fat).round(1)
end
def protein_percentage
return 0 if protein.nil?
percentage(:protein).round(1)
end
private
def percentage nutrient
return 0 if self.send(nutrient.to_sym) == 0
sum = 0
Meal.macro_nutrients.each do |macro_nutrient|
sum += self.send(macro_nutrient.to_sym)
end
self.send(nutrient).to_f / sum * 100
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/weight.rb | app/models/weight.rb | # == Schema Information
#
# Table name: weights
#
# id :integer not null, primary key
# type :string(255)
# user_id :integer
# bmi :float
# value :float
# lean_mass :float
# fat_mass :float
# fat_percent :float
# date :datetime
# created_at :datetime
# updated_at :datetime
# meta :hstore
# source :string(255)
#
class Weight < ActiveRecord::Base
attr_accessible :value, :date, :lean_mass, :fat_mass, :fat_percent,
:source, :meta
# We use this to store provider-specific metadata about the weight. In the case of withings,
# we get a pkey called grpid that is useful for maintaining a single copy of each record.
store_accessor :meta, :grpid
belongs_to :user
validates :value, presence: true, numericality: true
validates :lean_mass, numericality: true, allow_nil: true
validates :fat_mass, numericality: true, allow_nil: true
validates :fat_percent, numericality: true, allow_nil: true
validates :date, presence: true
before_save :calculate_all_known_values
def self.current(val, opts={})
return unless val.present?
opts = {
period: 7.days,
start: Date.today
}.merge(opts)
start = where("date >= ?", opts[:start]).order("date DESC").limit(1).first
return unless start.present? && start = start.date
records = select(val).where({
date: (start - opts[:period])..start
}).average(val)
end
def self.most_recent(count=1)
order("date DESC").limit(count)
end
def calculate_all_known_values
%w(lean_mass fat_mass fat_percent_value bmi).each do |measurement|
self.try("calculate_#{measurement}")
end
end
def calculate_bmi
if user && user.height
self.bmi = value / ( Unit.new(user.height, :centimeters).to_unit(:meters) ** 2 )
end
end
def calculate_lean_mass
calculate_missing_value :lean_mass, fat_mass, fat_percent
end
def calculate_fat_mass
calculate_missing_value :fat_mass, lean_mass, fat_percent
end
def calculate_fat_percent_value
self.fat_percent ||= if lean_mass
(value - lean_mass) / value * 100
elsif fat_mass
(fat_mass / value) * 100
end
end
def self.update_bmi_for_user id
User.find(id).weights.each do |weight|
weight.save #executes callbacks that update the bmi
end
end
protected
def calculate_missing_value missing, k, j
self[missing] ||= if k
value - k
elsif j
value - (value * (j / 100))
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/sleep.rb | app/models/sleep.rb | # == Schema Information
#
# Table name: sleeps
#
# id :integer not null, primary key
# start :datetime
# end :datetime
# user_id :integer
# created_at :datetime
# updated_at :datetime
# meta :hstore
# source :string(255)
#
class Sleep < ActiveRecord::Base
attr_accessible :start, :end, :source, :meta
validates_presence_of :start, :end
validate :ends_after_start
belongs_to :user
def duration
self.end - self.start
end
private
def ends_after_start
if self.end.present? && start.present? && self.end < start
errors.add(:end, "can't happen before start time")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/withings_account.rb | app/models/withings_account.rb | # == Schema Information
#
# Table name: withings_accounts
#
# id :integer not null, primary key
# userid :string(255)
# created_at :datetime
# updated_at :datetime
# oauth_token :string(255)
# user_id :integer
# oauth_token_secret :string(255)
# synced_at :datetime
# activated_at :datetime
#
class WithingsAccount < ActiveRecord::Base
include DataProvider
attr_accessible :userid, :oauth_token, :oauth_token_secret
validates_presence_of :userid, :oauth_token, :oauth_token_secret
data_provider_for :weights
def weights options={}
if options[:sync] == true && self.synced_at.present?
weights_since self.synced_at, options.except(:sync)
return
end
# TODO: This needs to be wrapped in an external API rescue so that
# failures are handled gracefully
response = client.send(:measurement_groups, options)
process_weights response
end
def weights_since date=Date.current, options={}
weights({ start_at: date }.merge(options))
end
private
def client
WithingsAccount.authenticated_user(id)
end
def self.authenticated_user id
user = WithingsAccount.find id
Withings::User.authenticate(user.userid, user.oauth_token, user.oauth_token_secret)
end
def process_weights weights
weights.each do |weight|
next if user.weights.where("meta @> 'grpid=>#{weight.grpid.to_s}'").first
user.weights.create(
value: weight.weight,
date: weight.taken_at,
fat_mass: weight.fat,
source: "WithingsAccount",
meta: {
grpid: weight.grpid.to_s
}
)
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/user.rb | app/models/user.rb | # == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# email :string(255) default(""), not null
# encrypted_password :string(255) default(""), not null
# reset_password_token :string(255)
# reset_password_sent_at :datetime
# remember_created_at :datetime
# confirmation_token :string(255)
# confirmed_at :datetime
# confirmation_sent_at :datetime
# unconfirmed_email :string(255)
# failed_attempts :integer default(0)
# unlock_token :string(255)
# locked_at :datetime
# name :string(255)
# height :float
# time_zone :string(255) default("UTC")
#
class User < ActiveRecord::Base
include Users::Meals
include Users::Weights
include Users::Sleeps
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :confirmable,
:omniauthable, omniauth_providers: [:withings, :fitbit, :foursquare]
# Setup accessible (or protected) attributes for your model
attr_accessible :email,
:password,
:password_confirmation,
:remember_me,
:name,
:height,
:time_zone
validates_numericality_of :height, allow_nil: true
validates_presence_of :name
after_save :update_weights_bmi, if: :height_changed?
has_many :weights
has_many :places
has_many :meals
has_many :sleeps
has_many :journal_entries
has_one :withings_account
has_one :fitbit_account
has_one :foursquare_account
def sync_all_provider_data
# Use try here so as not to raise on nil relations
[withings_account, fitbit_account].each do |provider|
if provider.present?
provider.sync
end
end
end
# This method exists to address a shortcoming in cancan where you can't define particular
# ability blocks as having exceptions when using :all
def user_id
@user_id ||= self.id
end
def has_withings_auth?
withings_account.present?
end
def has_fitbit_auth?
fitbit_account.present?
end
def has_foursquare_auth?
foursquare_account.present?
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/app/models/concerns/data_provider.rb | app/models/concerns/data_provider.rb | # DataProvider makes assumptions about the structure and source of data providers. These
# providers will typically be device manufacturers who grant open API access to consumers.
# We abstract the common API authentication behaviour here.
# All schemas for DataProviders should implement the following columns:
# => synced_at :datetime Last datetime data was imported from API
# => activated_at :datetime First known creation date of account - useful for pulling historical data
# => user_id :integer All accounts should belong to a user
module DataProvider
extend ActiveSupport::Concern
included do
belongs_to :user
after_create :import
attr_accessible :activated_at
def import
get_data import: true
end
def sync
get_data sync: true
end
private
def get_data options={}
provides_data_for.each do |type|
self.send type, options.slice(:import, :sync)
end
update_attribute :synced_at, Time.now
end
end
module ClassMethods
def data_provider_for(*attrs)
class_attribute :provides_data_for
self.provides_data_for = attrs
end
def provides_data_for
self.provides_data_for
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/seeds.rb | db/seeds.rb | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
User.all.each do |user|
5.times do |i|
user.weights.create(value: rand(200), date: Time.now - i.days, lean_mass: rand(150), source: "withings")
user.meals.create(date: Time.now - i.days, calories: rand(2000), carbohydrates: rand(100), fat: rand(100), protein: rand(100))
user.places.create(date: Time.now - i.days, lat: rand(99), lng: rand(99))
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/schema.rb | db/schema.rb | # 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 to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130728222738) do
create_table "fitbit_accounts", :force => true do |t|
t.string "uid"
t.string "oauth_token"
t.string "oauth_token_secret"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "fitbit_accounts", ["user_id"], :name => "index_fitbit_accounts_on_user_id"
create_table "locations", :force => true do |t|
t.integer "user_id"
t.datetime "recorded_at"
t.decimal "lat"
t.decimal "lng"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "measurements", :force => true do |t|
t.float "value"
t.string "type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.datetime "recorded_at"
end
add_index "measurements", ["user_id"], :name => "index_measurements_on_user_id"
create_table "spatial_ref_sys", :id => false, :force => true do |t|
t.integer "srid", :null => false
t.string "auth_name", :limit => 256
t.integer "auth_srid"
t.string "srtext", :limit => 2048
t.string "proj4text", :limit => 2048
end
create_table "users", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "name"
t.float "height"
end
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true
create_table "weights", :force => true do |t|
t.string "type"
t.integer "user_id"
t.float "bmi"
t.float "value"
t.float "lean_mass_value"
t.float "fat_mass_value"
t.float "fat_percentage"
t.datetime "recorded_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.hstore "meta"
t.string "source"
end
add_index "weights", ["meta"], :name => "index_weights_on_meta"
add_index "weights", ["user_id"], :name => "index_weights_on_user_id"
create_table "withings_accounts", :force => true do |t|
t.string "userid"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "oauth_token"
t.integer "user_id"
t.string "oauth_token_secret"
t.datetime "synced_at"
end
add_index "withings_accounts", ["user_id"], :name => "index_withings_accounts_on_user_id"
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130323055451_add_name_to_users.rb | db/migrate/20130323055451_add_name_to_users.rb | class AddNameToUsers < ActiveRecord::Migration
def change
add_column :users, :name, :string
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130803175122_rename_locations_to_places.rb | db/migrate/20130803175122_rename_locations_to_places.rb | class RenameLocationsToPlaces < ActiveRecord::Migration
def change
rename_table :locations, :places
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140109041557_create_sleeps.rb | db/migrate/20140109041557_create_sleeps.rb | class CreateSleeps < ActiveRecord::Migration
def change
create_table :sleeps do |t|
t.datetime :start
t.datetime :end
t.integer :user_id
t.timestamps
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130819210218_add_authentication_token_to_user.rb | db/migrate/20130819210218_add_authentication_token_to_user.rb | class AddAuthenticationTokenToUser < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130615173023_setup_hstore.rb | db/migrate/20130615173023_setup_hstore.rb | class SetupHstore < ActiveRecord::Migration
def self.up
execute "CREATE EXTENSION IF NOT EXISTS hstore"
end
def self.down
execute "DROP EXTENSION IF EXISTS hstore"
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130803051622_drop_measurements.rb | db/migrate/20130803051622_drop_measurements.rb | class DropMeasurements < ActiveRecord::Migration
def up
drop_table :measurements
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130913031613_change_datetime_to_date_on_meal.rb | db/migrate/20130913031613_change_datetime_to_date_on_meal.rb | class ChangeDatetimeToDateOnMeal < ActiveRecord::Migration
def up
connection = ActiveRecord::Base.connection()
connection.execute "ALTER TABLE meals
ALTER COLUMN date SET DATA TYPE date"
end
def down
connection = ActiveRecord::Base.connection()
connection.execute "ALTER TABLE meals
ALTER COLUMN date SET DATA TYPE date timestamp without time zone;"
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140118211647_add_synced_at_to_fitbit_account.rb | db/migrate/20140118211647_add_synced_at_to_fitbit_account.rb | class AddSyncedAtToFitbitAccount < ActiveRecord::Migration
def change
add_column :fitbit_accounts, :synced_at, :datetime
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130507025853_add_oauth_token_secret_to_withings_account.rb | db/migrate/20130507025853_add_oauth_token_secret_to_withings_account.rb | class AddOauthTokenSecretToWithingsAccount < ActiveRecord::Migration
def change
add_column :withings_accounts, :oauth_token_secret, :string
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130420171616_set_name_as_empty_string.rb | db/migrate/20130420171616_set_name_as_empty_string.rb | class SetNameAsEmptyString < ActiveRecord::Migration
def up
User.all.each do |user|
user.update_column(:name, "User")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140126060624_add_meta_to_sleep.rb | db/migrate/20140126060624_add_meta_to_sleep.rb | class AddMetaToSleep < ActiveRecord::Migration
def change
add_column :sleeps, :meta, :hstore
add_column :sleeps, :source, :string
add_hstore_index :sleeps, :meta
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130330165127_add_height_to_user.rb | db/migrate/20130330165127_add_height_to_user.rb | class AddHeightToUser < ActiveRecord::Migration
def change
add_column :users, :height, :float
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130622044752_add_source_to_weights.rb | db/migrate/20130622044752_add_source_to_weights.rb | class AddSourceToWeights < ActiveRecord::Migration
def change
add_column :weights, :source, :string
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130816020401_create_meals.rb | db/migrate/20130816020401_create_meals.rb | class CreateMeals < ActiveRecord::Migration
def change
create_table :meals do |t|
t.datetime :date
t.integer :calories
t.integer :carbohydrates
t.integer :protein
t.integer :fat
t.integer :user_id
t.string :description, limit: 255
t.timestamps
end
add_index :meals, :user_id
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130803162630_rename_weights_fields.rb | db/migrate/20130803162630_rename_weights_fields.rb | class RenameWeightsFields < ActiveRecord::Migration
def change
rename_column :weights, :lean_mass_value, :lean_mass
rename_column :weights, :fat_mass_value, :fat_mass
rename_column :weights, :fat_percentage, :fat_percent
rename_column :weights, :recorded_at, :date
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130608214958_remove_oauth_verify_token_from_withings_account.rb | db/migrate/20130608214958_remove_oauth_verify_token_from_withings_account.rb | class RemoveOauthVerifyTokenFromWithingsAccount < ActiveRecord::Migration
def change
remove_column :withings_accounts, :oauth_verifier
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130728222444_setup_earthdistance.rb | db/migrate/20130728222444_setup_earthdistance.rb | class SetupEarthdistance < ActiveRecord::Migration
def self.up
execute "CREATE EXTENSION IF NOT EXISTS cube"
execute "CREATE EXTENSION IF NOT EXISTS earthdistance"
end
def self.down
execute "DROP EXTENSION IF EXISTS earthdistance"
execute "DROP EXTENSION IF EXISTS cube"
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130913015037_add_time_zone_to_user.rb | db/migrate/20130913015037_add_time_zone_to_user.rb | class AddTimeZoneToUser < ActiveRecord::Migration
def change
add_column :users, :time_zone, :string, :default => "UTC"
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140125175905_convert_weights_to_kilograms.rb | db/migrate/20140125175905_convert_weights_to_kilograms.rb | class ConvertWeightsToKilograms < ActiveRecord::Migration
def up
Weight.all.each do |weight|
weight.update_attribute(:value, Unit.new(weight.value, :pounds).to_system(:metric))
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130310195028_create_users.rb | db/migrate/20130310195028_create_users.rb | class CreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.timestamps
end
end
def self.down
drop_table :users
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130420202841_add_oauth_token_to_withings_account.rb | db/migrate/20130420202841_add_oauth_token_to_withings_account.rb | class AddOauthTokenToWithingsAccount < ActiveRecord::Migration
def change
add_column :withings_accounts, :oauth_token, :string
add_column :withings_accounts, :oauth_verifier, :string
rename_column :withings_accounts, :uid, :userid
add_column :withings_accounts, :user_id, :integer
add_index :withings_accounts, :user_id
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140124014335_add_activation_date_to_data_providers.rb | db/migrate/20140124014335_add_activation_date_to_data_providers.rb | class AddActivationDateToDataProviders < ActiveRecord::Migration
def change
add_column :fitbit_accounts, :activated_at, :datetime
add_column :withings_accounts, :activated_at, :datetime
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130312014452_add_date_to_measurement.rb | db/migrate/20130312014452_add_date_to_measurement.rb | class AddDateToMeasurement < ActiveRecord::Migration
def change
add_column :measurements, :recorded_at, :datetime
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140712220030_add_encrypted_fields.rb | db/migrate/20140712220030_add_encrypted_fields.rb | class AddEncryptedFields < ActiveRecord::Migration
def change
add_column :journal_entries, :encrypted_happiness, :string
add_column :journal_entries, :encrypted_strategies, :text
add_column :journal_entries, :encrypted_feelings, :text
remove_column :journal_entries, :recorded_at, :datetime
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140712150021_create_journal_entries.rb | db/migrate/20140712150021_create_journal_entries.rb | class CreateJournalEntries < ActiveRecord::Migration
def change
create_table :journal_entries do |t|
t.datetime :recorded_at
t.string :feelings
t.integer :happiness
t.string :strategies
t.timestamps
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130324040455_create_weights.rb | db/migrate/20130324040455_create_weights.rb | class CreateWeights < ActiveRecord::Migration
def change
create_table :weights do |t|
t.string :type
t.integer :user_id
t.float :bmi
t.float :value
t.float :lean_mass_value
t.float :fat_mass_value
t.float :fat_percentage
t.datetime :recorded_at
t.timestamps
end
add_index :weights, :user_id
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130311013450_add_user_id_to_measurement.rb | db/migrate/20130311013450_add_user_id_to_measurement.rb | class AddUserIdToMeasurement < ActiveRecord::Migration
def change
add_column :measurements, :user_id, :integer
add_index :measurements, :user_id
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140108154856_remove_auth_token_from_user.rb | db/migrate/20140108154856_remove_auth_token_from_user.rb | class RemoveAuthTokenFromUser < ActiveRecord::Migration
def change
remove_column :users, :authentication_token
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130728222738_create_locations.rb | db/migrate/20130728222738_create_locations.rb | class CreateLocations < ActiveRecord::Migration
def change
create_table :locations do |t|
t.integer :user_id
t.datetime :recorded_at
t.decimal :lat
t.decimal :lng
t.timestamps
end
add_earthdistance_index :locations
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140110125408_add_index_to_sleeps_start.rb | db/migrate/20140110125408_add_index_to_sleeps_start.rb | class AddIndexToSleepsStart < ActiveRecord::Migration
def change
add_index :sleeps, :start
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140712190721_change_feelings_and_strategies_fields_to_text.rb | db/migrate/20140712190721_change_feelings_and_strategies_fields_to_text.rb | class ChangeFeelingsAndStrategiesFieldsToText < ActiveRecord::Migration
def change
change_column :journal_entries, :strategies, :text
change_column :journal_entries, :feelings, :text
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130622161730_move_grpid_to_meta.rb | db/migrate/20130622161730_move_grpid_to_meta.rb | class MoveGrpidToMeta < ActiveRecord::Migration
def up
Weight.all.each do |weight|
if weight.grpid.present?
weight.meta['grpid'] = weight.grpid
weight.source = "WithingsAccount"
weight.save
end
end
remove_column :weights, :grpid
end
def down
add_column :weights, :grpid, :integer
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130803175510_rename_places_fields.rb | db/migrate/20130803175510_rename_places_fields.rb | class RenamePlacesFields < ActiveRecord::Migration
def change
rename_column :places, :recorded_at, :date
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140712154647_add_journal_entry_to_user.rb | db/migrate/20140712154647_add_journal_entry_to_user.rb | class AddJournalEntryToUser < ActiveRecord::Migration
def change
add_column :journal_entries, :user_id, :integer
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130605043956_create_fitbit_accounts.rb | db/migrate/20130605043956_create_fitbit_accounts.rb | class CreateFitbitAccounts < ActiveRecord::Migration
def change
create_table :fitbit_accounts do |t|
t.string :uid
t.string :oauth_token
t.string :oauth_token_secret
t.integer :user_id
t.timestamps
end
add_index :fitbit_accounts, :user_id
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140521021713_remove_moods.rb | db/migrate/20140521021713_remove_moods.rb | class RemoveMoods < ActiveRecord::Migration
def up
drop_table :moods
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130316044213_create_withings_accounts.rb | db/migrate/20130316044213_create_withings_accounts.rb | class CreateWithingsAccounts < ActiveRecord::Migration
def change
create_table :withings_accounts do |t|
t.string :uid
t.timestamps
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130615174058_add_meta_to_weight.rb | db/migrate/20130615174058_add_meta_to_weight.rb | class AddMetaToWeight < ActiveRecord::Migration
def change
add_column :weights, :meta, :hstore
add_hstore_index :weights, :meta
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130310155705_create_measurements.rb | db/migrate/20130310155705_create_measurements.rb | class CreateMeasurements < ActiveRecord::Migration
def change
create_table :measurements do |t|
t.float :value
t.string :type
t.timestamps
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130323044051_add_devise_to_users.rb | db/migrate/20130323044051_add_devise_to_users.rb | class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
# t.integer :sign_in_count, :default => 0
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.string :current_sign_in_ip
# t.string :last_sign_in_ip
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130622203100_add_synced_at_to_withings_account.rb | db/migrate/20130622203100_add_synced_at_to_withings_account.rb | class AddSyncedAtToWithingsAccount < ActiveRecord::Migration
def change
add_column :withings_accounts, :synced_at, :datetime
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20140203025359_create_foursquare_table.rb | db/migrate/20140203025359_create_foursquare_table.rb | class CreateFoursquareTable < ActiveRecord::Migration
def change
create_table :foursquare_accounts do |t|
t.string :uid
t.string :oauth_token
t.datetime :activated_at
t.datetime :synced_at
t.integer :user_id
t.timestamps
end
add_index :foursquare_accounts, :user_id
add_column :places, :meta, :hstore
add_column :places, :source, :string
add_column :places, :response, :json
add_hstore_index :places, :meta
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20131231024056_create_moods.rb | db/migrate/20131231024056_create_moods.rb | class CreateMoods < ActiveRecord::Migration
def change
create_table :moods do |t|
t.datetime :date
t.integer :user_id
t.decimal :rating
t.text :description
t.timestamps
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/db/migrate/20130514040006_add_grpid_to_weights_table.rb | db/migrate/20130514040006_add_grpid_to_weights_table.rb | class AddGrpidToWeightsTable < ActiveRecord::Migration
def change
add_column :weights, :grpid, :integer
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/shared_examples_a_data_provider.rb | spec/shared_examples_a_data_provider.rb | require 'spec_helper'
shared_examples "a data provider" do
let(:data_provider) { described_class.new() }
it { should belong_to(:user) }
describe "#provides_data_for" do
context "with data types provided to #data_provider_for" do
before do
@provides_data_for = described_class.provides_data_for
described_class.data_provider_for :a, :b, :c
end
it "returns the same data types" do
expect(data_provider.provides_data_for).to eq([:a, :b, :c])
end
after do
described_class.data_provider_for *@provides_data_for
end
end
end
describe "#data_provider_for" do
context "with data types provided" do
before do
@provides_data_for = described_class.provides_data_for
described_class.data_provider_for :a, :b, :c
end
it "assigns data types to provides_data_for attribute" do
expect(data_provider.provides_data_for).to eq([:a, :b, :c])
end
after do
described_class.data_provider_for *@provides_data_for
end
end
end
describe "#sync" do
it "updates synced_at stamp" do
expect(data_provider.save).to_not eq(nil)
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/spec_helper.rb | spec/spec_helper.rb | require 'rubygems'
require 'webmock/rspec'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'email_spec'
require 'capybara/rspec'
require 'capybara/rails'
require 'omniauth'
OmniAuth.config.test_mode = true
# Disables external network connections
WebMock.disable_net_connect!(allow_localhost: true)
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Don't need passwords in test DB to be secure, but we would like 'em to be
# fast -- and the stretches mechanism is intended to make passwords
# computationally expensive.
module Devise
module Models
module DatabaseAuthenticatable
protected
def password_digest(password)
password
end
end
end
end
Devise.setup do |config|
config.stretches = 0
end
counter = -1
RSpec.configure do |config|
# Defer garbage collection
config.before(:all) do
DeferredGarbageCollection.start
end
config.after(:all) do
DeferredGarbageCollection.reconsider
end
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.after(:each) do
counter += 1
if counter > 9
GC.enable
GC.start
GC.disable
counter = 0
end
end
config.after(:suite) do
counter = 0
end
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.mock_with :rspec
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.include Devise::TestHelpers, type: :controller
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/initializers/unit_spec.rb | spec/initializers/unit_spec.rb | require 'spec_helper'
describe Unit do
describe ".to_unit" do
context "when converting 1 meter to feet" do
it "is 3.28084" do
Unit.new(1, :meters).to_unit(:feet).should eq(3.28084)
end
end
context "when converting 1 pound to one pound (same unit)" do
it "is 3.28084" do
Unit.new(1, :pounds).to_unit(:pounds).should eq(1)
end
end
end
describe ".to_system" do
context "when converting 1 meter to imperial" do
it "is 3.28084" do
Unit.new(1, :meters).to_system(:imperial).should eq(3.28084)
end
end
context "when converting 1 foot to metric" do
it "is 3.28084" do
Unit.new(1, :feet).to_system(:metric).should eq(0.3048)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/devise.rb | spec/support/devise.rb | RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/integration.rb | spec/support/integration.rb | require "#{Rails.root}/spec/support/integration/action_mailer_helpers.rb"
require "#{Rails.root}/spec/support/integration/omniauth_helpers.rb"
RSpec.configure do |config|
config.include Integration::ActionMailerHelpers, type: :request
config.include Integration::OmniauthHelpers, type: :request
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/be_a_data_provider_for_matcher.rb | spec/support/be_a_data_provider_for_matcher.rb | require 'rspec/expectations'
RSpec::Matchers.define :be_a_data_provider_for do |expected|
match do |actual|
actual.provides_data_for.include? expected
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/deferred_garbage_collection.rb | spec/support/deferred_garbage_collection.rb | class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 60.0).to_f
@@last_gc_run = Time.now
def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end
def self.reconsider
if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
GC.enable
GC.start
GC.disable
@@last_gc_run = Time.now
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/action_mailer.rb | spec/support/action_mailer.rb | RSpec.configure do |config|
config.before(:each) { ActionMailer::Base.deliveries.clear }
end | ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/integration/action_mailer_helpers.rb | spec/support/integration/action_mailer_helpers.rb | module Integration
module ActionMailerHelpers
def mailer_should_have_delivery(recipient, subject, body)
ActionMailer::Base.deliveries.should_not be_empty
message = ActionMailer::Base.deliveries.any? do |email|
email.to == [recipient] &&
email.subject =~ /#{subject}/i &&
email.body =~ /#{body}/
end
message.should be
end
def mailer_should_have_no_deliveries
ActionMailer::Base.deliveries.should be_empty
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/support/integration/omniauth_helpers.rb | spec/support/integration/omniauth_helpers.rb | module Integration
module OmniauthHelpers
OmniAuth.config.mock_auth[:withings] = OmniAuth::AuthHash.new({
provider: "withings",
uid: "0",
userid: "0",
info: {
name: nil
},
credentials: {
token: "0",
secret: "0"
}
})
OmniAuth.config.mock_auth[:fitbit] = OmniAuth::AuthHash.new({
provider: "fitbit",
uid: "0",
info: {
full_name: "Test User",
display_name: "Test",
nickname: "testuser",
gender: "MALE",
about_me: nil,
city: "0",
state: nil,
country: "0",
dob: "Mon, 01 Jan 1970",
member_since: "Mon, 01 Jan 1970",
locale: "en_US",
timezone: "America/New_York",
name: "testuser"
},
credentials: {
token: "0",
secret: "0"
}
})
end
OmniAuth.config.mock_auth[:foursquare] = OmniAuth::AuthHash.new({
provider: "foursquare",
uid: "152588",
info: {
first_name: "Test",
last_name: "User",
email: "test@example.com",
image: {
prefix: "https://irs3.4sqi.net/img/user/",
suffix: "/-IK3N0AMMIZ20ZS3H.jpg"
},
location: "Toronto, Canada"
},
credentials: {
token: "0",
expires: "false"
},
extra: {
raw_info: {
createdAt: 1391817305
}
}
})
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/omniauth_callbacks_routing_spec.rb | spec/routing/omniauth_callbacks_routing_spec.rb | require "spec_helper"
describe OmniauthCallbacksController do
describe "routing" do
# These specs exist to support the following devise config:
# config.sign_out_via = :delete
it "routes to #logout with DELETE" do
expect(delete: "/users/sign_out").to route_to(controller: "devise/sessions", action: "destroy")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/dashboard_routing_spec.rb | spec/routing/dashboard_routing_spec.rb | require "spec_helper"
describe DashboardController do
describe "routing" do
it "routes to #index" do
pending
#get("/").should route_to("dashboard#index")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/places_routing_spec.rb | spec/routing/places_routing_spec.rb | require "spec_helper"
describe PlacesController do
describe "routing" do
it "routes to #index" do
get("/places").should route_to("places#index")
end
it "routes to #new" do
get("/places/new").should route_to("places#new")
end
it "routes to #show" do
get("/places/1").should route_to("places#show", :id => "1")
end
it "routes to #edit" do
get("/places/1/edit").should route_to("places#edit", :id => "1")
end
it "routes to #create" do
post("/places").should route_to("places#create")
end
it "routes to #update" do
put("/places/1").should route_to("places#update", :id => "1")
end
it "routes to #destroy" do
delete("/places/1").should route_to("places#destroy", :id => "1")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/sleeps_routing_spec.rb | spec/routing/sleeps_routing_spec.rb | require "spec_helper"
describe SleepsController do
describe "routing" do
it "routes to #index" do
get("/sleeps").should route_to("sleeps#index")
end
it "routes to #new" do
get("/sleeps/new").should route_to("sleeps#new")
end
it "routes to #show" do
get("/sleeps/1").should route_to("sleeps#show", :id => "1")
end
it "routes to #edit" do
get("/sleeps/1/edit").should route_to("sleeps#edit", :id => "1")
end
it "routes to #create" do
post("/sleeps").should route_to("sleeps#create")
end
it "routes to #update" do
put("/sleeps/1").should route_to("sleeps#update", :id => "1")
end
it "routes to #destroy" do
delete("/sleeps/1").should route_to("sleeps#destroy", :id => "1")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/meals_routing_spec.rb | spec/routing/meals_routing_spec.rb | require "spec_helper"
describe MealsController do
describe "routing" do
it "routes to #index" do
get("/meals").should route_to("meals#index")
end
it "routes to #new" do
get("/meals/new").should route_to("meals#new")
end
it "routes to #show" do
get("/meals/1").should route_to("meals#show", :id => "1")
end
it "routes to #edit" do
get("/meals/1/edit").should route_to("meals#edit", :id => "1")
end
it "routes to #create" do
post("/meals").should route_to("meals#create")
end
it "routes to #update" do
put("/meals/1").should route_to("meals#update", :id => "1")
end
it "routes to #destroy" do
delete("/meals/1").should route_to("meals#destroy", :id => "1")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/devise_routing_spec.rb | spec/routing/devise_routing_spec.rb | require 'spec_helper'
describe Devise do
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/routing/weights_routing_spec.rb | spec/routing/weights_routing_spec.rb | require "spec_helper"
describe WeightsController do
describe "routing" do
it "routes to #index" do
get("/weights").should route_to("weights#index")
end
it "routes to #new" do
get("/weights/new").should route_to("weights#new")
end
it "routes to #show" do
get("/weights/1").should route_to("weights#show", :id => "1")
end
it "routes to #edit" do
get("/weights/1/edit").should route_to("weights#edit", :id => "1")
end
it "routes to #create" do
post("/weights").should route_to("weights#create")
end
it "routes to #update" do
put("/weights/1").should route_to("weights#update", :id => "1")
end
it "routes to #destroy" do
delete("/weights/1").should route_to("weights#destroy", :id => "1")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/requests/sleeps_spec.rb | spec/requests/sleeps_spec.rb | require 'spec_helper'
describe "Sleeps" do
let(:user) {Fabricate(:user)}
describe "GET /sleeps" do
context "when not signed in" do
it "redirects" do
get sleeps_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
SleepsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get sleeps_path
expect(
response.status
).to eq(200)
end
end
end
describe "GET /sleeps/new" do
context "when not signed in" do
it "redirects" do
get new_sleep_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
SleepsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get new_sleep_path
expect(
response.status
).to eq(200)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/requests/weights_spec.rb | spec/requests/weights_spec.rb | require 'spec_helper'
describe "Weights" do
let(:user) {Fabricate(:user)}
describe "GET /weights" do
context "when not signed in" do
it "redirects" do
get weights_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
WeightsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get weights_path
expect(
response.status
).to eq(200)
end
end
end
describe "GET /weights/new" do
context "when not signed in" do
it "redirects" do
get new_weight_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
WeightsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get new_weight_path
expect(
response.status
).to eq(200)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/requests/meals_spec.rb | spec/requests/meals_spec.rb | require 'spec_helper'
describe "Meals" do
let(:user) {Fabricate(:user)}
describe "GET /meals" do
context "when not signed in" do
it "redirects" do
get meals_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
MealsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get meals_path
expect(
response.status
).to eq(200)
end
end
end
describe "GET /meals/new" do
context "when not signed in" do
it "redirects" do
get new_meal_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
MealsController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get new_meal_path
expect(
response.status
).to eq(200)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/requests/places_spec.rb | spec/requests/places_spec.rb | require 'spec_helper'
describe "Places" do
let(:user) {Fabricate(:user)}
describe "GET /places" do
context "when not signed in" do
it "redirects" do
get places_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
PlacesController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get places_path
expect(
response.status
).to eq(200)
end
end
end
describe "GET /places/new" do
context "when not signed in" do
it "redirects" do
get new_place_path
expect(
response.status
).to eq(302) # have to be signed in
end
end
context "when signed in" do
before(:each) do
ApplicationController.any_instance.stub(:current_user).and_return(user)
PlacesController.any_instance.stub(:authenticate_user!).and_return(true)
end
it "returns 200" do
get new_place_path
expect(
response.status
).to eq(200)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/helpers/sleeps_helper_spec.rb | spec/helpers/sleeps_helper_spec.rb | require 'spec_helper'
describe SleepsHelper do
let(:sleep) { Fabricate(:sleep) }
describe '.formatted_duration' do
it 'displays duration in hours' do
expect(formatted_duration(sleep)).to eq("24.0 hours")
end
it 'uses singular in the case of a 1 hour duration' do
sleep.end = sleep.start + 1.hour
expect(formatted_duration(sleep)).to eq("1.0 hour")
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/helpers/meals_helper_spec.rb | spec/helpers/meals_helper_spec.rb | require 'spec_helper'
describe MealsHelper do
# helper MealsHelper
let(:meals) {
3.times do
Fabricate(:meal)
end
Meal.all
}
describe '.macro_percent_for_meals' do
it 'returns correct carb percentage for an array of meals' do
expect(helper.macro_percent_for_meals(meals, :carbohydrates)).to eq(33.33333333333333)
end
it 'returns correct protein percentage for an array of meals' do
expect(helper.macro_percent_for_meals(meals, :protein)).to eq(16.666666666666664)
end
it 'returns correct fat percentage for an array of meals' do
expect(helper.macro_percent_for_meals(meals, :fat)).to eq(50.0)
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/extensions/models/users/sleeps_spec.rb | spec/extensions/models/users/sleeps_spec.rb | require 'spec_helper'
describe Users::Meals do
include Users::Meals
let(:user) { Fabricate(:user)}
before do
3.times do |i|
user.sleeps.create(start: Date.current - i.days, end: Date.current - i.days + 6.hours)
end
end
describe "#sleeps_from" do
context "search for 1 day ago" do
it "finds 2 sleeps" do
user.sleeps_from(Date.yesterday).length.should eq(2)
end
end
context "search for today" do
it "finds 1 meal" do
user.sleeps_from(Date.current).length.should eq(1)
end
end
end
describe "#sleeps_after" do
context "search for 1 day ago" do
it "finds 1 sleep" do
user.sleeps_after(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 0 sleeps" do
user.sleeps_after(Date.current).length.should eq(0)
end
end
end
describe "#sleeps_before" do
context "search for 1 day ago" do
it "finds 1 sleep" do
user.sleeps_before(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 2 sleeps" do
user.sleeps_before(Date.current).length.should eq(2)
end
end
end
describe "#sleeps_on" do
context "search for 1 day ago" do
it "finds 1 sleep" do
user.sleeps_on(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 1 sleep" do
user.sleeps_on(Date.current).length.should eq(1)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/extensions/models/users/weights_spec.rb | spec/extensions/models/users/weights_spec.rb | require 'spec_helper'
describe Users::Weights do
include Users::Weights
let(:user) { Fabricate.build(:user) }
describe "#weight" do
before(:each) do
user.save
2.times do
user.weights.create(date: Time.now, value: 1.0)
end
end
it "returns a 7 day average from the last recorded Weight" do
user.current_weight.should eq(user.weights.current(:value))
end
it "returns the same value as #current" do
user.current_weight.should eq(user.weights.current(:value))
end
context "when the user has a height" do
before do
user.update_attribute(:height, 100)
end
it "returns valid bmi" do
user.bmi.to_f.should eq(1.0)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/extensions/models/users/meals_spec.rb | spec/extensions/models/users/meals_spec.rb | require 'spec_helper'
describe Users::Meals do
include Users::Meals
let(:user) { Fabricate(:user)}
before do
3.times do |i|
user.meals.create(date: Date.current - i.days, calories: 0, carbohydrates: 0, fat: 0, protein: 0)
end
end
describe "#meals_from" do
context "search for 1 day ago" do
it "finds 2 meals" do
user.meals_from(Date.yesterday).length.should eq(2)
end
end
context "search for today" do
it "finds 1 meal" do
user.meals_from(Date.current).length.should eq(1)
end
end
end
describe "#meals_after" do
context "search for 1 day ago" do
it "finds 1 meal" do
user.meals_after(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 0 meals" do
user.meals_after(Date.current).length.should eq(0)
end
end
end
describe "#meals_before" do
context "search for 1 day ago" do
it "finds 1 meal" do
user.meals_before(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 2 meals" do
user.meals_before(Date.current).length.should eq(2)
end
end
end
describe "#meals_on" do
context "search for 1 day ago" do
it "finds 1 meal" do
user.meals_on(Date.yesterday).length.should eq(1)
end
end
context "search for today" do
it "finds 1 meal" do
user.meals_on(Date.current).length.should eq(1)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/meals_controller_spec.rb | spec/controllers/meals_controller_spec.rb | require 'spec_helper'
describe MealsController do
def valid_attributes
{
date: Time.now,
calories: 0,
carbohydrates: 0,
fat: 0,
protein: 0
}
end
let(:meal) {Fabricate(:meal)}
let(:user) {Fabricate(:user)}
let(:other_user) {Fabricate(:user)}
describe "GET 'index'" do
context "when a user isn't signed in" do
it "should redirect" do
get :index
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "should only return the current_user's meals" do
meal = user.meals.create! valid_attributes
other_users_meal = other_user.meals.create! valid_attributes
get :index, {}
assigns(:meals).should eq([meal])
end
end
end
describe "GET 'show'" do
context "when a user isn't signed in" do
it "should redirect" do
get :show, {id: 1}
response.should be_redirect
end
end
context "when user is signed in" do
before(:each) do
sign_in user
end
it "assigns the meal to @meal" do
meal = user.meals.create! valid_attributes
get :show, {id: meal.to_param}
assigns(:meal).should eq(meal)
end
it "prevents access to another user's meal" do
other_meal = other_user.meals.create! valid_attributes
get :show, {id: other_meal.to_param}
response.should be_redirect
end
end
end
describe "GET 'new'" do
context "when a user isn't signed in" do
it "should redirect" do
get :new, {}
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns a new meal as @meal" do
get :new, {}
expect(
assigns(:meal)
).to be_a_new(Meal)
end
end
end
describe "GET 'edit'" do
context "when a user isn't signed in" do
it "should redirect" do
get :edit, {id: 1}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "assigns the requested meal as @meal" do
meal = user.meals.create! valid_attributes
get :edit, {id: meal.to_param}
assigns(:meal).should eq(meal)
end
it "prevents access to another user's meal" do
other_meal = other_user.meals.create! valid_attributes
get :edit, {id: other_meal.to_param}
response.should be_redirect
end
end
end
describe "POST 'create'" do
context "when a user isn't signed in" do
it "should redirect" do
post :create, {meal: valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "creates a new Meal" do
expect {
post :create, {meal: valid_attributes}
}.to change(Meal, :count).by(1)
end
it "assigns a newly created meal as @meal" do
post :create, {meal: valid_attributes}
assigns(:meal).should be_a(Meal)
assigns(:meal).should be_persisted
end
it "redirects to the meals index" do
post :create, {meal: valid_attributes}
response.should redirect_to(meals_path)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved meal as @meal" do
# Trigger the behavior that occurs when invalid params are submitted
Meal.any_instance.stub(:save).and_return(false)
post :create, {meal: { calories: 'abc' }}
assigns(:meal).should be_a_new(Meal)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Meal.any_instance.stub(:save).and_return(false)
post :create, {meal: { calories: 'abc' }}
response.should render_template("new")
end
end
end
end
describe "PUT update" do
context "when a user isn't signed in" do
it "should redirect" do
put :update, {:id => valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "updates the requested meal" do
meal = user.meals.create! valid_attributes
Meal.any_instance.should_receive(:update_attributes).with({ "calories" => "1.0" })
put :update, {:id => meal.to_param, :meal => { calories: 1.0}}
end
it "assigns the requested meal as @meal" do
meal = user.meals.create! valid_attributes
put :update, {:id => meal.to_param, :meal => valid_attributes}
assigns(:meal).should eq(meal)
end
it "redirects to meals index" do
meal = user.meals.create! valid_attributes
put :update, {:id => meal.to_param, :meal => valid_attributes}
response.should redirect_to(meals_path)
end
end
describe "with invalid params" do
it "assigns the meal as @meal" do
meal = user.meals.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Meal.any_instance.stub(:save).and_return(false)
put :update, {:id => meal.to_param, :meal => { calories: 'abc' }}
assigns(:meal).should eq(meal)
end
it "re-renders the 'edit' template" do
meal = user.meals.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Meal.any_instance.stub(:save).and_return(false)
put :update, {:id => meal.to_param, :meal => { calories: 'abc' }}
response.should render_template("edit")
end
end
end
end
describe "DELETE destroy" do
context "when a user isn't signed in" do
it "should redirect" do
meal = user.meals.create! valid_attributes
delete :destroy, {:id => meal.to_param}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "destroys the requested meal" do
meal = user.meals.create! valid_attributes
expect {
delete :destroy, {id: meal.to_param}
}.to change(Meal, :count).by(-1)
end
it "redirects to the meals list" do
meal = user.meals.create! valid_attributes
delete :destroy, {id: meal.to_param}
response.should redirect_to(meals_url)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/places_controller_spec.rb | spec/controllers/places_controller_spec.rb | require 'spec_helper'
describe PlacesController do
def valid_attributes
{
lat: 0.0,
lng: 0.0,
date: Time.now
}
end
let(:user) {Fabricate(:user)}
let(:other_user) {Fabricate(:user)}
describe "GET 'index'" do
context "when a user isn't signed in" do
it "should redirect" do
get :index
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "should only return the current_user's places" do
place = user.places.create! valid_attributes
other_users_place = other_user.places.create! valid_attributes
get :index, {}
assigns(:places).should eq([place])
end
end
end
describe "GET 'show'" do
context "when a user isn't signed in" do
it "should redirect" do
get :show, {id: 1}
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns the place to @place" do
place = user.places.create! valid_attributes
get :show, {id: place.to_param}
assigns(:place).should eq(place)
end
it "prevents access to another user's place" do
other_place = other_user.places.create! valid_attributes
get :show, {id: other_place.to_param}
response.should be_redirect
end
end
end
describe "GET 'new'" do
context "when a user isn't signed in" do
it "should redirect" do
get :new, {}
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns a new place as @place" do
get :new, {}
assigns(:place).should be_a_new(Place)
end
end
end
describe "GET 'edit'" do
context "when a user isn't signed in" do
it "should redirect" do
get :edit, {id: 1}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "assigns the requested place as @place" do
place = user.places.create! valid_attributes
get :edit, {id: place.to_param}
assigns(:place).should eq(place)
end
it "prevents access to another user's place" do
other_place = other_user.places.create! valid_attributes
get :edit, {id: other_place.to_param}
response.should be_redirect
end
end
end
describe "POST 'create'" do
context "when a user isn't signed in" do
it "should redirect" do
post :create, {place: valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "creates a new Place" do
expect {
post :create, {place: valid_attributes}
}.to change(Place, :count).by(1)
end
it "assigns a newly created place as @place" do
post :create, {place: valid_attributes}
assigns(:place).should be_a(Place)
assigns(:place).should be_persisted
end
it "redirects to the created place" do
post :create, {place: valid_attributes}
response.should redirect_to(place_path(Place.last))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved place as @place" do
# Trigger the behavior that occurs when invalid params are submitted
Place.any_instance.stub(:save).and_return(false)
post :create, {place: { lat: 'abc' }}
assigns(:place).should be_a_new(Place)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Place.any_instance.stub(:save).and_return(false)
post :create, {place: { lat: 'abc' }}
response.should render_template("new")
end
end
end
end
describe "PUT update" do
context "when a user isn't signed in" do
it "should redirect" do
put :update, {id: valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "updates the requested place" do
place = user.places.create! valid_attributes
Place.any_instance.should_receive(:update_attributes).with({ "lat" => "1.0" })
put :update, {id: place.to_param, place: { lat: 1.0 }}
end
it "assigns the requested place as @place" do
place = user.places.create! valid_attributes
put :update, {id: place.to_param, place: valid_attributes}
assigns(:place).should eq(place)
end
it "redirects to the place" do
place = user.places.create! valid_attributes
put :update, {id: place.to_param, place: valid_attributes}
response.should redirect_to(place_path(place))
end
end
describe "with invalid params" do
it "assigns the place as @place" do
place = user.places.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Place.any_instance.stub(:save).and_return(false)
put :update, {id: place.to_param, place: { lat: 'abc' }}
assigns(:place).should eq(place)
end
it "re-renders the 'edit' template" do
place = user.places.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Place.any_instance.stub(:save).and_return(false)
put :update, {id: place.to_param, place: { lat: 'abc' }}
response.should render_template("edit")
end
end
end
end
describe "DELETE destroy" do
context "when a user isn't signed in" do
it "should redirect" do
place = user.places.create! valid_attributes
delete :destroy, {id: place.to_param}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "destroys the requested place" do
place = user.places.create! valid_attributes
expect {
delete :destroy, {id: place.to_param}
}.to change(Place, :count).by(-1)
end
it "redirects to the places list" do
place = user.places.create! valid_attributes
delete :destroy, {id: place.to_param}
response.should redirect_to(places_url)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/omniauth_callbacks_controller_spec.rb | spec/controllers/omniauth_callbacks_controller_spec.rb | require 'spec_helper'
describe OmniauthCallbacksController do
let(:user) {Fabricate(:user)}
describe "GET 'withings'" do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:withings]
WithingsAccount.any_instance.stub(:import).and_return(true)
end
context "when a user is signed in" do
it "should create a WithingsAccount relation" do
sign_in user
get :withings
user.withings_account.should be_present
end
end
context "when a user already has a WithingsAccount" do
it "should set a flash notification" do
User.any_instance.stub(:has_withings_auth?) { true }
sign_in user
get :withings
flash[:success].should == "You've already synchronized your scale"
end
end
context "when there is no current user" do
it "should redirect to login" do
get :withings
response.should be_redirect
end
end
end
describe "GET 'fitbit'" do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:fitbit]
FitbitAccount.any_instance.stub(:import).and_return(true)
end
context "when a user is signed in" do
it "should create a FitbitAccount relation" do
sign_in user
get :fitbit
user.fitbit_account.should be_present
end
end
context "when a user already has a FitbitAccount" do
it "should set a flash notification" do
User.any_instance.stub(:has_fitbit_auth?) { true }
sign_in user
get :fitbit
flash[:success].should == "You've already synchronized your Fitbit account"
end
end
context "when there is no current user" do
it "should redirect to login" do
get :fitbit
response.should be_redirect
end
end
end
describe "GET 'foursquare'" do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:foursquare]
FoursquareAccount.any_instance.stub(:import).and_return(true)
end
context "when a user is signed in" do
it "show create a FoursquareAccount relation" do
sign_in user
get :foursquare
user.foursquare_account.should be_present
end
end
context "when a user already has a FoursquareAccount" do
it "should set a flash notification" do
User.any_instance.stub(:has_foursquare_auth?) { true }
sign_in user
get :foursquare
flash[:success].should == "You've already synchronized your Foursquare account"
end
end
context "when there is no current user" do
it "should redirect to login" do
get :foursquare
response.should be_redirect
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/users_controller_spec.rb | spec/controllers/users_controller_spec.rb | require 'spec_helper'
describe UsersController do
before (:each) do
@user = Fabricate(:user)
sign_in @user
end
describe "GET 'show'" do
it "should be successful" do
get :show, :id => @user.id
response.should be_success
end
it "should find the right user" do
get :show, :id => @user.id
assigns(:user).should == @user
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/home_controller_spec.rb | spec/controllers/home_controller_spec.rb | require 'spec_helper'
describe HomeController do
def valid_session
{}
end
describe "GET index" do
it "loads a valid response" do
get :index, {}, valid_session
response.should be_successful
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/journal_entries_controller_spec.rb | spec/controllers/journal_entries_controller_spec.rb | require 'spec_helper'
describe JournalEntriesController do
let(:user) { Fabricate(:user) }
let(:valid_attributes) {
{
"happiness" => "1",
"strategies" => "test string",
"feelings" => "test string"
}
}
describe "GET index" do
context "when a user isn't signed in" do
it "redirects" do
get :index
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns all journal entries as @journal_entries" do
journal_entry = user.journal_entries.create! valid_attributes
get :index
assigns(:journal_entries).should eq([journal_entry])
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/weights_controller_spec.rb | spec/controllers/weights_controller_spec.rb | require 'spec_helper'
describe WeightsController do
# This should return the minimal set of attributes required to create a valid
# Weight. As you add validations to Weight, be sure to
# update the return value of this method accordingly.
def valid_attributes
{
value: 0.0,
date: Time.now
}
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# WeightsController. Be sure to keep this updated too.
def valid_session
{}
end
let(:user) { Fabricate(:user) }
before(:each) do
sign_in user
end
describe "GET index" do
it "assigns all weights as @weights" do
weight = user.weights.create! valid_attributes
get :index, {}
assigns(:weights).should eq([weight])
end
end
describe "GET show" do
it "assigns the requested weight as @weight" do
weight = user.weights.create! valid_attributes
get :show, {id: weight.to_param}
assigns(:weight).should eq(weight)
end
end
describe "GET new" do
it "assigns a new weight as @weight" do
get :new, {}
assigns(:weight).should be_a_new(Weight)
end
end
describe "GET edit" do
it "assigns the requested weight as @weight" do
weight = user.weights.create! valid_attributes
get :edit, { id: weight.to_param, weight: {} }
assigns(:weight).should eq(weight)
end
end
describe "POST create" do
describe "with valid params" do
before(:each) do
sign_in user
end
it "creates a new Weight" do
expect {
post :create, {weight: valid_attributes}
}.to change(Weight, :count).by(1)
end
it "assigns a newly created weight as @weight" do
post :create, {weight: valid_attributes}
assigns(:weight).should be_a(Weight)
assigns(:weight).should be_persisted
end
it "redirects to the created weight" do
post :create, {weight: valid_attributes}
response.should redirect_to(weight_path(Weight.last))
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved weight as @weight" do
# Trigger the behavior that occurs when invalid params are submitted
Weight.any_instance.stub(:save).and_return(false)
post :create, {weight: { value: 'invalid params' }}
assigns(:weight).should be_a_new(Weight)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Weight.any_instance.stub(:save).and_return(false)
post :create, {weight: { value: 'invalid params' }}
response.should render_template('new')
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested weight" do
weight = user.weights.create! valid_attributes
# Assuming there are no other weights in the database, this
# specifies that the Weight created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Weight.any_instance.should_receive(:update_attributes).with({ 'value' => '1.0' })
put :update, {id: weight.to_param, weight: { value: 1.0 }}
end
it "assigns the requested weight as @weight" do
weight = user.weights.create! valid_attributes
put :update, {id: weight.to_param, weight: valid_attributes}
assigns(:weight).should eq(weight)
end
it "redirects to the weight" do
weight = user.weights.create! valid_attributes
put :update, {id: weight.to_param, weight: valid_attributes}
response.should redirect_to(weight_path(weight))
end
end
describe "with invalid params" do
it "assigns the weight as @weight" do
weight = user.weights.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Weight.any_instance.stub(:save).and_return(false)
put :update, { id: weight.to_param, weight: { value: 'invalid value' }}
assigns(:weight).should eq(weight)
end
it "re-renders the 'edit' template" do
weight = user.weights.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Weight.any_instance.stub(:save).and_return(false)
put :update, { id: weight.to_param, weight: { value: "invalid value" }}
response.should render_template("edit")
end
end
end
describe "DELETE destroy" do
it "destroys the requested weight" do
weight = user.weights.create! valid_attributes
expect {
delete :destroy, { id: weight.to_param, weight: {} }
}.to change(Weight, :count).by(-1)
end
it "redirects to the weights list" do
weight = user.weights.create! valid_attributes
delete :destroy, { id: weight.to_param, weight: {} }
response.should redirect_to(weights_url)
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/dashboard_controller_spec.rb | spec/controllers/dashboard_controller_spec.rb | require 'spec_helper'
describe DashboardController do
let(:user) {Fabricate(:user)}
describe "GET 'index'" do
context "when a user isn't signed in" do
it "should redirect" do
get :index
response.should be_redirect
end
end
context "when a user is signed in" do
it "should be successful" do
sign_in user
get :index
response.should be_success
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/controllers/sleeps_controller_spec.rb | spec/controllers/sleeps_controller_spec.rb | require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe SleepsController do
# This should return the minimal set of attributes required to create a valid
# Sleep. As you add validations to Sleep, be sure to
# adjust the attributes here as well.
let(:user) {Fabricate(:user)}
let(:valid_attributes) { { "start" => "2014-01-08 23:15:57", "end" => "2014-01-09 23:15:57" } }
describe "GET index" do
context "when a user isn't signed in" do
it "redirects" do
get :index
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns all sleeps as @sleeps" do
sleep = user.sleeps.create! valid_attributes
get :index
assigns(:sleeps).should eq([sleep])
end
end
end
describe "GET 'show'" do
context "when a user isn't signed in" do
it "redirects" do
get :show, {id: 1}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "assigns the requested sleep as @sleep" do
sleep = user.sleeps.create! valid_attributes
get :show, {:id => sleep.to_param}
assigns(:sleep).should eq(sleep)
end
it "prevents access to another user's sleep" do
sleep = Sleep.create! valid_attributes
get :show, {id: sleep.to_param}
response.should be_redirect
end
end
end
describe "GET new" do
context "when a user isn't signed in" do
it "redirects" do
get :new, {}
response.should be_redirect
end
end
context "when a user is signed in" do
before(:each) do
sign_in user
end
it "assigns a new sleep as @sleep" do
get :new, {}
assigns(:sleep).should be_a_new(Sleep)
end
end
end
describe "GET edit" do
context "when a user isn't signed in" do
it "should redirect" do
get :edit, {id: 1}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "assigns the requested sleep as @sleep" do
sleep = user.sleeps.create! valid_attributes
get :edit, {:id => sleep.to_param}
assigns(:sleep).should eq(sleep)
end
it "prevents access to another user's sleep" do
sleep = Sleep.create! valid_attributes
get :edit, {id: sleep.to_param}
response.should be_redirect
end
end
end
describe "POST create" do
context "when a user isn't signed in" do
it "should redirect" do
post :create, {:sleep => valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "creates a new Sleep" do
expect {
post :create, {:sleep => valid_attributes}
}.to change(Sleep, :count).by(1)
end
it "assigns a newly created sleep as @sleep" do
post :create, {:sleep => valid_attributes}
assigns(:sleep).should be_a(Sleep)
assigns(:sleep).should be_persisted
end
it "redirects to the sleep index" do
post :create, {:sleep => valid_attributes}
response.should redirect_to(sleeps_url)
end
end
describe "with invalid params" do
it "assigns a newly created but unsaved sleep as @sleep" do
# Trigger the behavior that occurs when invalid params are submitted
Sleep.any_instance.stub(:save).and_return(false)
post :create, {:sleep => { "start" => "invalid value" }}
assigns(:sleep).should be_a_new(Sleep)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Sleep.any_instance.stub(:save).and_return(false)
post :create, {:sleep => { "start" => "invalid value" }}
response.should render_template("new")
end
end
end
end
describe "PUT update" do
context "when a user isn't signed in" do
it "should redirect" do
put :update, {:id => valid_attributes}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
describe "with valid params" do
it "updates the requested sleep" do
sleep = user.sleeps.create! valid_attributes
# Assuming there are no other sleeps in the database, this
# specifies that the Sleep created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Sleep.any_instance.should_receive(:update).with({ "start" => "2014-01-08 23:15:57" })
put :update, {:id => sleep.to_param, :sleep => { "start" => "2014-01-08 23:15:57" }}
end
it "assigns the requested sleep as @sleep" do
sleep = user.sleeps.create! valid_attributes
put :update, {:id => sleep.to_param, :sleep => valid_attributes}
assigns(:sleep).should eq(sleep)
end
it "redirects to the sleep index" do
sleep = user.sleeps.create! valid_attributes
put :update, {:id => sleep.to_param, :sleep => valid_attributes}
response.should redirect_to(sleeps_url)
end
end
describe "with invalid params" do
it "assigns the sleep as @sleep" do
sleep = user.sleeps.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Sleep.any_instance.stub(:save).and_return(false)
put :update, {:id => sleep.to_param, :sleep => { "start" => "invalid value" }}
assigns(:sleep).should eq(sleep)
end
it "re-renders the 'edit' template" do
sleep = user.sleeps.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Sleep.any_instance.stub(:save).and_return(false)
put :update, {:id => sleep.to_param, :sleep => { "start" => "invalid value" }}
response.should render_template("edit")
end
end
end
end
describe "DELETE destroy" do
context "when a user isn't signed in" do
it "should redirect" do
sleep = user.sleeps.create! valid_attributes
delete :destroy, {:id => sleep.to_param}
response.should be_redirect
end
end
context "when a user is is signed in" do
before(:each) do
sign_in user
end
it "destroys the requested sleep" do
sleep = user.sleeps.create! valid_attributes
expect {
delete :destroy, {:id => sleep.to_param}
}.to change(Sleep, :count).by(-1)
end
it "redirects to the sleeps list" do
sleep = user.sleeps.create! valid_attributes
delete :destroy, {:id => sleep.to_param}
response.should redirect_to(sleeps_url)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/place_spec.rb | spec/models/place_spec.rb | # == Schema Information
#
# Table name: places
#
# id :integer not null, primary key
# user_id :integer
# date :datetime
# lat :decimal(, )
# lng :decimal(, )
# created_at :datetime
# updated_at :datetime
# meta :hstore
# source :string(255)
# response :json
#
require 'spec_helper'
describe Place do
# it { should validate_presence_of :value }
it { should validate_numericality_of :lat }
it { should validate_presence_of :lat }
it { should validate_numericality_of :lng }
it { should validate_presence_of :lng }
it { should belong_to(:user) }
it { should validate_presence_of :date }
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/meal_spec.rb | spec/models/meal_spec.rb | # == Schema Information
#
# Table name: meals
#
# id :integer not null, primary key
# date :date
# calories :integer
# carbohydrates :integer
# protein :integer
# fat :integer
# user_id :integer
# description :string(255)
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
describe Meal do
it { should validate_presence_of :date }
it { should validate_presence_of :calories }
it { should validate_numericality_of :calories }
it { should validate_numericality_of :carbohydrates }
it { should validate_numericality_of :fat }
it { should validate_numericality_of :protein }
it { should belong_to(:user) }
let(:meal) { Fabricate.build(:meal) }
describe "#percentage" do
it "calculates carbohydrate percentage correctly" do
meal.carbohydrates_percentage.should(eq(33.3))
end
it "calculates protein percentage correctly" do
meal.protein_percentage.should(eq(16.7))
end
it "calculates fat percentage correctly" do
meal.fat_percentage.should(eq(50.0))
end
context "all macros are set to 0" do
before(:each) do
meal.carbohydrates = 0
meal.protein = 0
meal.fat = 0
end
it "returns 0 for each macro percentage" do
meal.carbohydrates_percentage.should(eq(0.0))
meal.fat_percentage.should(eq(0.0))
meal.protein_percentage.should(eq(0.0))
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/sleep_spec.rb | spec/models/sleep_spec.rb | # == Schema Information
#
# Table name: sleeps
#
# id :integer not null, primary key
# start :datetime
# end :datetime
# user_id :integer
# created_at :datetime
# updated_at :datetime
# meta :hstore
# source :string(255)
#
require 'spec_helper'
describe Sleep do
it { should validate_presence_of :start }
it { should validate_presence_of :end }
it { should belong_to(:user) }
it "validates that the end is after the start time" do
pending
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/fitbit_account_spec.rb | spec/models/fitbit_account_spec.rb | # == Schema Information
#
# Table name: fitbit_accounts
#
# id :integer not null, primary key
# uid :string(255)
# oauth_token :string(255)
# oauth_token_secret :string(255)
# user_id :integer
# created_at :datetime
# updated_at :datetime
# synced_at :datetime
# activated_at :datetime
#
require 'spec_helper'
require 'shared_examples_a_data_provider'
describe FitbitAccount do
it { should validate_presence_of :uid }
it { should validate_presence_of :oauth_token }
it { should validate_presence_of :oauth_token_secret }
it { should be_a_data_provider_for :weights, :sleeps }
it_behaves_like "a data provider"
let(:user) {
user = Fabricate(:user)
user.fitbit_account = Fabricate.build(:fitbit_account)
user
}
let(:fitbit_account) {
user.fitbit_account
}
before do
stub_request(:get, /.*api.fitbit.com\/1\/user\/-\/sleep\/startTime\/date\/.*\/.*.json/).
to_return(status: 200, body: "{\"sleep-startTime\": [{\"dateTime\": \"2014-01-22\",\"value\": \"00:52\"}]}", headers: {})
stub_request(:get, /.*api.fitbit.com\/1\/user\/-\/body\/log\/weight\/date\/.*\/30d.json/).
to_return(status: 200, body: "{\"weight\":[{\"bmi\":31.45,\"date\":\"2014-01-11\",\"logId\":1389484799000,\"time\":\"23:59:59\",\"weight\":195},{\"bmi\":30.81,\"date\":\"2014-01-18\",\"logId\":1390089599000,\"time\":\"23:59:59\",\"weight\":191}]}", :headers => {})
stub_request(:get, /.*api.fitbit.com\/1\/user\/-\/sleep\/date\/.*.json/).
to_return(status: 200, body: "{\"sleep\":[{\"awakeningsCount\":14,\"duration\":26160000,\"efficiency\":93,\"isMainSleep\":true,\"logId\":98934441,\"minuteData\":[{\"dateTime\":\"00:52:00\",\"value\":\"3\"}],\"minutesAfterWakeup\":0,\"minutesAsleep\":401,\"minutesAwake\":29,\"minutesToFallAsleep\":6,\"startTime\":\"2014-01-22T00:52:00.000\",\"timeInBed\":436}],\"summary\":{\"totalMinutesAsleep\":401,\"totalSleepRecords\":1,\"totalTimeInBed\":436}}")
stub_request(:get, /.*api.fitbit.com\/1\/user\/-\/profile.json/).
to_return(:status => 200, :body => "{\"user\":{\"timezone\":\"America/New_York\"}}", :headers => {})
end
context "with a user" do
before do
# Let user #after_create occur - I'm not sure why this is all necessary though?
user.save
user.weights.delete_all
user.sleeps.delete_all
user.fitbit_account.synced_at = Date.current - 1.day
end
describe ".sync" do
it "updates weights on user" do
expect{fitbit_account.sync}.to change{user.weights.count}.by(2)
end
it "updates sleeps on user" do
expect{fitbit_account.sync}.to change{user.sleeps.count}.by(1)
end
end
describe ".weights" do
context "with { sync: true }" do
it "requests .weights_since self.synced_at" do
FitbitAccount.any_instance.should_receive(:weights_since).with(fitbit_account.synced_at, {})
fitbit_account.weights({ sync: true })
end
end
context "with { import: true }" do
it "requests .weights_since self.actived_at" do
FitbitAccount.any_instance.should_receive(:weights_since).with(fitbit_account.activated_at, {})
fitbit_account.weights({ import: true })
end
end
context "without options" do
it "does not request .weights_since" do
FitbitAccount.any_instance.should_not_receive(:weights_since)
fitbit_account.weights
end
it "sends weights response to .process_weights" do
FitbitAccount.any_instance.should_receive(:process_weights).with([{"bmi"=>31.45, "date"=>"2014-01-11", "logId"=>1389484799000, "time"=>"23:59:59", "weight"=>195}, {"bmi"=>30.81, "date"=>"2014-01-18", "logId"=>1390089599000, "time"=>"23:59:59", "weight"=>191}])
fitbit_account.weights
end
end
end
describe ".weights_since" do
it "requests weights from yesterday + 30 days forward" do
yesterday = Date.current - 1.day
yesterday_in_30_days = yesterday + 30.days
fitbit_account.weights_since(yesterday)
a_request(:any, /.*api.fitbit.com\/1\/user\/-\/body\/log\/weight\/date\/#{yesterday_in_30_days.strftime("%F")}\/30d.*/).should have_been_made
end
end
describe ".process_weights" do
it "persists new weights" do
expect {
fitbit_account.send(:process_weights, [{"bmi"=>31.45, "date"=>"2014-01-11", "logId"=>1389484799000, "time"=>"23:59:59", "weight"=>195}, {"bmi"=>30.81, "date"=>"2014-01-18", "logId"=>1390089599000, "time"=>"23:59:59", "weight"=>191}])
}.to change(Weight, :count).by(2)
end
it "raises ArgumentError if no weights sent" do
expect {
fitbit_account.send(:process_weights)
}.to raise_error(ArgumentError)
end
end
describe ".sleeps" do
context "with { sync: true }" do
it "requests .sleeps_since self.synced_at" do
FitbitAccount.any_instance.should_receive(:sleeps_since).with(fitbit_account.synced_at, {sync: true, end_date: Date.current })
fitbit_account.sleeps({ sync: true })
end
end
context "with { import: true }" do
it "requests .sleeps_since self.actived_at" do
FitbitAccount.any_instance.should_receive(:sleeps_since).with(fitbit_account.activated_at, {import: true, period: "max"})
fitbit_account.sleeps({ import: true })
end
end
context "without options" do
it "does not request .sleeps_since" do
FitbitAccount.any_instance.should_not_receive(:sleeps_since)
fitbit_account.sleeps
end
it "sends weights response to .process_sleeps" do
FitbitAccount.any_instance.should_receive(:process_sleeps).with([{"awakeningsCount"=>14, "duration"=>26160000, "efficiency"=>93, "isMainSleep"=>true, "logId"=>98934441, "minuteData"=>[{"dateTime"=>"00:52:00", "value"=>"3"}], "minutesAfterWakeup"=>0, "minutesAsleep"=>401, "minutesAwake"=>29, "minutesToFallAsleep"=>6, "startTime"=>"2014-01-22T00:52:00.000", "timeInBed"=>436}])
fitbit_account.sleeps
end
end
end
describe ".sleeps_since" do
it "raises an argument error if neither options[:period] nor options[:end_date] are provided" do
expect {
fitbit_account.sleeps_since Date.current
}.to raise_error(ArgumentError)
end
it "requests sleeps by date range from Fitbit api" do
fitbit_account.sleeps_since Date.current - 1.day, { period: "max" }
a_request(:any, /.*api.fitbit.com\/1\/user\/-\/sleep\/startTime\/date\/#{(Date.current - 1.day).strftime("%F")}\/.*.json/).should have_been_made
end
end
describe ".process_sleeps" do
it "persists new sleeps" do
expect {
fitbit_account.send(:process_sleeps, [{"awakeningsCount"=>14, "duration"=>26160000, "efficiency"=>93, "isMainSleep"=>true, "logId"=>98934441, "minuteData"=>[{"dateTime"=>"00:52:00", "value"=>"3"}], "minutesAfterWakeup"=>0, "minutesAsleep"=>401, "minutesAwake"=>29, "minutesToFallAsleep"=>6, "startTime"=>"2014-01-22T00:52:00.000", "timeInBed"=>436}])
}.to change(Sleep, :count).by(1)
end
it "raises ArgumentError if no sleeps sent" do
expect {
fitbit_account.send(:process_sleeps)
}.to raise_error(ArgumentError)
end
end
describe ".time_zone" do
it "returns a time zone for the client" do
expect(
fitbit_account.time_zone
).to eq("America/New_York")
end
end
describe ".user_info" do
it "returns a hash" do
expect(
fitbit_account.send(:user_info)
).to eq({"timezone"=>"America/New_York"})
end
end
describe ".client" do
it "returns a FitbitGem authenticated user" do
expect(
fitbit_account.send(:client).class
).to eq(Fitgem::Client)
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/foursquare_account_spec.rb | spec/models/foursquare_account_spec.rb | # == Schema Information
#
# Table name: foursquare_accounts
#
# id :integer not null, primary key
# uid :string(255)
# oauth_token :string(255)
# activated_at :datetime
# synced_at :datetime
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
require 'shared_examples_a_data_provider'
describe FoursquareAccount do
it { should validate_presence_of :uid }
it { should validate_presence_of :oauth_token }
it { should be_a_data_provider_for :places }
it_behaves_like "a data provider"
let(:user) { Fabricate(:user) }
let(:foursquare_account) { Fabricate(:foursquare_account, user: user) }
before do
stub_request(:get, /.*api.foursquare.com\/v2\/users\/self\/checkins.*/).
to_return(:status => 200, :body => "{\"meta\":{\"code\":200},\"notifications\":[{\"type\":\"notificationTray\",\"item\":{\"unreadCount\":0}}],\"response\":{\"checkins\":{\"count\":60,\"items\":[{\"id\":\"52f7e2e3498e92497b856745\",\"createdAt\":1391977187,\"type\":\"checkin\",\"timeZoneOffset\":-300,\"venue\":{\"id\":\"4ad88e03f964a520451221e3\",\"name\":\"Future Bakery & Café\",\"contact\":{\"phone\":\"4163667259\",\"formattedPhone\":\"(416) 366-7259\"},\"location\":{\"address\":\"483 Bloor St W\",\"crossStreet\":\"at Brunswick Ave.\",\"lat\":43.665884,\"lng\":-79.407433,\"postalCode\":\"M5S 1Y2\",\"cc\":\"CA\",\"city\":\"Toronto\",\"state\":\"ON\",\"country\":\"Canada\"},\"categories\":[{\"id\":\"4bf58dd8d48988d16d941735\",\"name\":\"Café\",\"pluralName\":\"Cafés\",\"shortName\":\"Café\",\"icon\":{\"prefix\":\"https://ss1.4sqi.net/img/categories_v2/food/cafe_\",\"suffix\":\".png\"},\"primary\":true}],\"verified\":false,\"stats\":{\"checkinsCount\":3486,\"usersCount\":1893,\"tipCount\":71},\"likes\":{\"count\":24,\"groups\":[{\"type\":\"others\",\"count\":24,\"items\":[]}],\"summary\":\"24 likes\"},\"like\":false,\"beenHere\":{\"count\":1,\"marked\":false},\"storeId\":\"Brunswick House\"},\"likes\":{\"count\":0,\"groups\":[]},\"like\":false,\"photos\":{\"count\":0,\"items\":[]},\"posts\":{\"count\":0,\"textCount\":0},\"comments\":{\"count\":0},\"source\":{\"name\":\"foursquare for Android\",\"url\":\"https://foursquare.com/download/#/android\"}}]}}}", :headers => {})
end
before do
foursquare_account.save
end
context "with a user" do
describe ".places" do
context "with { sync: true }" do
it "requests .places_since self.synced_at" do
FoursquareAccount.any_instance.should_receive(:places_since).with(foursquare_account.synced_at, {})
foursquare_account.places({ sync: true })
end
end
context "with { import: true }" do
it "requests .places_since self.actived_at" do
FoursquareAccount.any_instance.should_receive(:places_since).with(foursquare_account.activated_at, {})
foursquare_account.places({ import: true })
end
end
context "without options" do
it "does not request .places_since" do
FoursquareAccount.any_instance.should_not_receive(:places_since)
foursquare_account.places
end
it "sends places response to .process_places" do
FoursquareAccount.any_instance.should_receive(:process_places) # Arg is too long to define
foursquare_account.places
end
end
end
describe ".places_since" do
it "requests places from Foursquare API" do
pending
end
end
describe ".client" do
it "returns a Foursquare2 authenticated user" do
expect(
foursquare_account.send(:client).class
).to eq(Foursquare2::Client)
end
end
describe ".process_places" do
pending
end
describe ".parse_created_at_with_time_zone_offset" do
pending
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/journal_entry_spec.rb | spec/models/journal_entry_spec.rb | # == Schema Information
#
# Table name: journal_entries
#
# id :integer not null, primary key
# feelings :text
# happiness :integer
# strategies :text
# created_at :datetime
# updated_at :datetime
# user_id :integer
# encrypted_happiness :string(255)
# encrypted_strategies :text
# encrypted_feelings :text
#
require 'spec_helper'
describe JournalEntry do
pending "add some examples to (or delete) #{__FILE__}"
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/withings_account_spec.rb | spec/models/withings_account_spec.rb | # == Schema Information
#
# Table name: withings_accounts
#
# id :integer not null, primary key
# userid :string(255)
# created_at :datetime
# updated_at :datetime
# oauth_token :string(255)
# user_id :integer
# oauth_token_secret :string(255)
# synced_at :datetime
# activated_at :datetime
#
require 'spec_helper'
require 'shared_examples_a_data_provider'
describe WithingsAccount do
it { should validate_presence_of :userid }
it { should validate_presence_of :oauth_token }
it { should validate_presence_of :oauth_token_secret }
it { should belong_to(:user) }
it { should be_a_data_provider_for :weights }
it_behaves_like "a data provider"
let(:user) { Fabricate(:user, withings_account: Fabricate(:withings_account)) }
before do
stub_request(:get, /.*wbsapi.withings.net\/user\?action=getbyuserid.*/).
to_return(:status => 200, :body => "{\"status\":0,\"body\":{\"users\":[{\"id\":0,\"firstname\":\"Test\",\"lastname\":\"User\",\"shortname\":\"TES\",\"gender\":0,\"fatmethod\":131,\"birthdate\":598467600,\"ispublic\":5}]}}", :headers => {})
stub_request(:get, /.*wbsapi.withings.net\/measure\?action=getmeas.*/).
to_return(:status => 200, :body => "{\"status\":0,\"body\":{\"updatetime\":1370730432,\"more\":370,\"measuregrps\":[{\"grpid\":123986552,\"attrib\":0,\"date\":1370691572,\"category\":1,\"measures\":[{\"value\":64400,\"type\":1,\"unit\":-3},{\"value\":54519,\"type\":5,\"unit\":-3},{\"value\":15344,\"type\":6,\"unit\":-3},{\"value\":9881,\"type\":8,\"unit\":-3}]}]}}", :headers => {})
end
context "with an active withings account" do
describe ".sync" do
it "should update #synced_at" do
pending
end
it "should get add weights to user" do
pending
end
end
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/user_spec.rb | spec/models/user_spec.rb | # == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# created_at :datetime
# updated_at :datetime
# email :string(255) default(""), not null
# encrypted_password :string(255) default(""), not null
# reset_password_token :string(255)
# reset_password_sent_at :datetime
# remember_created_at :datetime
# confirmation_token :string(255)
# confirmed_at :datetime
# confirmation_sent_at :datetime
# unconfirmed_email :string(255)
# failed_attempts :integer default(0)
# unlock_token :string(255)
# locked_at :datetime
# name :string(255)
# height :float
# time_zone :string(255) default("UTC")
#
require 'spec_helper'
describe User do
it { should have_many(:weights) }
it { should have_many(:meals) }
it { should have_many(:places) }
it { should have_many(:sleeps) }
it { should have_one(:withings_account) }
it { should have_one(:fitbit_account) }
it { should have_one(:foursquare_account) }
it { should validate_numericality_of :height }
it { should validate_presence_of :name }
describe ".has_withings_auth?" do
pending
end
describe ".has_foursquare_auth?" do
pending
end
describe ".has_fitbit_auth?" do
pending
end
describe ".sync_all_provider_data" do
pending
end
describe ".user_id" do
pending
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/models/weight_spec.rb | spec/models/weight_spec.rb | # == Schema Information
#
# Table name: weights
#
# id :integer not null, primary key
# type :string(255)
# user_id :integer
# bmi :float
# value :float
# lean_mass :float
# fat_mass :float
# fat_percent :float
# date :datetime
# created_at :datetime
# updated_at :datetime
# meta :hstore
# source :string(255)
#
require 'spec_helper'
describe Weight do
it { should validate_presence_of :value }
it { should validate_numericality_of :value }
it { should validate_numericality_of :lean_mass }
it { should validate_numericality_of :fat_mass }
it { should validate_numericality_of :fat_percent }
it { should belong_to(:user) }
it { should validate_presence_of :date }
let(:weight) {Fabricate(:weight)}
let(:user) { Fabricate(:user) { height 165 } }
let(:weight_with_height) {
user.weights.new(value: 70)
}
describe "#calculate_bmi" do
context "when user doesn't have height" do
it "returns nil" do
weight.calculate_bmi.should be_nil
end
end
context "when user has a height" do
it "returns a value" do
weight_with_height.calculate_bmi.should eq(25.711662075298435)
end
end
end
describe "#calculate_all_known_values" do
context "when user doesn't have lean_mass, fat_mass, or fat_percent" do
it "isn't changed" do
weight.calculate_all_known_values
weight.changed?.should be_false
end
end
context "when user has a lean_mass" do
it "updates fat_mass and fat_percent" do
weight.update_attributes(lean_mass: 9.0, value: 10.0)
weight.fat_mass.should(eq(1.0)) && weight.fat_percent.should(eq(10.0))
end
end
context "when user has a fat_mass" do
it "updates lean_mass and fat_percent" do
weight.update_attributes(fat_mass: 9.0, value: 10.0)
weight.lean_mass.should(eq(1.0)) && weight.fat_percent.should(eq(90.0))
end
end
context "when user has a fat_percent" do
it "updates lean_mass and fat_percent" do
weight.update_attributes(fat_percent: 50.0, value: 10.0)
weight.lean_mass.should(eq(5.0)) && weight.fat_mass.should(eq(5.0))
end
end
end
describe ".interpolate" do
pending
end
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
jdjkelly/quant | https://github.com/jdjkelly/quant/blob/b3a1d83466ff5bb3b80e29f4d9999d871c77d280/spec/fabricators/withings_account_fabricator.rb | spec/fabricators/withings_account_fabricator.rb | # == Schema Information
#
# Table name: withings_accounts
#
# id :integer not null, primary key
# userid :string(255)
# created_at :datetime
# updated_at :datetime
# oauth_token :string(255)
# user_id :integer
# oauth_token_secret :string(255)
# synced_at :datetime
# activated_at :datetime
#
Fabricator(:withings_account) do
oauth_token "0"
oauth_token_secret "0"
userid "0"
end
| ruby | MIT | b3a1d83466ff5bb3b80e29f4d9999d871c77d280 | 2026-01-04T17:44:17.025352Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.