Revisions

gist: 166634 Download_button fork
public
Public Clone URL: git://gist.github.com/166634.git
Embed All Files: show embed
customer_helper.rb #
1
2
3
4
5
module Admin::CustomerHelper
  def customer_breadcrumbs(customer)
    link_to(h(customer.name), [:edit, :admin, customer]) + " » "
  end
end
customer_test_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "test_helper"
 
class Admin::CustomerHelperTest < ActionView::TestCaseWithControllerAssertions
  context "customer_breadcrumbs" do
    setup { @customer = Factory(:customer) }
 
    should "generate a link" do
      with_content(customer_breadcrumbs(@customer)) do
        assert_select "a[href=?]", edit_admin_customer_path(@customer), @customer.name
        # yes, assertions other than assert_select work within this block
        assert_tag :a,
                    :attributes => {:href => edit_admin_customer_path(@customer)},
                    :content => @customer.name
      end
    end
 
    should "include the proper separator" do
      assert_match %r( &#187; ), customer_breadcrumbs(@customer)
    end
  end
end
test_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
# etc.
 
class ActionView::TestCaseWithControllerAssertions < ActionView::TestCase
  protected
  def with_content(content, content_type = "html")
    @response = stub_everything(:content_type => content_type, :body => content)
    yield if block_given?
  end
end