Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 7911425

Browse files
committed
Add #wordpress_user_profile_form_fields spec
1 parent 51a1728 commit 7911425

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

spec/wordpress/user_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
res.body = body
2222
res.code = code
2323

24-
allow(subject).to receive(:execute_post_request).and_return(res)
24+
allow(subject).to receive(:execute_request).and_return(res)
2525
end
2626

2727
describe '#wordpress_user_exists?' do
@@ -30,4 +30,31 @@
3030
expect(subject.wordpress_user_exists?('foo')).to be true
3131
end
3232
end
33+
34+
describe '#wordpress_user_profile_form_fields' do
35+
context 'when the profile form is accessible and contains a valid form' do
36+
let(:code) { 200 }
37+
let(:body) { '<form><input name="key" value="value"><input name="foo" required value="bar"/>' }
38+
it 'returns a hash constructed from the input elements in the profile form' do
39+
fields = subject.wordpress_user_profile_form_fields('')
40+
expect(fields).to eq('key' => 'value', 'foo' => 'bar')
41+
end
42+
end
43+
44+
context 'when the profile form is accessible and contains no form elements' do
45+
let(:code) { 200 }
46+
let(:body) { '<form></form>' }
47+
it 'returns an empty hash' do
48+
expect(subject.wordpress_user_profile_form_fields('')).to eq({})
49+
end
50+
end
51+
52+
context 'when the profile form request returns a code != 200' do
53+
let(:code) { 404 }
54+
let(:body) { nil }
55+
it 'returns nil' do
56+
expect(subject.wordpress_user_profile_form_fields('')).to be_nil
57+
end
58+
end
59+
end
3360
end

0 commit comments

Comments
 (0)