Skip to content
This repository
Browse code

Merge pull request #715 from carols10cents/cleanup

Cleanup
  • Loading branch information...
commit 2120fb65fe79d273c67eab7d7258bf2f42a35244 2 parents 9464c48 + 2fafbdb
Carol Nichols carols10cents authored
22 app/controllers/static_controller.rb
... ... @@ -1,15 +1,6 @@
1 1 class StaticController < ApplicationController
2 2 before_filter :require_user, :only => :follow
3 3
4   - def homepage
5   - @list_class = ""
6   - render :layout => false
7   - end
8   -
9   - def open_source
10   - @title = "open source"
11   - end
12   -
13 4 def about
14 5 @title = "about us"
15 6 end
@@ -21,4 +12,17 @@ def contact
21 12 def follow
22 13 @title = "follow a user"
23 14 end
  15 +
  16 + def help
  17 + end
  18 +
  19 + def homepage
  20 + @list_class = ""
  21 + render :layout => false
  22 + end
  23 +
  24 + def open_source
  25 + @title = "open source"
  26 + end
  27 +
24 28 end
0  app/models/.gitkeep
No changes.
49 app/models/author.rb
@@ -15,8 +15,10 @@ class Author
15 15 # public keys are good for 4 weeks
16 16 PUBLIC_KEY_LEASE_DAYS = 28
17 17
  18 + # Schema
  19 +
18 20 # We've got a bunch of data that gets stored in Author. And basically none
19   - # of it is val*idated right now. Fun. Then again, not all of it is neccesary.
  21 + # of it is validated right now. Fun. Then again, not all of it is neccesary.
20 22 key :username, String
21 23
22 24 # This contains the domain that the author's feed originates.
@@ -25,18 +27,6 @@ class Author
25 27 # When true, this author wishes ssl and https to be used for their endpoints
26 28 key :use_ssl, Boolean
27 29
28   - validates_presence_of :domain
29   -
30   - # Normalize the domain so we can use them the same way
31   - before_save :normalize_domain
32   -
33   - # Make sure the image url uses https
34   - before_save :https_image_url
35   -
36   - # Twitter has an SSL cert that doesn't match the domain but we can
37   - # change the domain to match the cert and the avatars work
38   - before_save :modify_twitter_image_url_domain
39   -
40 30 # The Author has a profile and with that various entries
41 31 key :name, String
42 32 key :email, String
@@ -60,6 +50,9 @@ class Author
60 50 # For sorting by signup, Authors require timestamps
61 51 timestamps!
62 52
  53 + # Validations
  54 +
  55 + validates_presence_of :domain
63 56 # We cannot put a :unique tag above because of a MongoMapper bug
64 57 validates_uniqueness_of :remote_url, :allow_nil => :true
65 58
@@ -70,9 +63,20 @@ class Author
70 63 one :feed, :dependent => :destroy
71 64 one :user
72 65
  66 + # Callbacks
  67 +
  68 + # Normalize the domain so we can use them the same way
  69 + before_save :normalize_domain
  70 +
  71 + # Make sure the image url uses https
  72 + before_save :https_image_url
  73 +
  74 + # Twitter has an SSL cert that doesn't match the domain but we can
  75 + # change the domain to match the cert and the avatars work
  76 + before_save :modify_twitter_image_url_domain
  77 +
73 78 # This takes results from an omniauth reponse and generates an author
74 79 def self.create_from_hash!(hash, domain)
75   -
76 80 # Omniauth user information, as a hash
77 81 user = hash['info']
78 82
@@ -236,20 +240,21 @@ def to_atom
236 240 :uri => author_url,
237 241 :portable_contacts => poco,
238 242 :links => [Atom::Link.new(:rel => "avatar",
239   - :type => "image/png",
240   - :href => avatar_url_abs)])
241   -
  243 + :type => "image/png",
  244 + :href => avatar_url_abs)])
