Skip to content

Commit

Permalink
Merge pull request hotsh#401 from clnclarinet/fixing-errors
Browse files Browse the repository at this point in the history
Fixing errors
  • Loading branch information
steveklabnik committed Sep 26, 2011
2 parents 7e3bbfe + facc09f commit 1fc65f7
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 29 deletions.
20 changes: 10 additions & 10 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def destroy

@author = feed.author

# You're not allowed to follow yourself.
redirect_to request.referrer if @author.user == current_user

# If we're already following them, noop.
unless current_user.following_url? feed.url
if @author.user == current_user
# You're not allowed to follow yourself.
redirect_to request.referrer
elsif !current_user.following_url? feed.url
# If we're not following them, noop.
flash[:notice] = "You're not following #{@author.username}."
redirect_to request.referrer
end

current_user.unfollow! feed
else
current_user.unfollow! feed

flash[:notice] = "No longer following #{@author.username}."
redirect_to request.referrer
flash[:notice] = "No longer following #{@author.username}."
redirect_to request.referrer
end
end

# subscriber receives updates
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def update
if @user == current_user
response = @user.edit_user_profile(params)
if response == true
flash[:notice] = "Profile saved!"
redirect_to user_path(params[:id])

unless @user.email_confirmed
# Generate same token as password reset....
Expand All @@ -61,6 +59,8 @@ def update
flash[:notice] = "Profile saved!"
end

redirect_to user_path(params[:id])

else
flash[:notice] = "Profile could not be saved: #{response}"
render :edit
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def following_url? feed_url

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

Expand Down
17 changes: 15 additions & 2 deletions test/acceptance/acceptance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@ def log_in_email(user)
click_button "Log in"
end

def profile_bio
".info p.note"
def profile(section = nil)
case section
when "name"
"#profile h3.fn"
when "website"
"#profile .info .website"
when "bio"
"#profile .info p.note"
else
"#profile"
end
end

def flash
"#flash"
end
end
4 changes: 3 additions & 1 deletion test/acceptance/following_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
visit "/users/#{u.username}/following"
click_button "unfollow-#{u2.feed.id}"

assert_match "No longer following #{u2.username}", page.body
within flash do
assert has_content? "No longer following #{u2.username}"
end
end
end

Expand Down
117 changes: 105 additions & 12 deletions test/acceptance/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,113 @@
assert has_link? "Edit"
end

it "updates your profile" do
u = Factory(:user)
a = Factory(:authorization, :user => u)
log_in(u, a.uid)
visit "/users/#{u.username}/edit"
bio_text = "To be or not to be"
fill_in "bio", :with => bio_text
describe "updating" do
before do
Pony.deliveries.clear
@u = Factory(:user)
a = Factory(:authorization, :user => @u)
log_in(@u, a.uid)
end

VCR.use_cassette('update_profile') do
click_button "Save"
attributes_without_confirmation = {"name" => "Mark Zuckerberg",
"website" => "http://test.com",
"bio" => "To be or not to be"}

attributes_without_confirmation.each do |key, value|
it "updates your #{key}" do
visit "/users/#{@u.username}/edit"
fill_in key, :with => value

VCR.use_cassette("update_profile_#{key}") do
click_button "Save"
end

within profile(key) do
assert has_content?(value), "Cannot find #{key} with text #{value}"
end
end
end

within profile_bio do
assert has_content? bio_text
it "updates your password successfully" do
visit "/users/#{@u.username}/edit"
fill_in "password", :with => "new_password"
fill_in "password_confirm", :with => "new_password"

VCR.use_cassette("update_profile_password") do
click_button "Save"
end

within profile "name" do
assert has_content?(@u.author.name), "Password update failed"
end
end

it "does not update your password if the confirmation doesn't match" do
visit "/users/#{@u.username}/edit"
fill_in "password", :with => "new_password"
fill_in "password_confirm", :with => "bunk"

VCR.use_cassette("update_profile_password_mismatch") do
click_button "Save"
end

within flash do
assert has_content?("Profile could not be saved: Passwords must match")
end

assert has_field?("password")
end

it "verifies your email if you change it" do
visit "/users/#{@u.username}/edit"
email = "new_email@new_email.com"
fill_in "email", :with => email

VCR.use_cassette('update_profile_email') do
click_button "Save"
end

within profile "name" do
assert has_content? @u.author.name
end

assert_equal 1, Pony.deliveries.size
end

it "does not verify your email if you havent specified one" do
user_without_email = Factory(:user, :email => "", :username => "no_email")
a = Factory(:authorization, :user => user_without_email)

log_in(user_without_email, a.uid)
visit "/users/#{user_without_email.username}/edit"
name = "Mark Zuckerberg"
fill_in "name", :with => name

VCR.use_cassette('update_profile_no_email') do
click_button "Save"
end

within profile "name" do
assert has_content? name
end

assert Pony.deliveries.empty?
end

it "does not verify your email if you havent changed it" do
visit "/users/#{@u.username}/edit"
name = "Steve Jobs"
fill_in "name", :with => name

VCR.use_cassette('update_profile_no_email') do
click_button "Save"
end

within profile "name" do
assert has_content? name
end

assert Pony.deliveries.empty?
end
end

Expand All @@ -77,7 +170,7 @@
click_button "Save"
end

within profile_bio do
within profile "bio" do
assert has_content? bio_text
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

Factory.define :user do |u|
u.username { Factory.next(:usernames) }
u.author {|a| Factory(:author, :username => a.username, :created_at => a.created_at) }
u.email { Factory.next(:emails) }
u.author {|a| Factory(:author, :username => a.username, :created_at => a.created_at, :email => a.email) }
end

Factory.sequence :integer do |i|
Expand Down

0 comments on commit 1fc65f7

Please sign in to comment.