Skip to content

Commit

Permalink
Cover with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vergilet committed Jun 20, 2019
1 parent b6f369b commit 1ea31b7
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
repost (0.2.2)
repost (0.2.6)

GEM
remote: https://rubygems.org/
Expand All @@ -14,7 +14,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/repost/extend_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def repost(*args)

alias :redirect_post :repost
end
end
end
2 changes: 1 addition & 1 deletion lib/repost/senpai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(url, params: {}, options: {})
@options = options
@method = options[:method] || :post
@form_id = options[:form_id] || generated_form_id
@autosubmit = options[:autosubmit] && true
@autosubmit = options.fetch(:autosubmit, true)
@section_classes = options.dig(:decor, :section, :classes)
@section_html = options.dig(:decor, :section, :html)
@submit_classes = options.dig(:decor, :submit, :classes)
Expand Down
2 changes: 1 addition & 1 deletion lib/repost/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Repost
VERSION = "0.2.2"
VERSION = "0.2.6"
end
2 changes: 1 addition & 1 deletion repost.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
spec.email = ["[email protected]"]

spec.summary = %q{Gem implements Redirect using POST method}
spec.description = %q{Later}
spec.description = %q{Helps to make POST 'redirect', but actually builds <form> with method: :post under the hood}
spec.homepage = "https://vergilet.github.io/repost/"
spec.license = "MIT"

Expand Down
4 changes: 0 additions & 4 deletions spec/repost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
it "has a version number" do
expect(Repost::VERSION).not_to be nil
end

it "does something useful" do
expect(false).to eq(true)
end
end
96 changes: 96 additions & 0 deletions spec/senpai_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
require 'spec_helper'

RSpec.describe Repost::Senpai do
let(:url) { 'http://example.com/endpoint' }
let(:html) { described_class.perform(url) }

it 'generates post form' do
aggregate_failures do
expect(html).to include('form')
expect(html).to include(url)
expect(html).to include("type='submit'")
end
end

it 'autosubmit form by default' do
expect(html).to include('.submit()')
end

describe 'with params' do
let(:params) do
{
name: 'TestName',
description: 'Some cool description',
count: 696,
string_size: '234',
boolean: true,
string_boolean: 'false'
}
end

let(:html) { described_class.perform(url, params: params) }

it 'generates post form' do
aggregate_failures do
expect(html).to include("input type='hidden'")
expect(html).to include("value='#{params[:name]}'")
expect(html).to include("value='#{params[:description]}'")
expect(html).to include("value='#{params[:string_size]}'")
expect(html).to include("value='#{params[:string_boolean]}'")

expect(html).to include("value='#{params[:count]}'")
expect(html).to include("value='#{params[:boolean]}'")
end
end
end

describe 'with options' do
let(:options) { {} }
let(:html) { described_class.perform(url, options: options) }

context 'empty options' do
it 'autosubmit form by default' do
expect(html).to include('.submit()')
end
end

context 'set options' do
describe 'autosubmit' do
context 'enabled' do

let(:options) do
{
autosubmit: true
}
end

it 'returns submit function' do
aggregate_failures do
expect(html).to include('.submit()')
expect(html).to include('<noscript>')
end
end
end

context 'disabled' do
let(:options) do
{
autosubmit: false
}
end

it "doesn't return submit function" do
aggregate_failures do
expect(html).to_not include('.submit()')
expect(html).to_not include('<noscript>')
end
end
end
end

describe 'decor' do

end
end
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "bundler/setup"
require "repost"

require 'repost'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 1ea31b7

Please sign in to comment.