Voting Specs
01 Jul 2016
Reading time ~2 minutes
What I Did
- Today I further refactored controller related things mostly in
comments_controller.rb
andvotes_controller.rb
. - I wrote integration tests for up/down voting for the simple case in which a given post has no votes currently.
What I Learned
- JavaScript-related goodness
- JavaScript can make requests to a server, parse it’s response and update parts of a page, effectively bypassing the typical request-response cycle, allowing for slick, front-end interactions.
- CoffeeScript is a small language that conveniently compiles into JavaScript.
- Unobtrusive JavaScript is a general approach to the use of JavaScript in web pages including separation of functionality from a Web page’s structure/content and presentation. Ajax is predicated by unobtrusive JavaScript. Ajax can be triggered by setting the attribute
data-remote: true
within a given form.
- Object-relational mapping (ORM) - is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates a virtual object database that can be used from within the programming language. ActiveRecord is the default object-relational mapping library for Rails.
- Memoization is the process of storing a computed value to avoid duplicated work by future calls. This is a handy technique for accessing instance variables in much less time than allowing however many lines of code within a given method to run each time one seeks to retrieve a oft-required variable.
- Session and params are only available to the controller. Specs are do not have access (inherently) to these resources.
- Setting null constraints on text columns may generate problems down the line (especially when working with MySQL).
- FactoryGirl traits allows for unique factories to be generated efficiently.
- Pry and the Capybara save_and_open_page method are the best thing to ever happen to Ruby on Rails.
- Implementing a counter cache when appropriate is a good alternative to excessive database access through repetitive SQL calls.
What I Still Don’t Understand
- After rebasing a given branch with another, I’ve been simply force pushing the updated branch to GitHub, and I’m not sure if there is a more appropriate action to take (although I’m suspicious there is).
What I’d Like To Learn
- I’d like to get more and more familiar with the internal of Ruby and Rails, because I feel that my surface level understanding is fine and dandy for a link aggregator site, but won’t do me enough good for debugging a full-scale production site that is actually heavily utilized in real life.