Permalink
Browse files

Merge pull request #715 from carols10cents/cleanup

Cleanup
  • Loading branch information...
2 parents 9464c48 + 2fafbdb commit 2120fb65fe79d273c67eab7d7258bf2f42a35244 @carols10cents carols10cents committed Dec 27, 2012
View
22 app/controllers/static_controller.rb
@@ -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
@@ -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
View
0 app/models/.gitkeep
No changes.
View
49 app/models/author.rb
@@ -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.
@@ -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
@@ -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
@@ -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']
@@ -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
View
44 app/models/feed.rb
@@ -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!
@@ -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
@@ -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
View
11 config/routes.rb
@@ -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
View
0 lib/tasks/.gitkeep
No changes.
View
0 log/.gitkeep
No changes.
View
8 test/acceptance/alps/message_test.rb
@@ -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"
View
12 test/fabricators/author_fabricator.rb
@@ -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
View
10 test/fabricators/authorization_fabricator.rb
@@ -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
View
4 test/fabricators/update_fabricator.rb
@@ -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
View
6 test/fabricators/user_fabricator.rb
@@ -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
View
12 test/models/author_test.rb
@@ -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

0 comments on commit 2120fb6

Please sign in to comment.