Merge branch 'rspec' into registry-480

# Conflicts:
#	spec/views/mailers/shared/registrant/registrant_shared.rb
This commit is contained in:
Artur Beljajev 2017-05-25 23:36:40 +03:00
commit 9486138e5e
14 changed files with 38 additions and 308 deletions

View file

@ -1,4 +1,5 @@
language: ruby
cache: bundler
env:
- DB=postgresql
bundler_args: --without development staging production

View file

@ -135,8 +135,6 @@ group :development, :test do
# debug
gem 'pry', '0.10.1'
# code review
gem 'rubycritic', '3.2.0'
gem 'bullet', '4.14.7' # for finding database optimizations
gem 'bundler-audit'
gem 'brakeman', '3.6.1', require: false # for security audit'

View file

@ -141,8 +141,6 @@ GEM
xpath (~> 2.0)
chronic (0.10.2)
cliver (0.3.2)
codeclimate-engine-rb (0.4.0)
virtus (~> 1.0)
codeclimate-test-reporter (1.0.8)
simplecov (<= 0.13)
coderay (1.1.0)
@ -195,15 +193,6 @@ GEM
ffi (1.9.18)
figaro (1.1.1)
thor (~> 0.14)
flay (2.8.1)
erubis (~> 2.7.0)
path_expander (~> 1.0)
ruby_parser (~> 3.0)
sexp_processor (~> 4.0)
flog (4.6.1)
path_expander (~> 1.0)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.8)
globalid (0.3.7)
activesupport (>= 4.1.0)
grape (0.12.0)
@ -271,7 +260,7 @@ GEM
liquid (3.0.6)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.4)
mail (2.6.5)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
@ -303,7 +292,6 @@ GEM
orm_adapter (0.5.0)
parser (2.4.0.0)
ast (~> 2.2)
path_expander (1.0.1)
pdfkit (0.6.2)
pg (0.19.0)
phantomjs (1.9.8.0)
@ -372,10 +360,6 @@ GEM
i18n
polyamorous (~> 1.1)
rdoc (4.3.0)
reek (4.6.1)
codeclimate-engine-rb (~> 0.4.0)
parser (>= 2.3.1.2, < 2.5)
rainbow (~> 2.0)
ref (2.0.0)
request_store (1.1.0)
responders (2.3.0)
@ -414,15 +398,6 @@ GEM
ruby-progressbar (1.8.1)
ruby_parser (3.8.4)
sexp_processor (~> 4.1)
rubycritic (3.2.0)
flay (~> 2.8)
flog (~> 4.4)
launchy (= 2.4.3)
parser (= 2.4.0)
rainbow (~> 2.1)
reek (~> 4.4)
ruby_parser (~> 3.8)
virtus (~> 1.0)
safe_yaml (1.0.4)
sass (3.4.23)
sass-rails (5.0.6)
@ -581,7 +556,6 @@ DEPENDENCIES
rest-client
rspec-rails (~> 3.6)
rubocop (= 0.48.1)
rubycritic (= 3.2.0)
sass-rails (= 5.0.6)
sdoc (= 0.4.1)
select2-rails (= 3.5.9.3)

View file

@ -58,9 +58,6 @@ BCODE=0 # tmp
bundle exec brakeman -q
echo "END_OF_SECURITY_RESULTS"
# update code review
bundle exec rubycritic app lib
if [ $RCODE == 0 ] && [ $TCODE == 0 ] &&[ $BCODE == 0 ]; then
exit 0
else

View file

@ -9,7 +9,6 @@ require 'support/requests/session_helpers'
require 'support/requests/epp_helpers'
require 'support/features/session_helpers'
require 'support/matchers/alias_attribute'
require 'support/matchers/active_job'
require 'support/matchers/epp/code'
require 'support/capybara'

View file

