強欲で謙虚なツボツボ

趣味の読書の書の方

備忘録(Ruby)

Rspecのfill_in

フォームのテキストフィールドに値を挿入

<label for="name">氏名</label>
<input type="text" />
fill_in 'メールアドレス', with: '山田太郎' (ラベルの指定だと上手くいかないこともそこそこある)
fill_in 'name', with: '山田太郎' //(id指定の方が確実)

 

Rspecのselect

フォームのセレクトボックスで選択

<label for="prefecture">都道府県</label>
<select id="prefecture">
  <option value="1">北海道</option>
  <option value="2">岩手県</option>
  <option value="3">青森県</option>
</select>
select '北海道', from: '都道府県'
select '北海道', from: 'prefecture' #(id指定の方が確実)
find("#prefecture").find("option[value='1']").select_option #(一番確実)

 

Rspecのchoose

ラジオボタンをクリック

<label>
  <input id="gender_male" name="gender" type="radio" value="male">男性
</label>
<label>
  <input id="gender_female" name="gender" type="radio" value="female">女性
</label>
choose '男性'

 

Rspecのcheckとuncheck

チェックボタンをチェック

<label>利用規約</label>
  <input type="checkbox" id="rule" value="1" />
</label>
check '利用規約'
uncheck '利用規約'

 

routeでサブドメイン設定

Rails.application.routes.draw do
  constraints subdomain: 'admin' do
    resources :admin
  end
  constraints subdomain: '' do
    resources :user
  end
end

# admin.example.com/sign_inだと/admin/sign_in
# example.com/sign_inだと/user/sign_in
# みたいな感じ