Skip to content

Commit

Permalink
Merge pull request hotsh#715 from carols10cents/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
carols10cents committed Dec 27, 2012
2 parents 9464c48 + 2fafbdb commit 2120fb6
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 85 deletions.
22 changes: 13 additions & 9 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
class StaticController < ApplicationController
before_filter :require_user, :only => :follow

def homepage
@list_class = ""
render :layout => false
end

def open_source
@title = "open source"
end

def about
@title = "about us"
end
Expand All @@ -21,4 +12,17 @@ def contact
def follow
@title = "follow a user"
end

def help
end

def homepage
@list_class = ""
render :layout => false
end

def open_source
@title = "open source"
end

end
Empty file removed app/models/.gitkeep
Empty file.
49 changes: 27 additions & 22 deletions app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class Author
# public keys are good for 4 weeks
PUBLIC_KEY_LEASE_DAYS = 28

# Schema

# We've got a bunch of data that gets stored in Author. And basically none
# of it is val*idated right now. Fun. Then again, not all of it is neccesary.
# of it is validated right now. Fun. Then again, not all of it is neccesary.
key :username, String

# This contains the domain that the author's feed originates.
Expand All @@ -25,18 +27,6 @@ class Author
# When true, this author wishes ssl and https to be used for their endpoints
key :use_ssl, Boolean

validates_presence_of :domain

# Normalize the domain so we can use them the same way
before_save :normalize_domain

# Make sure the image url uses https
before_save :https_image_url

# Twitter has an SSL cert that doesn't match the domain but we can
# change the domain to match the cert and the avatars work
before_save :modify_twitter_image_url_domain

# The Author has a profile and with that various entries
key :name, String
key :email, String
Expand All @@ -60,6 +50,9 @@ class Author
# For sorting by signup, Authors require timestamps
timestamps!

# Validations

validates_presence_of :domain
# We cannot put a :unique tag above because of a MongoMapper bug
validates_uniqueness_of :remote_url, :allow_nil => :true

Expand All @@ -70,9 +63,20 @@ class Author
one :feed, :dependent => :destroy
one :user

# Callbacks

# Normalize the domain so we can use them the same way
before_save :normalize_domain

# Make sure the image url uses https
before_save :https_image_url

# Twitter has an SSL cert that doesn't match the domain but we can
# change the domain to match the cert and the avatars work
before_save :modify_twitter_image_url_domain

# This takes results from an omniauth reponse and generates an author
def self.create_from_hash!(hash, domain)

# Omniauth user information, as a hash
user = hash['info']

Expand Down Expand Up @@ -236,20 +240,21 @@ def to_atom
:uri => author_url,
:portable_contacts => poco,
:links => [Atom::Link.new(:rel => "avatar",
:type => "image/png",
:href => avatar_url_abs)])

:type => "image/png",
:href => avatar_url_abs)])
author
end

def normalize_domain
set_default_use_ssl if use_ssl.nil?

