This repository was archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathform_spec.rb
More file actions
66 lines (55 loc) · 2.35 KB
/
form_spec.rb
File metadata and controls
66 lines (55 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'spec_helper'
describe 'NestedForm' do
include Capybara::DSL
def check_form
page.should have_no_css('form .fields input[id$=name]')
click_button 'Add new task'
page.should have_css('form .fields input[id$=name]', :count => 1)
find('form .fields input[id$=name]').should be_visible
find('form .fields input[id$=_destroy]').value.should == 'false'
click_button 'Remove'
find('form .fields input[id$=_destroy]').value.should == '1'
find('form .fields input[id$=name]').should_not be_visible
click_button 'Add new task'
click_button 'Add new task'
fields = all('form .fields')
fields.select { |field| field.visible? }.count.should == 2
fields.reject { |field| field.visible? }.count.should == 1
end
it 'should work with jQuery', :js => true do
visit '/projects/new'
check_form
end
it 'should work with Prototype', :js => true do
visit '/projects/new?type=prototype'
check_form
end
it 'works when there are no inputs for intermediate association', :js => true do
visit '/projects/without_intermediate_inputs'
click_button 'Add new task'
click_button 'Add new milestone'
click_button 'Add new milestone'
inputs = all('.fields .fields input[id$=name]')
inputs.first[:name].should_not eq(inputs.last[:name])
end
it 'generates correct name for the nested input', :js => true do
visit '/projects/new?type=jquery'
click_button 'Add new task'
click_button 'Add new milestone'
name = find('.fields .fields input[id$=name]')[:name]
name.should match(/\Aproject\[tasks_attributes\]\[\d+\]\[milestones_attributes\]\[\d+\]\[name\]\z/)
end
it 'generates correct name for the nested input (has_one => has_many)', :js => true do
visit '/companies/new?type=jquery'
click_button 'Add new task'
name = find('.fields .fields input[id$=name]')[:name]
name.should match(/\Acompany\[project_attributes\]\[tasks_attributes\]\[\d+\]\[name\]\z/)
end
it 'generates correct name for the nested input (has_one => has_many => has_many)', :js => true do
visit '/companies/new?type=jquery'
click_button 'Add new task'
click_button 'Add new milestone'
name = find('.fields .fields .fields input[id$=name]')[:name]
name.should match(/\Acompany\[project_attributes\]\[tasks_attributes\]\[\d+\]\[milestones_attributes\]\[\d+\]\[name\]\z/)
end
end