Skip to content

Commit

Permalink
submit mautic form always return 302
Browse files Browse the repository at this point in the history
  • Loading branch information
luk4s committed Nov 22, 2017
1 parent 6e28a75 commit 4ff9731
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/mautic/form_helper.rb
Expand Up @@ -31,6 +31,7 @@ def data
raise ArgumentError if @data.nil?
defaults = {
'submit' => '1',
'return' => host,
'domain' => host
}
defaults.merge(@data.to_h).inject({}){|mem, (name, value)| mem["mauticform[#{name}]"] = value; mem}
Expand All @@ -41,7 +42,12 @@ def submit
uri.path = '/form/submit'
headers = {}
headers.store 'X-Forwarded-For', forward_ip if forward_ip
RestClient.post uri.to_s, data, headers
begin
@response = RestClient.post uri.to_s, data, headers
rescue RestClient::Found => e
@response = e
end

end
alias_method :push, :submit
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mautic/version.rb
@@ -1,3 +1,3 @@
module Mautic
VERSION = '1.0.0'
VERSION = '1.0.1'
end
6 changes: 3 additions & 3 deletions spec/models/mautic/form_helper_spec.rb
Expand Up @@ -6,7 +6,7 @@ module Mautic
it '#send_data' do
m = FormHelper.new("https://mautic.fake.com")
stub = stub_request(:post, "#{m.url}/form/submit")
.with(body: hash_including("mauticform" => hash_including("name"))).to_return(status: 200)
.with(body: hash_including("mauticform" => hash_including("name"))).to_return(status: 302)

m.send_data 1 do |i|
i.name = Faker::Name.first_name
Expand All @@ -18,15 +18,15 @@ module Mautic
it '#push' do
m = FormHelper.new("https://mautic.fake.com")
stub = stub_request(:post, "#{m.url}/form/submit")
.with(body: hash_including("mauticform" => hash_including("name"))).to_return(status: 200)
.with(body: hash_including("mauticform" => hash_including("name"))).to_return(status: 302)
m.data = {name: Faker::Name.first_name, email: Faker::Internet.free_email}
m.submit
expect(stub).to have_been_made
end

it '.submit' do
stub = stub_request(:post, "https://mautic.my.app/form/submit")
.with(body: hash_including("mauticform" => hash_including("name", "domain"))).to_return(status: 200)
.with(body: hash_including("mauticform" => hash_including("name", "domain"))).to_return(status: 302)

FormHelper.submit(form: 13, request: OpenStruct.new(host: Faker::Internet.domain_name)) do |i|
i.name = Faker::Name.first_name
Expand Down

0 comments on commit 4ff9731

Please sign in to comment.