Skip to content

Commit

Permalink
Split User#following? into User.following_author? and User.following_…
Browse files Browse the repository at this point in the history
…url?
  • Loading branch information
carols10cents committed Aug 31, 2011
1 parent 0b46331 commit 425e8ab
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/salmon_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def feeds
# A notification that somebody is now following our user
elsif action == :follow
if user
if not user.following? author.feed.remote_url
if not user.following_author? author
user.followed_by! author.feed
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def destroy
redirect_to request.referrer if @author.user == current_user

# If we're already following them, noop.
unless current_user.following? feed.url
unless current_user.following_url? feed.url
flash[:notice] = "You're not following #{@author.username}."
redirect_to request.referrer
end
Expand Down Expand Up @@ -109,7 +109,7 @@ def create
end

# If we're already following them, noop
if current_user.following? feed_url
if current_user.following_url? feed_url
feed = Feed.first(:remote_url => feed_url)
if feed.nil? and feed_url.start_with?("/")
feed_id = feed_url[/^\/feeds\/(.+)$/,1]
Expand Down
2 changes: 1 addition & 1 deletion app/models/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_mentions
# look at who they are following
if a.nil? and user = self.author.user
authors.each do |author|
if user.following?(author.remote_url)
if user.following_author?(author)
a = author
end
end
Expand Down
10 changes: 8 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,25 @@ def followed_by? feed_url
end
end

def following? feed_url
def following_author? author
following.include?(author.feed)
end

def following_url? feed_url
# Handle possibly created multiple feeds for the same remote_url
existing_feeds = Feed.all(:remote_url => feed_url)

# local feed?
if existing_feeds.empty? and feed_url[0].chr == "/"
if existing_feeds.empty? and feed_url.start_with?("http://#{author.domain}/")
feed_id = feed_url[/^\/feeds\/(.+)$/,1]
existing_feeds = [Feed.first(:id => feed_id)]
end

if existing_feeds.empty?
false
else
# Intersect the feeds we're following and the possibly
# created multiple feeds for the remote
!(following & existing_feeds).empty?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_list.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- if current_user && current_user.feed != author.feed && author.feed
/ - unfollow_url = author.feed.local? ? "/users/#{author.username}/unfollow" : "/feeds/#{author.feed.id}/unsubscribe"
- following = current_user.following?(author.feed.url)
- following = current_user.following_author?(author)
.follow{:class => (following ? "negative" : "positive")}
- if following
= form_tag "/subscriptions/#{author.feed.id}" do
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.follow-wrap
- unless current_user and @author.user == current_user
#follow
- if current_user and current_user.following? @author.feed.url
- if current_user and current_user.following_author? @author
.negative
= form_tag "/subscriptions/#{@author.feed.id}" do
%input{:type => "hidden", :name => "_method", :value => "delete"}
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/fixdb.rake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace :fixdb do
desc "Fix any users who are following themselves"
task :unfollow_self => :environment do
User.find_each do |user|
if user.following? user.feed.url
if user.following_url? user.feed.url
user.unfollow! user.feed
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/following_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
describe "yourself" do
it "doesn't make you follow yourself after signing up" do
u = Factory(:user)
refute u.following? u.feed.url
refute u.following_url? u.feed.url
end

it "disallows following yourself" do
u = Factory(:user)
u.follow! u.feed.url
refute u.following? u.feed.url
refute u.following_url? u.feed.url
end
end

Expand Down

0 comments on commit 425e8ab

Please sign in to comment.