Skip to content

Commit

Permalink
regenerate friendly id as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
scarroll32 committed Nov 14, 2016
1 parent 8ee15c2 commit f97ca68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def cache_rendered_markdown
end
end

def reset_friendly_id
if challenge_changed?
self.slug = 'poo'
end
end

def should_generate_new_friendly_id?
challenge_changed?
end


def valid_status
if self.status == :running
Expand Down
9 changes: 9 additions & 0 deletions spec/models/challenge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@
end
end

describe "friendly_id" do
it 'updates the slug when the challenge title changes' do
challenge = create(:challenge)
challenge.challenge = 'a new challenge title'
challenge.save!
expect(challenge.slug).to eq('a-new-challenge-title')
end
end


end
end

0 comments on commit f97ca68

Please sign in to comment.