Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question error message duplicacy removed #2273

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def validate(record)
record.errors[:base] << "You may not use the title 'new'." # otherwise the below title uniqueness check fails, as title presence validation doesn't run until after
else
if !Node.where(path: record.generate_path).first.nil? && record.type == 'note'
record.errors[:base] << 'You have already used this title today.'
record.errors[:base] << 'You have already used this title.'
end
end
end
Expand Down Expand Up @@ -50,7 +50,6 @@ def updated_month

validates :title, presence: :true
validates_with UniqueUrlValidator, on: :create
validates :path, uniqueness: { message: 'This title has already been taken' }

# making drupal and rails database conventions play nice;
# 'changed' is a reserved word in rails
Expand Down Expand Up @@ -172,7 +171,7 @@ def answered
def has_accepted_answers
self.answers.where(accepted: true).count.positive?
end

# users who like this node
def likers
node_selections
Expand Down Expand Up @@ -817,23 +816,23 @@ def is_liked_by(user)
def toggle_like(user)
nodes = NodeSelection.where(nid: self.id , liking: true).count
if is_liked_by(user)
self.cached_likes = nodes-1
self.cached_likes = nodes-1
else
self.cached_likes = nodes+1
self.cached_likes = nodes+1
end
end

def self.like(nid , user)
# scope like variable outside the transaction
like = nil
count = nil

ActiveRecord::Base.transaction do
# Create the entry if it isn't already created.
like = NodeSelection.where(user_id: user.uid,
nid: nid).first_or_create
like.liking = true
node = Node.find(nid)
node = Node.find(nid)
if node.type == 'note'
SubscriptionMailer.notify_note_liked(node, like.user)
end
Expand All @@ -849,17 +848,17 @@ def self.like(nid , user)
def self.unlike(nid , user)
like = nil
count = nil

ActiveRecord::Base.transaction do
like = NodeSelection.where(user_id: user.uid,
nid: nid).first_or_create
like.liking = false
count = -1
node = Node.find(nid)
count = -1
node = Node.find(nid)
node.toggle_like(like.user)
node.save!
like.save!
end
end
count
end
end
13 changes: 6 additions & 7 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def teardown
assert_not_nil @response.body
assert_equal '/notes/Bob/' + Time.now.strftime('%m-%d-%Y') + '/a-completely-unique-snowflake', @response.body
end

test 'post_note_error_no_title_xhr' do
UserSession.create(users(:bob))

Expand All @@ -353,7 +353,6 @@ def teardown

assert_response :success
assert_not_nil @response.body
assert_equal "{\"title\":[\"can't be blank\"],\"path\":[\"This title has already been taken\"]}", @response.body
end

test 'returning json errors on xhr note update' do
Expand Down Expand Up @@ -586,7 +585,7 @@ def teardown
end

assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s
end
end

test "should not delete wiki if other author have contributed" do
node = nodes(:about)
Expand All @@ -597,9 +596,9 @@ def teardown
assert_no_difference 'Node.count' do
get :delete, id: node.nid
end

assert_redirected_to '/dashboard' + '?_=' + Time.now.to_i.to_s
end
end

#should change title
test 'title change feature in comments when author is logged in' do
Expand All @@ -609,7 +608,7 @@ def teardown
assert_redirected_to node.path+"#comments"
assert_equal node.reload.title, 'changed title'
end

# should not change title
test 'title change feature in comments when author is not logged in' do
node = nodes(:one)
Expand All @@ -621,7 +620,7 @@ def teardown

def test_get_rss_feed
get :rss, :format => "rss"
assert_response :success
assert_response :success
assert_equal 'application/rss+xml', @response.content_type
end

Expand Down