Commit b67aca0f authored by Raphael's avatar Raphael

Put in a lot of non nullable fields, edit the specs to match, drop a couple superfluous columns

parent a037575e
......@@ -18,9 +18,8 @@ class ServicesController < ApplicationController
user = auth['user_info']
service = "Services::#{provider.camelize}".constantize.new(:nickname => user['nickname'],
:access_token => toke,
:access_token => toke,
:access_secret => secret,
:provider => provider,
:uid => auth['uid'])
current_user.services << service
......@@ -28,7 +27,7 @@ class ServicesController < ApplicationController
if current_user.getting_started
redirect_to getting_started_path(:step => 3)
else
redirect_to services_url
redirect_to services_url
end
end
......
......@@ -6,8 +6,6 @@ class AspectMembership < ActiveRecord::Base
belongs_to :aspect
belongs_to :contact
validates_presence_of :contact
validates_presence_of :aspect
has_one :user, :through => :contact
has_one :person, :through => :contact
......
class Services::Facebook < Service
MAX_CHARACTERS = 420
def provider
"facebook"
end
def post(post, url='')
Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}")
message = public_message(post, url)
begin
RestClient.post("https://graph.facebook.com/me/feed", :message => message, :access_token => self.access_token)
RestClient.post("https://graph.facebook.com/me/feed", :message => message, :access_token => self.access_token)
rescue Exception => e
Rails.logger.info("#{e.message} failed to post to facebook")
end
......
class Services::Twitter < Service
MAX_CHARACTERS = 140
def provider
"twitter"
end
def post(post, url='')
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url)
......
......@@ -30,7 +30,7 @@ class Statistic < ActiveRecord::Base
arr
end
def users_in_sample
def users_in_sample
@users ||= lambda {
users = self.data_points.map{|d| d.value}
users.inject do |total,curr|
......@@ -42,13 +42,14 @@ class Statistic < ActiveRecord::Base
def generate_graph
# need to use google's graph API
end
def self.generate(time=Time.now, post_range=(0..50))
stat = Statistic.new(:type => "posts_per_day", :time => time)
stat = Statistic.new(:time => time)
stat.save
post_range.each do |n|
data_point = DataPoint.users_with_posts_on_day(time,n)
data_point.statistic = stat
data_point.save
stat.data_points << data_point
end
stat.compute_average
stat.save
......
class DropExtraColumns < ActiveRecord::Migration
def self.up
remove_column :services, :provider
remove_column :statistics, :type
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end
class MakeFieldsNotNull < ActiveRecord::Migration
def self.non_nullable_fields
fields = {
:aspect_memberships => [:aspect_id, :contact_id],
:aspects => [:user_id, :name],
:comments => [:text, :post_id, :person_id, :guid],
:contacts => [:user_id, :person_id, :pending],
:data_points => [:key, :value, :statistic_id],
:invitations => [:recipient_id, :sender_id],
:notifications => [:recipient_id, :actor_id, :action, :unread],
:people => [:guid, :url, :diaspora_handle, :serialized_public_key],
:post_visibilities => [:aspect_id, :post_id],
:posts => [:person_id, :public, :guid, :pending, :type],
:profiles => [:person_id, :searchable],
:requests => [:sender_id, :recipient_id],
:services => [:type, :user_id],
:statistics => [:time],
:users => [:getting_started, :invites, :disable_mail]
}
end
def self.up
non_nullable_fields.each_pair do |table, columns|
columns.each do |column|
change_column_null(table, column, false)
end
end
end
def self.down
non_nullable_fields.each_pair do |table, columns|
columns.each do |column|
change_column_null(table, column, true)
end
end
end
end
......@@ -10,11 +10,11 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110126232040) do
ActiveRecord::Schema.define(:version => 20110127000953) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id"
t.integer "contact_id"
t.integer "aspect_id", :null => false
t.integer "contact_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -24,8 +24,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id"
create_table "aspects", :force => true do |t|
t.string "name"
t.integer "user_id"
t.string "name", :null => false
t.integer "user_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
......@@ -36,10 +36,10 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "aspects", ["user_id"], :name => "index_aspects_on_user_id"
create_table "comments", :force => true do |t|
t.text "text"
t.integer "post_id"
t.integer "person_id"
t.string "guid"
t.text "text", :null => false
t.integer "post_id", :null => false
t.integer "person_id", :null => false
t.string "guid", :null => false
t.text "creator_signature"
t.text "post_creator_signature"
t.text "youtube_titles"
......@@ -54,9 +54,9 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
create_table "contacts", :force => true do |t|
t.integer "user_id"
t.integer "person_id"
t.boolean "pending", :default => true
t.integer "user_id", :null => false
t.integer "person_id", :null => false
t.boolean "pending", :default => true, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
......@@ -68,9 +68,9 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "contacts", ["user_id", "person_id"], :name => "index_contacts_on_user_id_and_person_id", :unique => true
create_table "data_points", :force => true do |t|
t.string "key"
t.integer "value"
t.integer "statistic_id"
t.string "key", :null => false
t.integer "value", :null => false
t.integer "statistic_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -79,8 +79,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
create_table "invitations", :force => true do |t|
t.text "message"
t.integer "sender_id"
t.integer "recipient_id"
t.integer "sender_id", :null => false
t.integer "recipient_id", :null => false
t.integer "aspect_id"
t.datetime "created_at"
t.datetime "updated_at"
......@@ -294,10 +294,10 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
create_table "notifications", :force => true do |t|
t.string "target_type"
t.integer "target_id"
t.integer "recipient_id"
t.integer "actor_id"
t.string "action"
t.boolean "unread", :default => true
t.integer "recipient_id", :null => false
t.integer "actor_id", :null => false
t.string "action", :null => false
t.boolean "unread", :default => true, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
......@@ -309,10 +309,10 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "notifications", ["target_type", "target_id"], :name => "index_notifications_on_target_type_and_target_id"
create_table "people", :force => true do |t|
t.string "guid"
t.text "url"
t.string "diaspora_handle"
t.text "serialized_public_key"
t.string "guid", :null => false
t.text "url", :null => false
t.string "diaspora_handle", :null => false
t.text "serialized_public_key", :null => false
t.integer "owner_id"
t.datetime "created_at"
t.datetime "updated_at"
......@@ -325,8 +325,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
create_table "post_visibilities", :force => true do |t|
t.integer "aspect_id"
t.integer "post_id"
t.integer "aspect_id", :null => false
t.integer "post_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -336,12 +336,12 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
create_table "posts", :force => true do |t|
t.integer "person_id"
t.boolean "public", :default => false
t.integer "person_id", :null => false
t.boolean "public", :default => false, :null => false
t.string "diaspora_handle"
t.string "guid"
t.boolean "pending", :default => false
t.string "type"
t.string "guid", :null => false
t.boolean "pending", :default => false, :null => false
t.string "type", :null => false
t.text "message"
t.integer "status_message_id"
t.text "caption"
......@@ -373,8 +373,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
t.date "birthday"
t.string "gender"
t.text "bio"
t.boolean "searchable", :default => true
t.integer "person_id"
t.boolean "searchable", :default => true, :null => false
t.integer "person_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
......@@ -387,8 +387,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id", :unique => true
create_table "requests", :force => true do |t|
t.integer "sender_id"
t.integer "recipient_id"
t.integer "sender_id", :null => false
t.integer "recipient_id", :null => false
t.integer "aspect_id"
t.datetime "created_at"
t.datetime "updated_at"
......@@ -401,9 +401,8 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
add_index "requests", ["sender_id"], :name => "index_requests_on_sender_id"
create_table "services", :force => true do |t|
t.string "type"
t.integer "user_id"
t.string "provider"
t.string "type", :null => false
t.integer "user_id", :null => false
t.string "uid"
t.string "access_token"
t.string "access_secret"
......@@ -419,8 +418,7 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
create_table "statistics", :force => true do |t|
t.integer "average"
t.string "type"
t.datetime "time"
t.datetime "time", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -428,9 +426,9 @@ ActiveRecord::Schema.define(:version => 20110126232040) do
create_table "users", :force => true do |t|
t.string "username"
t.text "serialized_private_key"
t.integer "invites", :default => 0
t.boolean "getting_started", :default => true
t.boolean "disable_mail", :default => false
t.integer "invites", :default => 0, :null => false
t.boolean "getting_started", :default => true, :null => false
t.boolean "disable_mail", :default => false, :null => false
t.string "language"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
......
......@@ -216,7 +216,6 @@ module DataConversion
SELECT mongo_services.id,
mongo_services.type,
users.id,
mongo_services.provider,
mongo_services.uid,
mongo_services.access_token,
mongo_services.access_secret,
......
......@@ -8,12 +8,12 @@ class Webfinger
OPTS = {:timeout => TIMEOUT, :redirects => REDIRECTS}
def initialize(account)
@account = account.strip.gsub('acct:','').to_s
@ssl = true
@ssl = true
Rails.logger.info("event=webfinger status=initialized target=#{account}")
end
end
def fetch
begin
begin
person = Person.by_account_identifier(@account)
if person
Rails.logger.info("event=webfinger status=success route=local target=#{@account}")
......@@ -21,8 +21,8 @@ class Webfinger
end
profile_url = get_xrd
webfinger_profile = get_webfinger_profile(profile_url)
fingered_person = make_person_from_webfinger(webfinger_profile)
webfinger_profile = get_webfinger_profile(profile_url)
fingered_person = make_person_from_webfinger(webfinger_profile)
if fingered_person
Rails.logger.info("event=webfinger status=success route=remote target=#{@account}")
fingered_person
......@@ -30,8 +30,8 @@ class Webfinger
Rails.logger.info("event=webfinger status=failure route=remote target=#{@account}")
raise WebfingerFailedError.new(@account)
end
rescue
Rails.logger.info("event=receive status=abort recipient=#{@account} sender=#{salmon.author_email} reason='#{e.message}'")
rescue Exception => e
Rails.logger.info("event=receive status=abort recipient=#{@account} reason='#{e.message}'")
nil
end
end
......@@ -55,7 +55,7 @@ class Webfinger
raise e
raise I18n.t('webfinger.xrd_fetch_failed', :account => @account)
end
end
end
end
......@@ -63,8 +63,8 @@ class Webfinger
begin
http = RestClient.get(profile_url, OPTS)
rescue
raise I18n.t('webfinger.fetch_failed', :profile_url => profile_url)
rescue
raise I18n.t('webfinger.fetch_failed', :profile_url => profile_url)
end
return http.body
end
......@@ -90,8 +90,8 @@ class Webfinger
private
def webfinger_profile_url(xrd_response)
doc = Nokogiri::XML::Document.parse(xrd_response)
return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
doc = Nokogiri::XML::Document.parse(xrd_response)
return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
end
......
......@@ -15,7 +15,7 @@ describe NotificationsController do
describe '#update' do
it 'marks a notification as read' do
note = Notification.create(:recipient_id => @user.id)
note = Factory(:notification, :recipient => @user)
put :update, :id => note.id
Notification.first.unread.should == false
end
......@@ -23,8 +23,8 @@ describe NotificationsController do
it 'only lets you read your own notifications' do
user2 = bob
Notification.create(:recipient_id => @user.id)
note = Notification.create(:recipient_id => user2.id)
Factory(:notification, :recipient => @user)
note = Factory(:notification, :recipient => user2)
put :update, :id => note.id
......@@ -35,8 +35,8 @@ describe NotificationsController do
describe "#read_all" do
it 'marks all notifications as read' do
request.env["HTTP_REFERER"] = "I wish I were spelled right"
Notification.create(:recipient_id => @user.id)
Notification.create(:recipient_id => @user.id)
Factory(:notification, :recipient => @user)
Factory(:notification, :recipient => @user)
Notification.where(:unread => true).count.should == 2
get :read_all
......@@ -47,7 +47,7 @@ describe NotificationsController do
describe '#index' do
it 'paginates the notifications' do
35.times do
Notification.create(:recipient_id => @user.id)
Factory(:notification, :recipient => @user)
end
get :index
......
......@@ -78,16 +78,16 @@ describe PeopleController do
describe '#index (search)' do
before do
@eugene = Factory.create(:person,
:profile => Factory(:profile, :first_name => "Eugene",
:profile => Factory.build(:profile, :first_name => "Eugene",
:last_name => "w"))
@korth = Factory.create(:person,
:profile => Factory(:profile, :first_name => "Evan",
:profile => Factory.build(:profile, :first_name => "Evan",
:last_name => "Korth"))
end
it "assigns people" do
eugene2 = Factory.create(:person,
:profile => Factory(:profile, :first_name => "Eugene",
:profile => Factory.build(:profile, :first_name => "Eugene",
:last_name => "w"))
get :index, :q => "Eug"
assigns[:people].should =~ [@eugene, eugene2]
......
......@@ -6,7 +6,7 @@ require 'spec_helper'
describe PublicsController do
render_views
let(:fixture_path) { File.join(Rails.root, 'spec', 'fixtures')}
before do
@user = alice
@person = Factory(:person)
......@@ -17,6 +17,7 @@ describe PublicsController do
get :host_meta
response.should be_success
response.body.should =~ /webfinger/
save_fixture(response.body, "host-meta", fixture_path)
end
end
describe '#receive' do
......@@ -60,6 +61,7 @@ describe PublicsController do
it "succeeds" do
post :hcard, "guid" => @user.person.guid.to_s
response.should be_success
save_fixture(response.body, "hcard", fixture_path)
end
it 'sets the person' do
......@@ -78,6 +80,7 @@ describe PublicsController do
it "succeeds when the person and user exist locally" do
post :webfinger, 'q' => @user.person.diaspora_handle
response.should be_success
save_fixture(response.body, "webfinger", fixture_path)
end
it "404s when the person exists remotely because it is local only" do
......
......@@ -30,7 +30,7 @@ describe ServicesController do
describe '#index' do
it 'displays all connected serivices for a user' do
4.times do
@user.services << Factory(:service)
Factory(:service, :user => @user)
end
get :index
......@@ -72,8 +72,7 @@ describe ServicesController do
describe '#destroy' do
before do
@service1 = Factory.create(:service)
@user.services << @service1
@service1 = Factory.create(:service, :user => @user)
end
it 'destroys a service selected by id' do
lambda{
......
......@@ -9,6 +9,7 @@ describe StatisticsController do
end
before do
faker_stat = Statistic.generate
@stat = Statistic.new
5.times do |n|
bob.post(:status_message, :message => 'hi', :to => bob.aspects.first)
......@@ -16,6 +17,7 @@ describe StatisticsController do
(0..10).each do |n|
@stat.data_points << DataPoint.users_with_posts_on_day(Time.now, n)
end
@stat.time = faker_stat.time
@stat.save
end
......
......@@ -20,8 +20,13 @@ end
Factory.define :person do |p|
p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" }
p.sequence(:url) { |n| "http://google-#{n}#{r_str}.com/" }
p.association :profile
p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
p.after_build do |person|
person.profile ||= Factory.build(:profile, :person => person)
end
p.after_create do |person|
person.profile.save
end
end
Factory.define :searchable_person, :parent => :person do |p|
......@@ -37,19 +42,24 @@ Factory.define :user do |u|
u.password_confirmation { |u| u.password }
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
u.after_build do |user|
user.person = Factory.build(:person, :profile => Factory.create(:profile),
user.person = Factory.build(:person, :profile => Factory.build(:profile),
:owner_id => user.id,
:serialized_public_key => user.encryption_key.public_key.export,
:diaspora_handle => "#{user.username}@#{AppConfig[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
end
u.after_create do |user|
user.person.save
user.person.profile.save
end
end
Factory.define :user_with_aspect, :parent => :user do |u|
u.after_build { |user| user.aspects << Factory(:aspect) }
u.after_create { |user| Factory(:aspect, :user => user) }
end
Factory.define :aspect do |aspect|
aspect.name "generic"
aspect.association :user
end
Factory.define :status_message do |m|
......@@ -66,18 +76,25 @@ end
Factory.define :service do |service|
service.nickname "sirrobertking"
service.provider "twitter"
service.type "Services::Twitter"
service.sequence(:uid) { |token| "00000#{token}" }
service.sequence(:access_token) { |token| "12345#{token}" }
service.sequence(:access_secret) { |token| "98765#{token}" }
service.after_build do |s|
s.type = "Services::#{s.provider.camelize}"
end
end
Factory.define(:comment) do |comment|
comment.sequence(:text) {|n| "#{n} cats"}
comment.association(:person)
comment.association :post, :factory => :status_message
end
Factory.define(:notification) do |n|
n.association :recipient, :factory => :user
n.association :actor, :factory => :person
n.association :target, :factory => :comment
n.after_build do |note|
note.action = note.target.notification_type(note.recipient, note.actor)
end
end