Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

FIS Day22

HTTParty

Rant

  • Conway’s law
    • organizational communication will be reflected in the product

seagull architect -

comes in, shits all over your code and then leaves

Insufficiency of good design

Open source: def up and down in migration.rb in rails can be refactored

POTD

Joseph Weizenbaum

Rails Lecture

Controller Test Continued from Day21…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'spec_helper'

describe SongsController do
  describe 'POST /songs' do

    it 'should create a song with a name' do
      post :create, {:song => {:name => "Thriller"}}

      assigns(:song).name.should == "Thriller"
    end

    it 'should create a song with an artist name' do
      post :create, {:song => {:name => "Thriller", :artist_name => "Michael Jackson"}}

      assigns(:song).artist_name.should == "Michael Jackson"
    end

    it "should create a song with a genre string" do
      post :create, {:song => {:name => "Thriller", :genre_names => "Pop"}}

      assigns(:song).genre_names.should include("Pop")
    end


    it "should create a song with a genres from a CSV string" do
      post :create, {:song => {:name => "Thriller", :genre_names => "Pop, Techno"}}

      assigns(:song).genre_names.should include("Pop")
    end

    it "should create a song with a genre array containing CSV string" do
      post :create, {:song => {:name => "Thriller", :genre_names => ["Pop, Techno", "Rap"]}}

      assigns(:song).genre_names.should include("Pop")
    end

  end
end
song_spec.rb Unit Test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'

describe Song do
  let(:song){Song.new(:name => "Thriller")}

  context 'with genres' do
    let(:genre){Genre.create(:name => "Pop")}

    context '.genre_names' do
      it "should return an array of genre names" do
        song.genres << genre
        song.save


        song.genre_names.should be_an_instance_of(Array)
        song.genre_names.should include("Pop")
      end

      it "should accept a genre name and add that genre" do
        song.genre_names = "Techno"
        song.save

        song.genre_names.should include("Techno")
      end

      it "should accept a comma delimited list of genre names" do
        song.genre_names = "Techno, Pop"
        song.save

        song.genre_names.should include("Techno", "Pop")
      end

      it "should accept an array containing comma delimited list of genre names" do
        song.genre_names = ["Techno, Pop", "Rap"]
        song.save

        song.genre_names.should include("Techno", "Pop", "Rap")
      end

      it "should only add unique genres" do
        song.genre_names = ["Pop", "Pop"]
        song.save

        song.genre_names.count.should == 1
      end

    end

rake spec:models

gem file
1
2
3
group [:development, :test] do
  gem 'debugger'
end
  • detect returns nil if there is not match
  • select returns an empty array when no match

to_sentence method in rails

HTML < form_tag lower < form_for

form_tag

gem file
1
2
3
4
5
6
7
8
9
10
11
12
13
<form action="/songs" id="new_song" class="new_song"> <form>

<%= form_tag(songs_path, :id => "new song") do %>
  <%= text_field_tag "song[name]", @song.name, :id => "song_name"] %>
  <%= text_field_tag "song[artist_name]", @song.artist_name, :id => "song_artist_name"] %>
  <%= submit_tag "Create Song", :id => "create_song" %>
<% end %>

<%= form_for(@song) do |f| %>
  <%= f.text_field :name %>
  <%= f.text_field :artist_name %>
  <%= f.submit %>
<% end %>

text_field_tag docs

Integration test / Acceptance Test

Continuous Integration / Testing

  • autotest
  • guard
  • rb-fsevent -> rb-FileSaveEvent -> gem that pings guard (or anything else) when a file is saved
  • growl extension or terminal notifier on the guard gem page
  • capybara

receiver.try(:method) -> if the receiver is nil then try will not call the method, otherwise it will

Pull down the other app

git merge upstream/master

Comments