require 'spec_helper' describe HomeController do render_views it 'renders default field' do get :default_fields response.should be_success assert_select "form[class=?]", /form-horizontal/ do assert_select "div.control-group" do assert_select 'label.control-label', 'Email' assert_select 'div.controls' do assert_select 'input[type=email]' end end assert_select "div.control-group" do assert_select 'label.control-label', 'Avatar' assert_select 'div.controls' do assert_select 'input[type=file]' end end assert_select "div.control-group" do assert_select 'label.control-label', 'Password' assert_select 'div.controls' do assert_select 'input[type=password]' end end assert_select "div.control-group" do assert_select 'label.control-label', 'Motto' assert_select 'div.controls' do assert_select 'input[type=text]' end end assert_select "div.control-group" do assert_select 'label.control-label', 'About' assert_select 'div.controls' do assert_select 'textarea[rows=?][cols=?]', 7, 40 end end assert_select "div.control-group" do assert_select 'label.control-label', 'Role' assert_select 'div.controls' do assert_select 'select' end end assert_select "div.control-group" do assert_select 'label.control-label', 'Remember me' assert_select 'div.controls' do assert_select 'label.checkbox' do assert_select 'input[type=hidden][value=?]', 0 assert_select 'input[type=checkbox][value=?]', 1 end end end end end it 'renders error message' do get :errors_for response.should be_success assert_select "form[class=?]", /form-horizontal/ do assert_select 'div.alert.alert-error' do assert_select 'p' do assert_select 'b', 'User: not saved because of 1 error' end assert_select 'ul' do assert_select 'li', 'Email should be email' end end end end it 'renders field with hint' do get :field_with_hint response.should be_success assert_select "form" do assert_select 'div.control-group' do assert_select 'label.control-label', 'Email' assert_select 'div.controls' do assert_select 'input[type=email]' assert_select 'p.help-block', 'Enter proper email address' end end end end it 'renders different buttons' do get :buttons response.should be_success assert_select "form" do assert_select 'div.form-actions' do assert_select 'input.btn.btn-primary[type=?][value=?]', 'submit', 'Sign in' assert_select 'button.btn[type=?]', 'submit', 'Cancel' assert_select 'button.btn.btn-danger[type=?]', 'submit', 'Danger button' assert_select 'input.btn[type=?][value=?]', 'submit', 'Submit without the primary class' end end end it 'renders submit buttons wrapped in div.form-actions' do get :submit_button response.should be_success assert_select "form" do assert_select "div.control-group" do assert_select 'label.control-label', 'Email' assert_select 'div.controls' do assert_select 'input[type=email]' end end assert_select 'div.form-actions' do assert_select 'input.btn.btn-primary[type=?][value=?]', 'submit', 'Create User' end end end end