@ -6,17 +6,7 @@ if ENV['TRAVIS']
SimpleCov.start
end
RSpec.configure do |config|
# https://github.com/rspec/rspec-rails/issues/1076
config.around :each, type: :view do |example|
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = false
example.run
mocks.verify_partial_doubles = true
end
end
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.

View file

@ -1,252 +0,0 @@
require "active_job/base"
require "active_job/arguments"
# This matcher is needed because it is absent it rspec-rails 3.3.2
module RSpec
module Rails
module Matchers
# Namespace for various implementations of ActiveJob features
#
# @api private
module ActiveJob
# rubocop: disable Style/ClassLength
# @private
class Base < RSpec::Matchers::BuiltIn::BaseMatcher
def initialize
@args = []
@queue = nil
@at = nil
@block = Proc.new {}
set_expected_number(:exactly, 1)
end
def with(*args, &block)
@args = args
@block = block if block.present?
self
end
def on_queue(queue)
@queue = queue
self
end
def at(date)
@at = date
self
end
def exactly(count)
set_expected_number(:exactly, count)
self
end
def at_least(count)
set_expected_number(:at_least, count)
self
end
def at_most(count)
set_expected_number(:at_most, count)
self
end
def times
self
end
def once
exactly(:once)
end
def twice
exactly(:twice)
end
def thrice
exactly(:thrice)
end
def failure_message
"expected to enqueue #{base_message}"
end
def failure_message_when_negated
"expected not to enqueue #{base_message}"
end
def message_expectation_modifier
case @expectation_type
when :exactly then "exactly"
when :at_most then "at most"
when :at_least then "at least"
end
end
def supports_block_expectations?
true
end
private
def check(jobs)
@matching_jobs_count = jobs.count do |job|
if serialized_attributes.all? { |key, value| value == job[key] }
args = ::ActiveJob::Arguments.deserialize(job[:args])
@block.call(*args)
true
else
false
end
end
case @expectation_type
when :exactly then @expected_number == @matching_jobs_count
when :at_most then @expected_number >= @matching_jobs_count
when :at_least then @expected_number <= @matching_jobs_count
end
end
def base_message
"#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg|
msg << " with #{@args}," if @args.any?
msg << " on queue #{@queue}," if @queue
msg << " at #{@at}," if @at
msg << " but enqueued #{@matching_jobs_count}"
end
end
def serialized_attributes
{}.tap do |attributes|
attributes[:args] = ::ActiveJob::Arguments.serialize(@args) if @args.any?
attributes[:at] = @at.to_f if @at
attributes[:queue] = @queue if @queue
attributes[:job] = @job if @job
end
end
def set_expected_number(relativity, count)
@expectation_type = relativity
@expected_number = case count
when :once then 1
when :twice then 2
when :thrice then 3
else Integer(count)
end
end
def queue_adapter
::ActiveJob::Base.queue_adapter
end
end
# rubocop: enable Style/ClassLength
# @private
class HaveEnqueuedJob < Base
def initialize(job)
super()
@job = job
end
def matches?(proc)
raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc
original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count
proc.call
in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count)
check(in_block_jobs)
end
end
# @private
class HaveBeenEnqueued < Base
def matches?(job)
@job = job
check(queue_adapter.enqueued_jobs)
end
end
end
# @api public
# Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times.
#
# @example
# expect {
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job
#
# # Using alias
# expect {
# HeavyLiftingJob.perform_later
# }.to enqueue_job
#
# expect {
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job(HelloJob).exactly(:once)
#
# expect {
# 3.times { HelloJob.perform_later }
# }.to have_enqueued_job(HelloJob).at_least(2).times
#
# expect {
# HelloJob.perform_later
# }.to have_enqueued_job(HelloJob).at_most(:twice)
#
# expect {
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# }.to have_enqueued_job(HelloJob).and have_enqueued_job(HeavyLiftingJob)
#
# expect {
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
def have_enqueued_job(job = nil)
check_active_job_adapter
ActiveJob::HaveEnqueuedJob.new(job)
end
alias_method :enqueue_job, :have_enqueued_job
# @api public
# Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
#
# @example
# before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear }
#
# HeavyLiftingJob.perform_later
# expect(HeavyLiftingJob).to have_been_enqueued
#
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once)
#
# 3.times { HelloJob.perform_later }
# expect(HelloJob).to have_been_enqueued.at_least(2).times
#
# HelloJob.perform_later
# expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice)
#
# HelloJob.perform_later
# HeavyLiftingJob.perform_later
# expect(HelloJob).to have_been_enqueued
# expect(HeavyLiftingJob).to have_been_enqueued
#
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon)
def have_been_enqueued
check_active_job_adapter
ActiveJob::HaveBeenEnqueued.new
end
private
# @private
def check_active_job_adapter
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`"
end
end
end
end

View file

@ -5,10 +5,13 @@ RSpec.describe 'admin/billing/prices/_form' do
let(:price) { build_stubbed(:price) }
before :example do
allow(view).to receive(:price).and_return(price)
allow(view).to receive(:zones).and_return([])
allow(view).to receive(:operation_categories).and_return([])
allow(view).to receive(:durations).and_return([])
without_partial_double_verification do
allow(view).to receive(:price).and_return(price)
allow(view).to receive(:zones).and_return([])
allow(view).to receive(:operation_categories).and_return([])
allow(view).to receive(:durations).and_return([])
end
stub_template '_form_errors' => ''
end

View file

@ -6,7 +6,10 @@ RSpec.describe 'admin/domains/edit' do
before :example do
allow(DomainPresenter).to receive(:new).and_return(domain_presenter)
allow(view).to receive(:force_delete_templates)
without_partial_double_verification do
allow(view).to receive(:force_delete_templates)
end
assign(:domain, domain)

View file

@ -5,8 +5,10 @@ RSpec.shared_examples 'domain mailer registrant info' do |template_path|
let(:registrant) { instance_spy(RegistrantPresenter) }
before :example do
allow(view).to receive(:registrant).and_return(registrant)
allow(view).to receive(:address_processing)
without_partial_double_verification do
allow(view).to receive(:registrant).and_return(registrant)
allow(view).to receive(:address_processing)
end
end
it 'has name' do

View file

@ -4,7 +4,9 @@ RSpec.shared_examples 'domain mailer registrar info' do
let(:registrar) { instance_spy(RegistrarPresenter) }
before :example do
allow(view).to receive(:registrar).and_return(registrar)
without_partial_double_verification do
allow(view).to receive(:registrar).and_return(registrar)
end
end
attributes = %i(

View file

@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/_form' do
let(:contact) { instance_spy(Depp::Contact) }
before :example do
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
without_partial_double_verification do
allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {}))
end
assign(:contact, contact)
stub_template 'registrar/shared/_error_messages' => ''
@ -16,7 +19,9 @@ RSpec.describe 'registrar/contacts/_form' do
context 'when address processing is enabled' do
before do
allow(view).to receive(:address_processing?).and_return(true)
without_partial_double_verification do
allow(view).to receive(:address_processing?).and_return(true)
end
end
it 'has address' do
@ -27,7 +32,9 @@ RSpec.describe 'registrar/contacts/_form' do
context 'when address processing is disabled' do
before do
allow(view).to receive(:address_processing?).and_return(false)
without_partial_double_verification do
allow(view).to receive(:address_processing?).and_return(false)
end
end
it 'has no address' do

View file

@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/form/_legal_document' do
let(:contact) { instance_spy(Depp::Contact) }
before :example do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {}))
without_partial_double_verification do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {}))
end
assign(:contact, contact)
end

View file

@ -4,7 +4,10 @@ RSpec.describe 'registrar/domains/_form' do
let(:domain) { instance_spy(Depp::Domain) }
before :example do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {}))
without_partial_double_verification do
allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {}))
end
assign(:domain, domain)
stub_template 'registrar/domains/form/_general' => ''