From b67aca0ffc39dd236486135dcadc0387debe00cb Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 26 Jan 2011 18:22:00 -0800 Subject: [PATCH] Put in a lot of non nullable fields, edit the specs to match, drop a couple superfluous columns --- app/controllers/services_controller.rb | 5 +- app/models/aspect_membership.rb | 2 - app/models/services/facebook.rb | 6 +- app/models/services/twitter.rb | 4 + app/models/statistic.rb | 9 +- .../20110127000931_drop_extra_columns.rb | 10 +++ .../20110127000953_make_fields_not_null.rb | 37 ++++++++ db/schema.rb | 86 +++++++++---------- lib/data_conversion/import_to_mysql.rb | 1 - lib/webfinger.rb | 24 +++--- .../notifications_controller_spec.rb | 12 +-- spec/controllers/people_controller_spec.rb | 6 +- spec/controllers/publics_controller_spec.rb | 5 +- spec/controllers/services_controller_spec.rb | 5 +- .../controllers/statistics_controller_spec.rb | 2 + spec/factories.rb | 31 +++++-- spec/fixtures/hcard.fixture.html | 62 +++++++++++++ spec/fixtures/host-meta.fixture.html | 9 ++ spec/fixtures/webfinger.fixture.html | 18 ++++ spec/intergration/receiving_spec.rb | 7 +- .../data_conversion/import_to_mysql_spec.rb | 2 - spec/lib/diaspora/parser_spec.rb | 2 +- spec/lib/webfinger_spec.rb | 61 ++++++------- spec/models/notification_spec.rb | 4 +- spec/models/person_spec.rb | 4 +- spec/models/profile_spec.rb | 2 +- spec/models/user/connecting_spec.rb | 4 +- spec/models/user/posting_spec.rb | 4 +- spec/support/fixture_generation.rb | 4 +- 29 files changed, 294 insertions(+), 134 deletions(-) create mode 100644 db/migrate/20110127000931_drop_extra_columns.rb create mode 100644 db/migrate/20110127000953_make_fields_not_null.rb create mode 100644 spec/fixtures/hcard.fixture.html create mode 100644 spec/fixtures/host-meta.fixture.html create mode 100644 spec/fixtures/webfinger.fixture.html diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index f0e33f468..a21b6a2b6 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -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 diff --git a/app/models/aspect_membership.rb b/app/models/aspect_membership.rb index 690233a60..f79d31520 100644 --- a/app/models/aspect_membership.rb +++ b/app/models/aspect_membership.rb @@ -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 diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 35960e0f5..5b837332c 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -1,11 +1,15 @@ 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 diff --git a/app/models/services/twitter.rb b/app/models/services/twitter.rb index aeecf8c0c..12c7d9585 100644 --- a/app/models/services/twitter.rb +++ b/app/models/services/twitter.rb @@ -1,6 +1,10 @@ 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) diff --git a/app/models/statistic.rb b/app/models/statistic.rb index 6ec3f4aff..02770b3ff 100644 --- a/app/models/statistic.rb +++ b/app/models/statistic.rb @@ -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 diff --git a/db/migrate/20110127000931_drop_extra_columns.rb b/db/migrate/20110127000931_drop_extra_columns.rb new file mode 100644 index 000000000..e228ca96b --- /dev/null +++ b/db/migrate/20110127000931_drop_extra_columns.rb @@ -0,0 +1,10 @@ +class DropExtraColumns < ActiveRecord::Migration + def self.up + remove_column :services, :provider + remove_column :statistics, :type + end + + def self.down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20110127000953_make_fields_not_null.rb b/db/migrate/20110127000953_make_fields_not_null.rb new file mode 100644 index 000000000..343764f65 --- /dev/null +++ b/db/migrate/20110127000953_make_fields_not_null.rb @@ -0,0 +1,37 @@ +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 diff --git a/db/schema.rb b/db/schema.rb index f4baacd55..9ca792866 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/lib/data_conversion/import_to_mysql.rb b/lib/data_conversion/import_to_mysql.rb index f73e3765e..8ee83748b 100644 --- a/lib/data_conversion/import_to_mysql.rb +++ b/lib/data_conversion/import_to_mysql.rb @@ -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, diff --git a/lib/webfinger.rb b/lib/webfinger.rb index 60d6f66b5..61b2202a0 100644 --- a/lib/webfinger.rb +++ b/lib/webfinger.rb @@ -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 diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 614d6d33d..b3a85f8d6 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -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 diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index ebd99fcde..a978d8d83 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -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] diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index a94d02446..7fe29a526 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -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 diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index cd2b31ec4..ac89fb63c 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -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{ diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 482555713..f0809b4f9 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index f541ec34d..86a449acc 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/fixtures/hcard.fixture.html b/spec/fixtures/hcard.fixture.html new file mode 100644 index 000000000..46b7bcabc --- /dev/null +++ b/spec/fixtures/hcard.fixture.html @@ -0,0 +1,62 @@ +
+

Robert12074e3 Grimm1009eba

+
+
+

User profile

+
+
Nickname
+
+Robert12074e3 Grimm1009eba +
+
+
+
First name
+
+Robert12074e3 +
+
+
+
Family name
+
+Grimm1009eba +
+
+
+
Full name
+
+Robert12074e3 Grimm1009eba +
+
+
+
URL
+
+http://google-1266a2d.com/ +
+
+
+
Photo
+
+ +
+
+
+
Photo
+
+ +
+
+
+
Photo
+
+ +
+
+
+
Searchable
+
+true +
+
+
+
+
diff --git a/spec/fixtures/host-meta.fixture.html b/spec/fixtures/host-meta.fixture.html new file mode 100644 index 000000000..3b5ca9b2b --- /dev/null +++ b/spec/fixtures/host-meta.fixture.html @@ -0,0 +1,9 @@ + + + example.org + + Resource Descriptor + + diff --git a/spec/fixtures/webfinger.fixture.html b/spec/fixtures/webfinger.fixture.html new file mode 100644 index 000000000..0a9224bc1 --- /dev/null +++ b/spec/fixtures/webfinger.fixture.html @@ -0,0 +1,18 @@ + + + acct:alice@example.org + "http://google-1266a2d.com/" + + + + + + + + diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index ef00d2422..f08e85b0c 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -184,16 +184,17 @@ describe 'a user receives a post' do remote_person = @user3.person.dup @user3.person.delete @user3.delete + Person.where(:id => remote_person.id).delete_all + Profile.where(:person_id => remote_person.id).delete_all remote_person.id = nil - #stubs async webfinger Person.should_receive(:by_account_identifier).twice.and_return{ |handle| if handle == @user1.person.diaspora_handle @user1.person.save @user1.person else - remote_person.profile = Factory(:profile) - remote_person.save! + remote_person.save(:validate => false) + remote_person.profile = Factory(:profile, :person => remote_person) remote_person end } diff --git a/spec/lib/data_conversion/import_to_mysql_spec.rb b/spec/lib/data_conversion/import_to_mysql_spec.rb index 35ad3bb60..9c3d53f55 100644 --- a/spec/lib/data_conversion/import_to_mysql_spec.rb +++ b/spec/lib/data_conversion/import_to_mysql_spec.rb @@ -131,7 +131,6 @@ describe DataConversion::ImportToMysql do service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first service.type_before_type_cast.should == "Services::Facebook" service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014" - service.provider.should be_nil service.uid.should be_nil service.access_token.should == "yeah" service.access_secret.should be_nil @@ -739,7 +738,6 @@ describe DataConversion::ImportToMysql do service.mongo_id.should == "4d2b6ec4cc8cb43cc200003e" service.type_before_type_cast.should == "Services::Facebook" service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014" - service.provider.should be_nil service.uid.should be_nil service.access_token.should == "yeah" service.access_secret.should be_nil diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 8d51a839c..a7270a01b 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -79,7 +79,7 @@ describe Diaspora::Parser do #Build xml for profile, clear profile xml = person.profile.to_diaspora_xml reloaded_person = Person.find(id) - reloaded_person.profile = nil + reloaded_person.profile.delete reloaded_person.save(:validate => false) #Make sure profile is cleared diff --git a/spec/lib/webfinger_spec.rb b/spec/lib/webfinger_spec.rb index 712ad5e41..08a118b23 100644 --- a/spec/lib/webfinger_spec.rb +++ b/spec/lib/webfinger_spec.rb @@ -16,16 +16,15 @@ describe Webfinger do let(:good_request) { FakeHttpRequest.new(:success)} - let(:diaspora_xrd) {File.open(File.join(Rails.root, 'spec/fixtures/host_xrd')).read} - let(:diaspora_finger) {File.open(File.join(Rails.root, 'spec/fixtures/finger_xrd')).read} - let(:hcard_xml) {File.open(File.join(Rails.root, 'spec/fixtures/hcard_response')).read} + let(:diaspora_xrd) {File.open(File.join(Rails.root, 'spec/fixtures/host-meta.fixture.html')).read} + let(:diaspora_finger) {File.open(File.join(Rails.root, 'spec/fixtures/webfinger.fixture.html')).read} + let(:hcard_xml) {File.open(File.join(Rails.root, 'spec/fixtures/hcard.fixture.html')).read} let(:non_diaspora_xrd) {File.open(File.join(Rails.root, 'spec/fixtures/nonseed_finger_xrd')).read} let(:non_diaspora_hcard) {File.open(File.join(Rails.root, 'spec/fixtures/evan_hcard')).read} context 'setup' do - let(:action){ Proc.new{|person| person.inspect }} describe '#intialize' do it 'sets account ' do @@ -42,7 +41,8 @@ describe Webfinger do context 'webfinger query chain processing' do describe '#webfinger_profile_url' do it 'should parse out the webfinger template' do - finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}" + finger.send(:webfinger_profile_url, diaspora_xrd).should == + "http://example.org/webfinger?q=foo@tom.joindiaspora.com" end it 'should return nil if not an xrd' do @@ -50,7 +50,8 @@ describe Webfinger do end it 'should return the template for xrd' do - finger.send(:webfinger_profile_url, diaspora_xrd).should == 'http://tom.joindiaspora.com/webfinger/?q=foo@tom.joindiaspora.com' + finger.send(:webfinger_profile_url, diaspora_xrd).should == + 'http://example.org/webfinger?q=foo@tom.joindiaspora.com' end end @@ -70,30 +71,30 @@ describe Webfinger do context 'webfingering local people' do it 'should return a person from the database if it matches its handle' do person.save - finger.fetch.id.should == person.id - end + finger.fetch.id.should == person.id end - it 'should fetch a diaspora webfinger and make a person for them' do - diaspora_xrd.stub!(:body).and_return(diaspora_xrd) - hcard_xml.stub!(:body).and_return(hcard_xml) - diaspora_finger.stub!(:body).and_return(diaspora_finger) - RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) - #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") - # http://tom.joindiaspora.com/.well-known/host-meta - f = Webfinger.new("tom@tom.joindiaspora.com").fetch - - f.should be_valid - end - - it 'should retry with http if https fails' do - f = Webfinger.new("tom@tom.joindiaspora.com") - - diaspora_xrd.stub!(:body).and_return(diaspora_xrd) - RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd) - f.should_receive(:xrd_url).twice - f.send(:get_xrd) - f.instance_variable_get(:@ssl).should == false - end - end + it 'should fetch a diaspora webfinger and make a person for them' do + diaspora_xrd.stub!(:body).and_return(diaspora_xrd) + hcard_xml.stub!(:body).and_return(hcard_xml) + diaspora_finger.stub!(:body).and_return(diaspora_finger) + RestClient.stub!(:get).and_return(diaspora_xrd, diaspora_finger, hcard_xml) + #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") + # http://tom.joindiaspora.com/.well-known/host-meta + f = Webfinger.new("alice@example.org").fetch + + f.should be_valid + end + + it 'should retry with http if https fails' do + f = Webfinger.new("tom@tom.joindiaspora.com") + + diaspora_xrd.stub!(:body).and_return(diaspora_xrd) + RestClient.should_receive(:get).twice.and_return(nil, diaspora_xrd) + f.should_receive(:xrd_url).twice + f.send(:get_xrd) + f.instance_variable_get(:@ssl).should == false + end + end +end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 85a5cfd53..1e15ce06e 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -13,6 +13,7 @@ describe Notification do @aspect = @user.aspects.create(:name => "dudes") @opts = {:target_id => @sm.id, :target_type => @sm.class.name, + :action => "comment_on_post", :actor_id => @person.id, :recipient_id => @user.id} @note = Notification.new(@opts) @@ -60,7 +61,8 @@ describe Notification do it 'sockets to the recipient' do opts = {:target_id => @request.id, - :target_type => @request.notification_type(@user, @person), + :target_type => "Request", + :action => @request.notification_type(@user, @person), :actor_id => @person.id, :recipient_id => @user.id} diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 31ea2da2b..f0090a025 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -106,7 +106,7 @@ describe Person do end it "deletes all notifications from a person's actions" do - note = Notification.create(:actor_id => @deleter.id, :recipient_id => @user.id) + note = Factory(:notification, :actor => @deleter, :recipient => @user) @deleter.destroy Notification.where(:id => note.id).first.should be_nil end @@ -220,7 +220,7 @@ describe Person do end it 'only displays searchable people' do - invisible_person = Factory(:person, :profile => Factory(:profile,:searchable => false, :first_name => "johnson")) + invisible_person = Factory(:person, :profile => Factory.build(:profile,:searchable => false, :first_name => "johnson")) Person.search("johnson", @user).should_not include invisible_person Person.search("", @user).should_not include invisible_person end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 44182b519..9614f39ad 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -84,7 +84,7 @@ describe Profile do end describe 'date=' do - let(:profile) { Factory(:profile) } + let(:profile) { Factory.build(:profile) } it 'accepts form data' do profile.birthday.should == nil diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 537a2a95f..09ef01297 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -112,9 +112,7 @@ describe Diaspora::UserModules::Connecting do end it "should mark the corresponding notification as 'read'" do - notification = Notification.create(:target_id => @received_request.id, - :target_type => 'new_request', - :unread => true) + notification = Factory.create(:notification, :target => @received_request) Notification.where(:target_id=>@received_request.id).first.unread.should be_true user.accept_contact_request(@received_request, aspect) diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index eef990404..58bd66688 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -13,8 +13,8 @@ describe User do let!(:aspect1) { user.aspects.create(:name => 'other') } let!(:aspect2) { user2.aspects.first } - let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s } - let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } + let!(:service1) { Factory(:service, :type => 'Services::Twitter' , :user => user) } + let!(:service2) { Factory(:service, :type => 'Services::Facebook', :user => user) } describe '#add_to_streams' do before do diff --git a/spec/support/fixture_generation.rb b/spec/support/fixture_generation.rb index 57b7c4a16..f79dc4987 100644 --- a/spec/support/fixture_generation.rb +++ b/spec/support/fixture_generation.rb @@ -1,8 +1,8 @@ Rspec::Rails::ControllerExampleGroup.class_eval do # Saves the markup to a fixture file using the given name - def save_fixture(markup, name) - fixture_path = File.join(Rails.root, 'tmp', 'js_dom_fixtures') + def save_fixture(markup, name, fixture_path=nil ) + fixture_path = File.join(Rails.root, 'tmp', 'js_dom_fixtures') unless fixture_path Dir.mkdir(fixture_path) unless File.exists?(fixture_path) fixture_file = File.join(fixture_path, "#{name}.fixture.html")