The purpose of this guide is to document potential "gotchas" that contributors might encounter or should avoid during development of GitSwarm CE and EE.
describe
symbolsConsider the following model spec:
require 'rails_helper'
describe User do
describe :to_param do
it 'converts the username to a param' do
user = described_class.new(username: 'John Smith')
expect(user.to_param).to eq 'john-smith'
end
end
end
When run, this spec doesn't do what we might expect:
spec/models/user_spec.rb|6 error| Failure/Error: u = described_class.new NoMethodError: undefined method `new' for :to_param:Symbol
Except for the top-level describe
block, always provide a String argument to describe
.
rescue Exception
See "Why is it bad style to rescue Exception => e
in Ruby?".
Note: This rule is enforced automatically by Rubocop.
Using the inline :coffee
or :coffeescript
Haml filters comes with a performance overhead.
Note: We've removed these two filters in an initializer.
Normally, because HTML id
attributes need to be unique to the page, it's perfectly fine to write some JavaScript like the following:
$('#js-my-selector').hide();
However, there's a feature of GitSwarm's Markdown processing that automatically adds anchors to header elements, with the id
attribute being automatically generated based on the content of the header.
Unfortunately, this feature makes it possible for user-generated content to create a header element with the same id
attribute we're using in our selector, potentially breaking the JavaScript behavior. A user could break the above example with the following Markdown:
## JS My Selector
Which gets converted to the following HTML:
<h2>
<a id="js-my-selector" class="anchor" href="#js-my-selector" aria-hidden="true"></a>
JS My Selector
</h2>
The current recommended fix for this is to make our selectors slightly more specific:
$('div#js-my-selector').hide();