norm = self.domain.gsub(/^.*:\/\//, "")
norm = norm.gsub(/^www./, "")
norm = norm.gsub(/\/.*$/, "")
norm = norm.gsub(/\?.*$/, "")
norm = norm.gsub(/#.*$/, "")
norm = self.domain
norm = norm.gsub(/^.*:\/\//, "") # remove protocol
norm = norm.gsub(/^www./, "") # remove www
norm = norm.gsub(/\/.*$/, "") # remove trailing slash
norm = norm.gsub(/\?.*$/, "") # remove query string
norm = norm.gsub(/#.*$/, "") # remove anchors

self.domain = norm
end

Expand Down
44 changes: 20 additions & 24 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ class Feed

include MongoMapper::Document

# Feed url (and an indicator that it is local if this is nil)
key :remote_url, String

# OStatus subscriber information
key :verify_token, String
key :secret, String

# For both pubs and subs, it needs to know what hubs the feed is in
# communication with in order to control pub/sub operations
key :hubs, Array

belongs_to :author
key :author_id, ObjectId

many :updates, :order => 'created_at desc', :dependent => :destroy
key :remote_url, String # Feed url (and an indicator that it is local if
# this is nil)
key :verify_token, String # OStatus subscriber information
key :secret, String # OStatus subscriber information
key :hubs, Array # For both pubs and subs, it needs to know what
# hubs the feed is in
# communication with in order to control pub/sub
# operations
key :author_id, ObjectId # Association key

belongs_to :author
many :updates, :order => 'created_at desc', :dependent => :destroy

timestamps!

Expand All @@ -54,7 +51,7 @@ def populate(finger_data)
self.verify_token = SecureRandom.hex
self.secret = SecureRandom.hex

ostatus_feed = OStatus::Feed.from_url(url)
ostatus_feed = OStatus::Feed.from_url(url)

avatar_url = ostatus_feed.icon
if avatar_url == nil
Expand All @@ -63,19 +60,18 @@ def populate(finger_data)

a = ostatus_feed.author

self.author = Author.create(:name => a.portable_contacts.display_name,
:username => a.name,
:email => a.email,
self.author = Author.create(:name => a.portable_contacts.display_name,
:username => a.name,
:email => a.email,
:remote_url => a.uri,
:domain => a.uri,
:domain => a.uri,
:salmon_url => ostatus_feed.salmon,
:bio => a.portable_contacts.note,
:image_url => avatar_url)
:bio => a.portable_contacts.note,
:image_url => avatar_url)

if(finger_data)
if finger_data
self.author.public_key = finger_data.public_key
self.author.reset_key_lease

self.author.salmon_url = finger_data.salmon_url
self.author.save
end
Expand Down
11 changes: 5 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
match "/login", :to => "sessions#new"
match "/logout", :to => "sessions#destroy", :via => :post

match "/follow", :to => "static#follow", :via => :get

# Static
match "contact" => "static#contact"
match "about" => "static#about"
match "open_source" => "static#open_source"
match "help" => "static#help"
match "about", :to => "static#about"
match "contact", :to => "static#contact"
match "follow", :to => "static#follow", :via => :get
match "help", :to => "static#help"
match "open_source", :to => "static#open_source"

# External Auth
# If we add more valid auth providers, they will need to be added
Expand Down
Empty file removed lib/tasks/.gitkeep
Empty file.
Empty file removed log/.gitkeep
Empty file.
8 changes: 2 additions & 6 deletions test/acceptance/alps/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

before do
@a_user = Fabricate(:user)
@an_update = Fabricate(:update,
:author => @a_user.author,
:created_at => Time.parse(
"Jan 1, 2012 09:34:16 UTC"
)
)
@an_update = Fabricate(:update, :author => @a_user.author,
:created_at => Time.parse("Jan 1, 2012 09:34:16 UTC"))
@a_user.feed.updates << @an_update

visit "/updates"
Expand Down
12 changes: 6 additions & 6 deletions test/fabricators/author_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Fabricator(:author) do
feed { |author| Fabricate(:feed, :author => author) }
username "user"
email { sequence(:email) { |i| "user_#{i}@example.com" } }
website "http://example.com"
domain "http://foo.example.com"
name "Something"
bio "Hi, I do stuff."
username "user"
email { sequence(:email) { |i| "user_#{i}@example.com" } }
website "http://example.com"
domain "http://foo.example.com"
name "Something"
bio "Hi, I do stuff."
end
10 changes: 5 additions & 5 deletions test/fabricators/authorization_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Fabricator(:authorization) do
uid { sequence(:uid) { |i| i } }
nickname "god"
provider "twitter"
oauth_token "abcd"
oauth_secret "efgh"
uid { sequence(:uid) { |i| i } }
nickname "god"
provider "twitter"
oauth_token "abcd"
oauth_secret "efgh"
user
end
4 changes: 2 additions & 2 deletions test/fabricators/update_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Fabricator(:update) do
text { sequence(:text) { |i| "This is update #{i}" } }
text { sequence(:text) { |i| "This is update #{i}" } }
twitter false
author
feed { |update| Fabricate(:feed, :author => update.author) }
feed { |update| Fabricate(:feed, :author => update.author) }
end
6 changes: 3 additions & 3 deletions test/fabricators/user_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Fabricator(:user) do
username { sequence(:username) { |i| "user_#{i}" } }
email { sequence(:email) { |i| "user_#{i}@example.com" } }
author { |a| Fabricate(:author, :username => a.username, :created_at => a.created_at, :email => a.email) }
username { sequence(:username) { |i| "user_#{i}" } }
email { sequence(:email) { |i| "user_#{i}@example.com" } }
author { |user| Fabricate(:author, :username => user.username, :created_at => user.created_at, :email => user.email) }
end
12 changes: 10 additions & 2 deletions test/models/author_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@
end

it "sets the use_ssl flag to true when https is used to create the author" do
author = Fabricate :author, :username => "james", :domain => "https://example.com", :email => nil, :image_url => nil, :created_at => 3.days.ago
author = Fabricate(:author, :username => "james",
:domain => "https://example.com",
:email => nil,
:image_url => nil,
:created_at => 3.days.ago)
assert_equal author.use_ssl, true
end

it "sets the use_ssl flag to false when http is used to create the author" do
author = Fabricate :author, :username => "james", :domain => "http://example.com", :email => nil, :image_url => nil, :created_at => 3.days.ago
author = Fabricate(:author, :username => "james",
:domain => "http://example.com",
:email => nil,
:image_url => nil,
:created_at => 3.days.ago)
assert_equal author.use_ssl, false
end

Expand Down

0 comments on commit 2120fb6

Please sign in to comment.