background preloader

Testingrailsja

Facebook Twitter

Osx snow leopard - PostgreSQL error 'Could not connect to server: No such file or directory' Three Battle Tested Ways to Install PostgreSQL. PostgreSQL is a relational database manager, and it keeps getting more and more popular within the web development community.

Three Battle Tested Ways to Install PostgreSQL

It has taken over from MySQL as the preferred tool for production quality, scalable databases. The rise in popularity is likely due to the backlash from Oracle purchasing and messing with MySQL, Heroku choosing Postgres as the preferred database in production, and Postgres' faster introduction of new features like Arrays and HStore. How to install on - Mac OS X - Windows - Ubuntu How to Install Postgres on Mac OS X This guide will show you how to install PostgreSQL, the easy way, on a Mac. There are a lot of confusing options for installing PostgreSQL. The most popular package manager for Mac OS X, and the one I prefer, is homebrew. If you have MacPorts or Fink installed, this tutorial won't work for you. Open up the Terminal You'll need to use the command line interface to complete many of these steps.

Rails Misapprehensions: Helpers are shit. When I started using Rails years ago I found helpers extremely cool.

Rails Misapprehensions: Helpers are shit.

I could call a method in a view and it would help me by doing something. The method was simply there, no need to worry about its source and how to access it, just call it. I got older, wiser, and more opinionated. I still like the concept of helpers – of methods. How to use concerns in Rails 4. Code Concerns in Rails 4 Models - RichOnRails.com. Ruby on Rails Concerns This tutorial will teach you how to use ActiveModel concerns in Ruby on Rails.

Code Concerns in Rails 4 Models - RichOnRails.com

Guides Rake Tasks - Padrino Ruby Web Framework. After generating a new padrino project, you will not find any Rakefile in your generated project folder structure; in fact it’s not strictly needed to build a new one because we can already use padrino rake: padrino rake # or for a list of tasks padrino rake -T If you need custom tasks you can add those to: your_project/lib/tasksyour_project/tasksyour_project/testyour_project/spec Padrino will look recursively for any *.rake file in any of these directories.

Guides Rake Tasks - Padrino Ruby Web Framework

Padrino by default has some useful tasks. Basic Like other frameworks we have an :environment task that loads our environment and apps. . # This is a custom task# task/version.raketask :version => :environment do puts Padrino.versionend. Customizing Rake Tasks In Rails 4.1 And Higher - CustomInk Technology Blog. I have been overriding, invoking, and executing custom Rake tasks since I was an early Ruby developer.

Customizing Rake Tasks In Rails 4.1 And Higher - CustomInk Technology Blog

Tweaking your project's automated tasks are likely the closest thing Rails developers come to building their own light saber. Most popular are adding or changing how the Rails test suite behaves. For example, adding Capybara to your project. Recently I have been upgrading projects from 3.2 to 4.2 and one thing that really stood out to me was how Rails testing tasks are created and run.

Most obvious is that the default test task now runs all model, controller, mailer, helper, job, and integration tests in a single process now. IntegrationTest. An integration test spans multiple controllers and actions, tying them all together to ensure they work together as expected.

IntegrationTest

It tests more completely than either unit or functional tests do, exercising the entire stack, from the dispatcher to the database. At its simplest, you simply extend IntegrationTest and write your tests using the get/post methods: require "test_helper" class ExampleTest < ActionDispatch::IntegrationTest fixtures :people def test_login get "/login" assert_equal 200, status post "/login", username: people(:jamis).username, password: people(:jamis).password follow_redirect!

Assert_equal 200, status assert_equal "/home", path endend However, you can also have multiple session instances open per test, and even extend those instances with assertions and methods to create a very powerful testing DSL that is specific for your application. Methods document_root_element url_options Included Modules. Using Rails Helpers inside a Controller. Rails helpers are designed to be used inside views, but sometimes you might want the functionality from a helper inside your controller.

Using Rails Helpers inside a Controller

For example, you might be generating a simple JSON string and you want to use a view helper to format some element of the JSON. One way of doing this would be to include the helper directly into the controller (by simply doing include HelperName). I’m not a big fan of this approach since this includes all the helper’s methods in all your controller actions. Another approach (which I prefer) is to declare the helper method as a class function and then simply reference the helper directly in your controller. class MyController < ApplicationController def action @url = UrlHelper.generate_url(current_user) endend Of course, helper methods are not declared as class methods which means this code sample will fail. Three quick Rails console tips by Nick of Basecamp. I was bouncing around the Rails API documentation yesterday, and I noticed a few rails console tricks I haven’t seen before.

Three quick Rails console tips by Nick of Basecamp

There’s been plenty of posts about irb and Rails before, but I’m hoping you’ll learn something new here. The following console samples were taken with Basecamp Next on Rails version 3.2.3. Dive into your app Running the app method in rails console gives you an integration session instance, so you can use it just like when you’re a normal integration test for Rails. >> app.class => ActionDispatch::Integration::Session. JavaScript Test-Driven Development with Rails 4 & Konacha. At Contactually, our app’s back-end is written in Rails 4, while most of the front-end is a Single-Page Application (SPA) written in JavaScript, using Backbone.js, Marionette.js, and a number of JavaScript plugins.

JavaScript Test-Driven Development with Rails 4 & Konacha

On the back-end, we have a suite of RSpec unit specs and Capybara acceptance specs to make sure everything works on the back-end. When I joined Contactually in September 2014, the front-end code didn’t have any unit tests – everything was tested manually by traditional QA processes. In our app, there’s a lot of business logic between different objects.

A User has many Contacts and GroupingsA Contact can be in many Groupings, but only certain subtypes of Grouping, such as BucketsA Grouping can belong to many UsersA Domain can have many Users, and many GroupingsEtc. Almost all of this logic is spec’ed out and verified by RSpec and Capybara specs, but a lot of the same business logic on the client-side was not, which led to hard-to-find bugs in the Backbone app.