242 245 author
243 246 end
244 247
245 248 def normalize_domain
246 249 set_default_use_ssl if use_ssl.nil?
247 250
248   - norm = self.domain.gsub(/^.*:\/\//, "")
249   - norm = norm.gsub(/^www./, "")
250   - norm = norm.gsub(/\/.*$/, "")
251   - norm = norm.gsub(/\?.*$/, "")
252   - norm = norm.gsub(/#.*$/, "")
  251 + norm = self.domain
  252 + norm = norm.gsub(/^.*:\/\//, "") # remove protocol
  253 + norm = norm.gsub(/^www./, "") # remove www
  254 + norm = norm.gsub(/\/.*$/, "") # remove trailing slash
  255 + norm = norm.gsub(/\?.*$/, "") # remove query string
  256 + norm = norm.gsub(/#.*$/, "") # remove anchors
  257 +
253 258 self.domain = norm
254 259 end
255 260
44 app/models/feed.rb
@@ -14,21 +14,18 @@ class Feed
14 14
15 15 include MongoMapper::Document
16 16
17   - # Feed url (and an indicator that it is local if this is nil)
18   - key :remote_url, String
19   -
20   - # OStatus subscriber information
21   - key :verify_token, String
22   - key :secret, String
23   -
24   - # For both pubs and subs, it needs to know what hubs the feed is in
25   - # communication with in order to control pub/sub operations
26   - key :hubs, Array
27   -
28   - belongs_to :author
29   - key :author_id, ObjectId
30   -
31   - many :updates, :order => 'created_at desc', :dependent => :destroy
  17 + key :remote_url, String # Feed url (and an indicator that it is local if
  18 + # this is nil)
  19 + key :verify_token, String # OStatus subscriber information
  20 + key :secret, String # OStatus subscriber information
  21 + key :hubs, Array # For both pubs and subs, it needs to know what
  22 + # hubs the feed is in
  23 + # communication with in order to control pub/sub
  24 + # operations
  25 + key :author_id, ObjectId # Association key
  26 +
  27 + belongs_to :author
  28 + many :updates, :order => 'created_at desc', :dependent => :destroy
32 29
33 30 timestamps!
34 31
@@ -54,7 +51,7 @@ def populate(finger_data)
54 51 self.verify_token = SecureRandom.hex
55 52 self.secret = SecureRandom.hex
56 53
57   - ostatus_feed = OStatus::Feed.from_url(url)
  54 + ostatus_feed = OStatus::Feed.from_url(url)
58 55
59 56 avatar_url = ostatus_feed.icon
60 57 if avatar_url == nil
@@ -63,19 +60,18 @@ def populate(finger_data)
63 60
64 61 a = ostatus_feed.author
65 62
66   - self.author = Author.create(:name => a.portable_contacts.display_name,
67   - :username => a.name,
68   - :email => a.email,
  63 + self.author = Author.create(:name => a.portable_contacts.display_name,
  64 + :username => a.name,
  65 + :email => a.email,
69 66 :remote_url => a.uri,
70   - :domain => a.uri,
  67 + :domain => a.uri,
71 68 :salmon_url => ostatus_feed.salmon,
72   - :bio => a.portable_contacts.note,
73   - :image_url => avatar_url)
  69 + :bio => a.portable_contacts.note,
  70 + :image_url => avatar_url)
74 71
75   - if(finger_data)
  72 + if finger_data
76 73 self.author.public_key = finger_data.public_key
77 74 self.author.reset_key_lease
78   -
79 75 self.author.salmon_url = finger_data.salmon_url
80 76 self.author.save
81 77 end
11 config/routes.rb
@@ -7,13 +7,12 @@
7 7 match "/login", :to => "sessions#new"
8 8 match "/logout", :to => "sessions#destroy", :via => :post
9 9
10   - match "/follow", :to => "static#follow", :via => :get
11   -
12 10 # Static
13   - match "contact" => "static#contact"
14   - match "about" => "static#about"
15   - match "open_source" => "static#open_source"
16   - match "help" => "static#help"
  11 + match "about", :to => "static#about"
  12 + match "contact", :to => "static#contact"
  13 + match "follow", :to => "static#follow", :via => :get
  14 + match "help", :to => "static#help"
  15 + match "open_source", :to => "static#open_source"
17 16
18 17 # External Auth
19 18 # If we add more valid auth providers, they will need to be added
0  lib/tasks/.gitkeep
No changes.
0  log/.gitkeep
No changes.
8 test/acceptance/alps/message_test.rb
@@ -6,12 +6,8 @@
6 6
7 7 before do
8 8 @a_user = Fabricate(:user)
9   - @an_update = Fabricate(:update,
10   - :author => @a_user.author,
11   - :created_at => Time.parse(
12   - "Jan 1, 2012 09:34:16 UTC"
13   - )
14   - )
  9 + @an_update = Fabricate(:update, :author => @a_user.author,
  10 + :created_at => Time.parse("Jan 1, 2012 09:34:16 UTC"))
15 11 @a_user.feed.updates << @an_update
16 12
17 13 visit "/updates"
12 test/fabricators/author_fabricator.rb
... ... @@ -1,9 +1,9 @@
1 1 Fabricator(:author) do
2 2 feed { |author| Fabricate(:feed, :author => author) }
3   - username "user"
4   - email { sequence(:email) { |i| "user_#{i}@example.com" } }
5   - website "http://example.com"
6   - domain "http://foo.example.com"
7   - name "Something"
8   - bio "Hi, I do stuff."
  3 + username "user"
  4 + email { sequence(:email) { |i| "user_#{i}@example.com" } }
  5 + website "http://example.com"
  6 + domain "http://foo.example.com"
  7 + name "Something"
  8 + bio "Hi, I do stuff."
9 9 end
10 test/fabricators/authorization_fabricator.rb
... ... @@ -1,8 +1,8 @@
1 1 Fabricator(:authorization) do
2   - uid { sequence(:uid) { |i| i } }
3   - nickname "god"
4   - provider "twitter"
5   - oauth_token "abcd"
6   - oauth_secret "efgh"
  2 + uid { sequence(:uid) { |i| i } }
  3 + nickname "god"
  4 + provider "twitter"
  5 + oauth_token "abcd"
  6 + oauth_secret "efgh"
7 7 user
8 8 end
4 test/fabricators/update_fabricator.rb
... ... @@ -1,6 +1,6 @@
1 1 Fabricator(:update) do
2   - text { sequence(:text) { |i| "This is update #{i}" } }
  2 + text { sequence(:text) { |i| "This is update #{i}" } }
3 3 twitter false
4 4 author
5   - feed { |update| Fabricate(:feed, :author => update.author) }
  5 + feed { |update| Fabricate(:feed, :author => update.author) }
6 6 end
6 test/fabricators/user_fabricator.rb
... ... @@ -1,5 +1,5 @@
1 1 Fabricator(:user) do
2   - username { sequence(:username) { |i| "user_#{i}" } }
3   - email { sequence(:email) { |i| "user_#{i}@example.com" } }
4   - author { |a| Fabricate(:author, :username => a.username, :created_at => a.created_at, :email => a.email) }
  2 + username { sequence(:username) { |i| "user_#{i}" } }
  3 + email { sequence(:email) { |i| "user_#{i}@example.com" } }
  4 + author { |user| Fabricate(:author, :username => user.username, :created_at => user.created_at, :email => user.email) }
5 5 end
12 test/models/author_test.rb
@@ -37,12 +37,20 @@
37 37 end
38 38
39 39 it "sets the use_ssl flag to true when https is used to create the author" do
40   - author = Fabricate :author, :username => "james", :domain => "https://example.com", :email => nil, :image_url => nil, :created_at => 3.days.ago
  40 + author = Fabricate(:author, :username => "james",
  41 + :domain => "https://example.com",
  42 + :email => nil,
  43 + :image_url => nil,
  44 + :created_at => 3.days.ago)
41 45 assert_equal author.use_ssl, true
42 46 end
43 47
44 48 it "sets the use_ssl flag to false when http is used to create the author" do
45   - author = Fabricate :author, :username => "james", :domain => "http://example.com", :email => nil, :image_url => nil, :created_at => 3.days.ago
  49 + author = Fabricate(:author, :username => "james",
  50 + :domain => "http://example.com",
  51 + :email => nil,
  52 + :image_url => nil,
  53 + :created_at => 3.days.ago)
46 54 assert_equal author.use_ssl, false
47 55 end
48 56

0 comments on commit 2120fb6

Please sign in to comment.
Something went wrong with that request. Please try again.