@@ -11,10 +11,9 @@ General
1111* Don't duplicate the functionality of a built-in library.
1212* Don't swallow exceptions or "fail silently."
1313* Don't write code that guesses at future functionality.
14- * [ Exceptions should be exceptional] .
14+ * Exceptions should be exceptional.
1515* [ Keep the code simple] .
1616
17- [ Exceptions should be exceptional ] : http://www.readability.com/~/yichhgvu
1817[ Keep the code simple ] : http://www.readability.com/~/ko2aqda2
1918
2019Object-Oriented Design
@@ -64,6 +63,7 @@ Ruby Gems
6463Rails
6564-----
6665
66+ * [ Add foreign key constraints] [ fkey ] in migrations.
6767* Avoid bypassing validations with methods like ` save(validate: false) ` ,
6868 ` update_attribute ` , and ` toggle ` .
6969* Avoid instantiating more than one object in controllers.
8787 patch level for a project.
8888* Use ` _url ` suffixes for named routes in mailer views and [ redirects] . Use
8989 ` _path ` suffixes for named routes everywhere else.
90+ * Use a [ class constant rather than the stringified class name] [ class constant in association ]
91+ for ` class_name ` options on ActiveRecord association macros.
9092* Validate the associated ` belongs_to ` object (` user ` ), not the database column
9193 (` user_id ` ).
9294* Use ` db/seeds.rb ` for data that is required in all environments.
@@ -97,17 +99,24 @@ Rails
9799* Prefer ` Time.zone.parse("2014-07-04 16:05:37") ` over ` Time.parse("2014-07-04 16:05:37") `
98100* Use ` ENV.fetch ` for environment variables instead of ` ENV[] ` so that unset
99101 environment variables are detected on deploy.
102+ * [ Use blocks] [ date-block ] when declaring date and time attributes in FactoryGirl factories.
103+ * Use ` touch: true ` when declaring ` belongs_to ` relationships.
100104
105+ [ date-block ] : /best-practices/samples/ruby.rb#L10
106+ [ fkey ] : http://robots.thoughtbot.com/referential-integrity-with-foreign-keys
101107[ `.ruby-version` ] : https://gist.github.com/fnichol/1912050
102108[ redirects ] : http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
103109[ Spring binstubs ] : https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
104110[ prevent tampering ] : http://blog.bigbinary.com/2013/03/19/cookies-on-rails.html
111+ [ class constant in association ] : https://github.com/thoughtbot/guides/blob/master/style/rails/sample.rb
105112
106113Testing
107114-------
108115
109116* Avoid ` any_instance ` in rspec-mocks and mocha. Prefer [ dependency injection] .
110- * Avoid ` its ` , ` let ` , ` let! ` , ` specify ` , and ` before ` in RSpec.
117+ * Avoid ` its ` , ` specify ` , and ` before ` in RSpec.
118+ * Avoid ` let ` (or ` let! ` ) in RSpec. Prefer extracting helper methods,
119+ but do not re-implement the functionality of ` let ` . [ Example] [ avoid-let ] .
111120* Avoid using ` subject ` explicitly * inside of an* RSpec ` it ` block.
112121 [ Example] [ subject-example ] .
113122* Avoid using instance variables in tests.
@@ -125,7 +134,8 @@ Testing
125134* Use non-[ SUT] methods in expectations when possible.
126135
127136[ dependency injection ] : http://en.wikipedia.org/wiki/Dependency_injection
128- [ explicit subject example ] : /style/samples/testing.rb#17
137+ [ subject-example ] : ../style/testing/unit_test_spec.rb
138+ [ avoid-let ] : ../style/testing/avoid_let_spec.rb
129139[ `Delayed::Job` matcher ] : https://gist.github.com/3186463
130140[ stubs and spies ] : http://robots.thoughtbot.com/post/159805295/spy-vs-spy
131141[ assertions about state ] : https://speakerdeck.com/skmetz/magic-tricks-of-testing-railsconf?slide=51
@@ -155,6 +165,9 @@ Postgres
155165* Consider a [ partial index] for queries on booleans.
156166* Constrain most columns as [ ` NOT NULL ` ] .
157167* [ Index foreign keys] .
168+ * Use an ` ORDER BY ` clause on queries where the results will be displayed to a
169+ user, as queries without one may return results in a changing, arbitrary
170+ order.
158171
159172[ `NOT NULL` ] : http://www.postgresql.org/docs/9.1/static/ddl-constraints.html#AEN2444
160173[ combines multiple indexes ] : http://www.postgresql.org/docs/9.1/static/indexes-bitmap-scans.html
@@ -173,17 +186,28 @@ Email
173186
174187* Use [ SendGrid] or [ Amazon SES] to deliver email in staging and production
175188 environments.
176- * Use a tool like [ MailView ] to look at each created or updated mailer view
177- before merging.
189+ * Use a tool like [ ActionMailer Preview ] to look at each created or updated mailer view
190+ before merging. Use [ MailView ] gem unless using Rails version 4.1.0 or later.
178191
179192[ Amazon SES ] : http://robots.thoughtbot.com/post/3105121049/delivering-email-with-amazon-ses-in-a-rails-3-app
180193[ SendGrid ] : https://devcenter.heroku.com/articles/sendgrid
181194[ MailView ] : https://github.com/37signals/mail_view
195+ [ ActionMailer Preview ] : http://api.rubyonrails.org/v4.1.0/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Previewing+emails
196+
197+ Web
198+ ---
199+
200+ * Avoid a Flash of Unstyled Text, even when no cache is available.
201+ * Avoid rendering delays caused by synchronous loading.
202+ * Use https instead of http when linking to assets.
182203
183204JavaScript
184205----------
206+ * Use the latest stable JavaScript syntax with a transpiler, such as [ babel] .
207+ * Include a ` to_param ` or ` href ` attribute when serializing ActiveRecord models,
208+ and use that when constructing URLs client side, rather than the ID.
185209
186- * Use CoffeeScript.
210+ [ babel ] : http://babeljs.io/
187211
188212HTML
189213----
196220---
197221
198222* Use Sass.
223+ * Use [ Autoprefixer] [ autoprefixer ] to generate vendor prefixes based on the
224+ project-specific browser support that is needed.
225+
226+ [ autoprefixer ] : https://github.com/postcss/autoprefixer
199227
200228Sass
201229----
209237Browsers
210238--------
211239
212- * Don't support clients without Javascript.
213- * Don't support IE6 or IE7.
240+ * Avoid supporting versions of Internet Explorer before IE10.
214241
215242Objective-C
216243-----------
@@ -291,6 +318,20 @@ Ember
291318* Don't use jQuery outside of views and components.
292319* Prefer to use predefined ` Ember.computed.* ` functions when possible.
293320* Use ` href="#" ` for links that have an action.
321+ * Prefer dependency injection through ` Ember.inject ` over initializers, globals
322+ on window, or namespaces. ([ sample] [ inject ] )
323+ * Prefer sub-routes over maintaining state.
324+ * Prefer explicit setting of boolean properties over ` toggleProperty ` .
325+ * Prefer testing your application with [ QUnit] [ ember-test-guides ] .
326+
327+ [ ember-test-guides ] : https://guides.emberjs.com/v2.2.0/testing/
328+
329+ Testing
330+
331+ * Prefer ` findWithAssert ` over ` find ` when fetching an element you expect to
332+ exist
333+
334+ [ inject ] : samples/ember.js#L1-L11
294335
295336Angular
296337-------
@@ -307,3 +348,18 @@ Angular
307348[ annotations ] : http://robots.thoughtbot.com/avoid-angularjs-dependency-annotation-with-rails
308349[ ngannotate ] : https://github.com/kikonen/ngannotate-rails
309350[ angular-translate ] : https://github.com/angular-translate/angular-translate/wiki/Getting-Started#using-translate-directive
351+
352+ Ruby JSON APIs
353+ --------------
354+
355+ * Review the recommended practices outlined in Heroku's [ HTTP API Design Guide]
356+ before designing a new API.
357+ * Use a fast JSON parser, e.g. [ ` oj ` ] [ oj ]
358+ * Write integration tests for your API endpoints. When the primary consumer of
359+ the API is a JavaScript client maintained within the same code base as the
360+ provider of the API, write [ feature specs] . Otherwise write [ request specs] .
361+
362+ [ HTTP API Design Guide ] : https://github.com/interagent/http-api-design
363+ [ oj ] : https://github.com/ohler55/oj
364+ [ feature specs ] : https://www.relishapp.com/rspec/rspec-rails/docs/feature-specs/feature-spec
365+ [ request specs ] : https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec
0 commit comments