Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add view RSpec tests for /admin/settings

  • Loading branch information...
commit de7982d8427aba221c4f85d99f434ea67e97c808 1 parent 57403d7
Jacob Helwig authored
25 app/views/admin/settings/index.html.erb
... ... @@ -1,18 +1,25 @@
1 1 <h1>Listing settings</h1>
2 2
3 3 <table>
4   - <tr>
5   - </tr>
  4 + <thead>
  5 + <tr>
  6 + <th>Setting</th>
  7 + <th>Value</th>
  8 + <th colspan="3">Options</th>
  9 + </tr>
  10 + </thead>
6 11
  12 + <tbody>
7 13 <% @settings.each do |setting| %>
8   - <tr>
9   - <td><%= h setting.key %></td>
10   - <td><%= h setting.value %></td>
11   - <td><%= link_to 'Show', admin_setting_path(setting) %></td>
12   - <td><%= link_to 'Edit', edit_admin_setting_path(setting) %></td>
13   - <td><%= link_to 'Destroy', admin_setting_path(setting), :confirm => 'Are you sure?', :method => :delete %></td>
14   - </tr>
  14 + <tr>
  15 + <td><%= h setting.key %></td>
  16 + <td><%= h setting.value %></td>
  17 + <td><%= link_to 'Show', admin_setting_path(setting) %></td>
  18 + <td><%= link_to 'Edit', edit_admin_setting_path(setting) %></td>
  19 + <td><%= link_to 'Destroy', admin_setting_path(setting), :confirm => 'Are you sure?', :method => :delete %></td>
  20 + </tr>
15 21 <% end %>
  22 + </tbody>
16 23 </table>
17 24
18 25 <br />
23 spec/views/admin/settings/edit.html.erb_spec.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "/admin/settings/edit" do
  4 + before(:each) do
  5 + setting = mock_model(Setting)
  6 + setting.should_receive(:key).and_return('foo')
  7 + setting.should_receive(:value).and_return(42)
  8 + assigns[:setting] = setting
  9 + render 'admin/settings/edit'
  10 + end
  11 +
  12 + it "should tell you where you are" do
  13 + response.should have_tag('h1', %r[Editing setting])
  14 + end
  15 +
  16 + it 'should populate the key text box' do
  17 + response.should have_tag('input[name=?][value=?]', 'setting[key]', 'foo')
  18 + end
  19 +
  20 + it 'should populate the value text box' do
  21 + response.should have_tag('input[name=?][value=?]', 'setting[value]', '42')
  22 + end
  23 +end
90 spec/views/admin/settings/index.html.erb_spec.rb
... ... @@ -0,0 +1,90 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "/admin/settings/index" do
  4 + it "should tell you where you are" do
  5 + assigns[:settings] = []
  6 + render 'admin/settings/index'
  7 +
  8 + response.should have_tag('h1', %r[Listing settings])
  9 + end
  10 +
  11 + describe 'without any existing settings' do
  12 + before(:each) do
  13 + assigns[:settings] = []
  14 + render 'admin/settings/index'
  15 + end
  16 +
  17 + it 'should have an empty tbody' do
  18 + response.should have_tag('tbody') do
  19 + with_tag('tr', 0)
  20 + end
  21 + end
  22 + end
  23 +
  24 + describe 'with one existing setting' do
  25 + before(:each) do
  26 + setting = mock_model(Setting)
  27 + setting.should_receive(:key).and_return('foo')
  28 + setting.should_receive(:value).and_return(42)
  29 +
  30 + assigns[:settings] = [setting]
  31 + render 'admin/settings/index'
  32 + end
  33 +
  34 + it 'should have a single row in the tbody' do
  35 + response.should have_tag('tbody') do
  36 + with_tag('tr', 1)
  37 + end
  38 + end
  39 +
  40 + it 'should have the setting values, and links in the row' do
  41 + response.should have_tag('tbody tr') do
  42 + with_tag('td', 'foo')
  43 + with_tag('td', '42')
  44 + with_tag('td', /Show/)
  45 + with_tag('td', /Edit/)
  46 + with_tag('td', /Destroy/)
  47 + end
  48 + end
  49 + end
  50 +
  51 + describe 'with multiple existing settings' do
  52 + before(:each) do
  53 + setting1 = mock_model(Setting)
  54 + setting1.should_receive(:key).and_return('foo')
  55 + setting1.should_receive(:value).and_return(42)
  56 +
  57 + setting2 = mock_model(Setting)
  58 + setting2.should_receive(:key).and_return('bar')
  59 + setting2.should_receive(:value).and_return('baz')
  60 +
  61 + assigns[:settings] = [setting1, setting2]
  62 + render 'admin/settings/index'
  63 + end
  64 +
  65 + it 'should have multiple rows in the tbody' do
  66 + response.should have_tag('tbody') do
  67 + with_tag('tr', 2)
  68 + end
  69 + end
  70 +
  71 + it 'should have the setting values, and links in the rows' do
  72 + response.should have_tag('tbody') do
  73 + with_tag('tr') do
  74 + with_tag('td', 'foo')
  75 + with_tag('td', '42')
  76 + with_tag('td', /Show/)
  77 + with_tag('td', /Edit/)
  78 + with_tag('td', /Destroy/)
  79 + end
  80 + with_tag('tr') do
  81 + with_tag('td', 'bar')
  82 + with_tag('td', 'baz')
  83 + with_tag('td', /Show/)
  84 + with_tag('td', /Edit/)
  85 + with_tag('td', /Destroy/)
  86 + end
  87 + end
  88 + end
  89 + end
  90 +end
25 spec/views/admin/settings/new.html.erb_spec.rb
... ... @@ -0,0 +1,25 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "/admin/settings/new" do
  4 + before(:each) do
  5 + setting = mock_model(Setting)
  6 + setting.should_receive(:key).and_return(nil)
  7 + setting.should_receive(:value).and_return(nil)
  8 + assigns[:setting] = setting
  9 + render 'admin/settings/new'
  10 + end
  11 +
  12 + it "should tell you that you are editing a new setting" do
  13 + response.should have_tag('h1', %r[New setting])
  14 + end
  15 +
  16 + it 'should not have anything in the key text box' do
  17 + response.should have_tag('input[name=?]', 'setting[key]')
  18 + response.should_not have_tag('input[name=?][value]', 'setting[key]')
  19 + end
  20 +
  21 + it 'should not have anything in the value text box' do
  22 + response.should have_tag('input[name=?]', 'setting[value]')
  23 + response.should_not have_tag('input[name=?][value]', 'setting[value]')
  24 + end
  25 +end
15 spec/views/admin/settings/show.html.erb_spec.rb
... ... @@ -0,0 +1,15 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "/admin/settings/show" do
  4 + before(:each) do
  5 + setting = mock_model(Setting)
  6 + setting.should_receive(:key).and_return('foo')
  7 + setting.should_receive(:value).and_return(42)
  8 + assigns[:setting] = setting
  9 + render 'admin/settings/show'
  10 + end
  11 +
  12 + it "should show the setting key and value" do
  13 + response.should have_tag('p', %r[foo: 42])
  14 + end
  15 +end

0 comments on commit de7982d

Please sign in to comment.
Something went wrong with that request. Please try again.