Hi All,

I just started incorporating a mobile MIME format into my websites to
account for mobile phone technologies visiting my pages.  I decided to
share a functional controller test for requesting the mobile mime type
and asserting if it finds a particular div selector.

This test case can be applied to Ryan Bates' screencast on mobile
devices:

http://railscasts.com/episodes/199-mobile-devices

To make things easier, I've posted the entire test case here:

https://gist.github.com/980857

The main test is:

# When requesting mobile you can set the request environment two ways
# @request.env['HTTP_ACCEPT'] = "mobile"
# OR
# @request.accept = "mobile"
require 'test_helper'

class HomeControllerTest < ActionController::TestCase
  test "should get mobile index" do
    @request.accept = "mobile"
    get :index
    assert_response :success
    assert_select "div[data-role=header]" do
      assert_select 'h1', 'Your Header Title'
    end
  end
end

In your config/initializers/mime_types.rb you would have:

Mime::Type.register_alias "text/html", :mobile

And in your views/home/ you would have an ERB view for index.mobile.erb
that contains something similar:

<div data-role="header">
  <h1>Your Header Title</h1>
</div>

I'm using JQMobile so the mobile divs are using a data-role identifier
for header, content, footer, etc.  Tailor this to your own needs.  I
hope this helps someone down the road.

Take care.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to