From 00dd84d757b6d38be4fb1d5a779309c19e86cb42 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:10:57 +0200 Subject: [PATCH 01/31] chore: upgrade inherited_resources for compatibility with strong_paramters --- Gemfile.lock | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d5b3b3db..a544ffa8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,17 +100,21 @@ GEM activesupport (>= 3.1, < 4.1) haml (>= 3.1, < 4.1) railties (>= 3.1, < 4.1) - has_scope (0.5.1) + has_scope (0.6.0.rc) + actionpack (>= 3.2, < 5) + activesupport (>= 3.2, < 5) hike (1.2.3) - i18n (0.6.11) - inherited_resources (1.3.1) - has_scope (~> 0.5.0) - responders (~> 0.6) + i18n (0.7.0) + inherited_resources (1.5.1) + actionpack (>= 3.2, < 4.2) + has_scope (~> 0.6.0.rc) + railties (>= 3.2, < 4.2) + responders (~> 1.0) journey (1.0.4) jquery-rails (2.1.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.8.1) + json (1.8.2) libv8 (3.16.14.7) libwebsocket (0.1.6.1) websocket @@ -137,7 +141,7 @@ GEM rack (>= 0.4) rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) rails (3.2.21) actionmailer (= 3.2.21) @@ -158,8 +162,8 @@ GEM rdoc (3.12.2) json (~> 1.4) ref (1.0.5) - responders (0.9.3) - railties (~> 3.1) + responders (1.1.2) + railties (>= 3.2, < 4.2) rspec-core (2.13.1) rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) From f33bbdda149a0ad31e3195c62c70f0359b11b762 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:11:20 +0200 Subject: [PATCH 02/31] feat: added strong_parameters gem to help with upgrade --- Gemfile | 2 ++ Gemfile.lock | 6 ++++++ config/initializers/strong_parameters.rb | 1 + config/routes.rb | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 config/initializers/strong_parameters.rb diff --git a/Gemfile b/Gemfile index 786e6805..65cdf71a 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,8 @@ platforms :ruby do gem 'therubyracer' end +gem 'strong_parameters' + gem 'haml-rails' gem 'jquery-rails' gem 'will_paginate', '~> 3.0.4' diff --git a/Gemfile.lock b/Gemfile.lock index a544ffa8..21532565 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,11 @@ GEM tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) state_machine (1.1.2) + strong_parameters (0.2.3) + actionpack (~> 3.0) + activemodel (~> 3.0) + activesupport (~> 3.0) + railties (~> 3.0) therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref @@ -243,6 +248,7 @@ DEPENDENCIES sass-rails sqlite3 state_machine + strong_parameters therubyracer uglifier webrat diff --git a/config/initializers/strong_parameters.rb b/config/initializers/strong_parameters.rb new file mode 100644 index 00000000..394c1f5f --- /dev/null +++ b/config/initializers/strong_parameters.rb @@ -0,0 +1 @@ +ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection) diff --git a/config/routes.rb b/config/routes.rb index 9f8b8280..9b3c4b51 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,8 +25,8 @@ resources :macro_steps end - match '/audits(/:action(/:id))' => 'audits#index', :as => :audits - match '/reports(/:action)' => 'reports#index', :as => :reports + get '/audits(/:action(/:id))' => 'audits#index', :as => :audits + get '/reports(/:action)' => 'reports#index', :as => :reports resource :auth_token post '/token/:token' => 'sessions#token', :as => :token From 0c0eea63a5401224d5d3bb468baf384156906e24 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:40:45 +0200 Subject: [PATCH 03/31] feat: updated all controllers to use strong parameters --- app/controllers/domains_controller.rb | 12 ++++++++---- app/controllers/macro_steps_controller.rb | 14 +++++++++----- app/controllers/macros_controller.rb | 4 ++++ app/controllers/record_templates_controller.rb | 10 ++++++++-- app/controllers/records_controller.rb | 12 ++++++++++-- app/controllers/templates_controller.rb | 6 +++++- app/controllers/users_controller.rb | 6 ++++++ 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/controllers/domains_controller.rb b/app/controllers/domains_controller.rb index 60486895..060fbf37 100644 --- a/app/controllers/domains_controller.rb +++ b/app/controllers/domains_controller.rb @@ -27,6 +27,10 @@ def restrict_token_movements redirect_to domain_path( current_token.domain ) if current_token end + def domain_params + params.require(:domain).permit(:name, :zone_template_id, :zone_template_name, :primary_ns, :contact, :refresh, :retry, :expire, :minimum, :type, :master) + end + public def show @@ -38,15 +42,15 @@ def show end def create - @domain = Domain.new( params[:domain] ) + @domain = Domain.new( domain_params ) unless @domain.slave? - @zone_template = ZoneTemplate.find(params[:domain][:zone_template_id]) unless params[:domain][:zone_template_id].blank? - @zone_template ||= ZoneTemplate.find_by_name(params[:domain][:zone_template_name]) unless params[:domain][:zone_template_name].blank? + @zone_template = ZoneTemplate.find(domain_params[:zone_template_id]) unless params[:domain][:zone_template_id].blank? + @zone_template ||= ZoneTemplate.find_by_name(domain_params[:zone_template_name]) unless params[:domain][:zone_template_name].blank? unless @zone_template.nil? begin - @domain = @zone_template.build( params[:domain][:name] ) + @domain = @zone_template.build( domain_params[:name] ) rescue ActiveRecord::RecordInvalid => e @domain.attach_errors(e) diff --git a/app/controllers/macro_steps_controller.rb b/app/controllers/macro_steps_controller.rb index 63e71edd..bb4f76f5 100644 --- a/app/controllers/macro_steps_controller.rb +++ b/app/controllers/macro_steps_controller.rb @@ -17,14 +17,18 @@ def resource collection.find( params[:id] ) end + def macro_step_params + params.require(:macro_step).permit(:action, :record_type, :name, :content, :position, :prio) + end + public def create # Check for any previous macro steps if parent.macro_steps.any? # Check for the parameter - unless params[:macro_step][:position].blank? - position = params[:macro_step].delete(:position) + unless macro_step_params[:position].blank? + position = macro_step_params.delete(:position) else position = parent.macro_steps.last.position + 1 end @@ -32,7 +36,7 @@ def create position = '1' end - @macro_step = parent.macro_steps.create( params[:macro_step] ) + @macro_step = parent.macro_steps.create( macro_step_params ) @macro_step.insert_at( position.to_i ) if position && !@macro_step.new_record? @@ -45,10 +49,10 @@ def create end def update - position = params[:macro_step].delete(:position) + position = macro_step_params.delete(:position) @macro_step = parent.macro_steps.find( params[:id] ) - @macro_step.update_attributes( params[:macro_step] ) + @macro_step.update_attributes( macro_step_params ) @macro_step.insert_at( position.to_i ) if position diff --git a/app/controllers/macros_controller.rb b/app/controllers/macros_controller.rb index b4f5207b..ee8acef2 100644 --- a/app/controllers/macros_controller.rb +++ b/app/controllers/macros_controller.rb @@ -10,6 +10,10 @@ def collection @macros = Macro.user(current_user) end + def macro_params + params.require(:macro).permit(:name, :active, :user_id) + end + public def new diff --git a/app/controllers/record_templates_controller.rb b/app/controllers/record_templates_controller.rb index f1b33acf..bbe7d2f9 100644 --- a/app/controllers/record_templates_controller.rb +++ b/app/controllers/record_templates_controller.rb @@ -1,8 +1,8 @@ class RecordTemplatesController < ApplicationController def create - @record_template = RecordTemplate.new(params[:record_template]) @zone_template = ZoneTemplate.find(params[:zone_template][:id]) + @record_template = RecordTemplate.new( record_template_params ) @record_template.zone_template = @zone_template @record_template.save @@ -14,7 +14,7 @@ def create def update @record_template = RecordTemplate.find(params[:id]) - @record_template.update_attributes(params[:record_template]) + @record_template.update_attributes( record_template_params ) respond_to do |format| format.js @@ -30,4 +30,10 @@ def destroy redirect_to zone_template_path( zt ) end + private + + def record_template_params + params.require(:record_template).permit(:retry, :primary_ns, :contact, :refresh, :minimum, :expire, :record_type) + end + end diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index 3460f847..9155446d 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -37,10 +37,18 @@ def restrict_token_movements return false end + def record_params + params.require(:record).permit(:name, :ttl, :type, :content, :prio) + end + + def soa_params + params.require(:soa).permit(:primary_ns, :contact, :refresh, :retry, :minimum, :expire) + end + public def create - @record = parent.send( "#{params[:record][:type].downcase}_records".to_sym ).new( params[:record] ) + @record = parent.send( "#{record_params[:type].downcase}_records".to_sym ).new( record_params ) if current_token && !current_token.allow_new_records? && !current_token.can_add?( @record ) @@ -83,7 +91,7 @@ def destroy # Non-CRUD methods def update_soa @domain = parent - @domain.soa_record.update_attributes( params[:soa] ) + @domain.soa_record.update_attributes( soa_params ) end end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 00fd9207..7ba8174d 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -9,10 +9,14 @@ def collection @zone_templates = ZoneTemplate.user(current_user).all end + def template_params + params.require(:zone_template).permit(:name) + end + public def create - @zone_template = ZoneTemplate.new(params[:zone_template]) + @zone_template = ZoneTemplate.new(template_params) @zone_template.user = current_user unless current_user.admin? create! { zone_template_path( @zone_template ) } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7e910446..f7023127 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -32,4 +32,10 @@ def purge redirect_to users_path end + private + + def user_params + params.require(:user).permit(:login, :email, :password, :password_confirmation, :admin, :auth_tokens) + end + end From b23a30da1e223f3da03346def0611abc1d9f30cb Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:41:22 +0200 Subject: [PATCH 04/31] chore: drop 1.9.2 from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 252f100e..f943fe05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ rvm: - 2.0 - rbx-19mode - 1.9.3 - - 1.9.2 env: - DB=sqlite From 52b8b934aa22b37d349b57a35656b4a3f8db1d47 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:48:36 +0200 Subject: [PATCH 05/31] chore: bump audited-activerecord to 3.0.0 stable --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 65cdf71a..2f31d921 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'strong_parameters' gem 'haml-rails' gem 'jquery-rails' gem 'will_paginate', '~> 3.0.4' -gem "audited-activerecord", "~> 3.0.0.rc2" +gem "audited-activerecord", "~> 3.0.0" gem 'inherited_resources' gem 'devise', '~> 2.2.8' gem "devise-encryptable" diff --git a/Gemfile.lock b/Gemfile.lock index 21532565..51f20cc0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -227,7 +227,7 @@ PLATFORMS DEPENDENCIES RedCloth (>= 4.1.1) acts_as_list - audited-activerecord (~> 3.0.0.rc2) + audited-activerecord (~> 3.0.0) coffee-rails cucumber-rails database_cleaner From 130d492c4054f108dd77c6b14a526ad445dd521f Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 00:55:09 +0200 Subject: [PATCH 06/31] chore: bump to rspec 2.99 and get guard-rspec up in here --- Gemfile | 3 ++- Gemfile.lock | 69 ++++++++++++++++++++++++++++++++++++++++++++-------- Guardfile | 33 +++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 Guardfile diff --git a/Gemfile b/Gemfile index 2f31d921..24d54036 100644 --- a/Gemfile +++ b/Gemfile @@ -32,11 +32,12 @@ gem 'dynamic_form' group :development do gem 'debugger', :platform => :mri_19 + gem 'guard-rspec', :require => false #gem 'RedCloth', '>= 4.1.1' end group :development, :test do - gem "rspec-rails" + gem "rspec-rails", "~> 2.99.0" gem 'RedCloth', '>= 4.1.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 51f20cc0..d583f16f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,8 +46,11 @@ GEM rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 1.0.0) + celluloid (0.16.0) + timers (~> 4.0.0) childprocess (0.3.6) ffi (~> 1.0, >= 1.0.6) + coderay (1.1.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -80,7 +83,7 @@ GEM warden (~> 1.2.1) devise-encryptable (0.1.1) devise (>= 2.1.0.rc) - diff-lcs (1.2.1) + diff-lcs (1.2.5) dynamic_form (1.1.4) erubis (2.7.0) execjs (1.4.0) @@ -90,9 +93,24 @@ GEM factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) - ffi (1.2.0) + ffi (1.9.6) + formatador (0.2.5) gherkin (2.11.5) json (>= 1.4.6) + guard (2.11.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.0) + guard-rspec (4.5.0) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) haml (4.0.0) tilt haml-rails (0.4) @@ -104,6 +122,7 @@ GEM actionpack (>= 3.2, < 5) activesupport (>= 3.2, < 5) hike (1.2.3) + hitimes (1.2.2) i18n (0.7.0) inherited_resources (1.5.1) actionpack (>= 3.2, < 4.2) @@ -118,21 +137,35 @@ GEM libv8 (3.16.14.7) libwebsocket (0.1.6.1) websocket + listen (2.8.5) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + lumberjack (1.0.9) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.1) + method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.0) mocha (0.13.0) metaclass (~> 0.0.1) multi_json (1.10.1) mysql2 (0.3.11) + nenv (0.1.1) nokogiri (1.6.3.1) mini_portile (= 0.6.0) + notiffany (0.0.3) + nenv (~> 0.1) + shellany (~> 0.0) orm_adapter (0.5.0) pg (0.15.0) polyglot (0.3.5) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) rabl (0.7.6) activesupport (>= 2.3.14) multi_json (~> 1.0) @@ -159,22 +192,33 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.4.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) ref (1.0.5) responders (1.1.2) railties (>= 3.2, < 4.2) - rspec-core (2.13.1) - rspec-expectations (2.13.0) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-collection_matchers (1.1.2) + rspec-expectations (>= 2.99.0.beta1) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.0) - rspec-rails (2.13.0) + rspec-mocks (2.99.3) + rspec-rails (2.99.0) actionpack (>= 3.0) + activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) + rspec-collection_matchers + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) rubyzip (0.9.9) sass (3.2.3) sass-rails (3.2.5) @@ -186,6 +230,8 @@ GEM libwebsocket (~> 0.1.3) multi_json (~> 1.0) rubyzip + shellany (0.0.1) + slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) @@ -203,6 +249,8 @@ GEM ref thor (0.19.1) tilt (1.4.1) + timers (4.0.1) + hitimes treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -236,6 +284,7 @@ DEPENDENCIES devise-encryptable dynamic_form factory_girl_rails (~> 4.0) + guard-rspec haml-rails inherited_resources jquery-rails @@ -244,7 +293,7 @@ DEPENDENCIES pg (>= 0.9.0) rabl rails (~> 3.2.21) - rspec-rails + rspec-rails (~> 2.99.0) sass-rails sqlite3 state_machine diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..6a1a2f0d --- /dev/null +++ b/Guardfile @@ -0,0 +1,33 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +# Note: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rsspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separetly) +# * 'just' rspec: 'rspec' +guard :rspec, cmd: 'bundle exec rspec' do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + watch('spec/rails_helper.rb') { "spec" } + + # Capybara features specs + watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } +end + From 6d41ab0f9a3fa2d5c34ec625ef17afbd01e32c5f Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 01:32:15 +0200 Subject: [PATCH 07/31] feat: removed a ton of rspec deprecation message around `have(N).entry`, `be_true`, `be_false`. also refactored a few specs to use subject --- spec/controllers/domains_controller_spec.rb | 4 +- spec/models/a_spec.rb | 24 +++-- spec/models/aaaa_spec.rb | 9 +- spec/models/auth_token_spec.rb | 99 +++++++++++---------- spec/models/cname_spec.rb | 3 +- spec/models/domain_spec.rb | 18 ++-- spec/models/macro_spec.rb | 6 +- spec/models/macro_step_spec.rb | 30 ++++--- spec/models/mx_spec.rb | 21 +++-- spec/models/ns_spec.rb | 3 +- spec/models/record_spec.rb | 41 +++++---- spec/models/record_template_spec.rb | 44 +++++---- spec/models/soa_spec.rb | 75 ++++++++++------ spec/models/sshfp_spec.rb | 33 ++++--- spec/models/txt_spec.rb | 3 +- spec/models/zone_template_spec.rb | 81 +++++++++-------- 16 files changed, 300 insertions(+), 194 deletions(-) diff --git a/spec/controllers/domains_controller_spec.rb b/spec/controllers/domains_controller_spec.rb index 66466ae8..d0fedfd9 100644 --- a/spec/controllers/domains_controller_spec.rb +++ b/spec/controllers/domains_controller_spec.rb @@ -232,7 +232,7 @@ get :index, :format => 'json' data = ActiveSupport::JSON.decode( response.body ) - data.should have(1).entry + expect( data.size ).to eq(1) data.first.keys.should include("id", "name") end @@ -252,7 +252,7 @@ get :apply_macro, :id => domain.id, :format => 'json' data = ActiveSupport::JSON.decode( response.body ) - data.should have(1).entry + expect( data.size ).to eq(1) end it "applying a macro to a domain" do diff --git a/spec/models/a_spec.rb b/spec/models/a_spec.rb index f2517c95..70ac17aa 100644 --- a/spec/models/a_spec.rb +++ b/spec/models/a_spec.rb @@ -10,32 +10,40 @@ it "should only accept valid IPv4 addresses as content" do subject.content = '10' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '10.0' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '10.0.0' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '10.0.0.9/32' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '256.256.256.256' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '10.0.0.9' - subject.should have(:no).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "should not accept new lines in content" do subject.content = "10.1.1.1\nHELLO WORLD" - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should not act as a CNAME" do subject.content = 'google.com' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end end diff --git a/spec/models/aaaa_spec.rb b/spec/models/aaaa_spec.rb index 5513d920..67827e30 100644 --- a/spec/models/aaaa_spec.rb +++ b/spec/models/aaaa_spec.rb @@ -12,17 +12,20 @@ it "should not act as a CNAME" do subject.content = 'google.com' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should accept a valid ipv6 address" do subject.content = "2001:0db8:85a3:0000:0000:8a2e:0370:7334" - subject.should have(:no).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "should not accept new lines in content" do subject.content = "2001:0db8:85a3:0000:0000:8a2e:0370:7334\nHELLO WORLD" - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end end diff --git a/spec/models/auth_token_spec.rb b/spec/models/auth_token_spec.rb index 30fc9fba..1abb908f 100644 --- a/spec/models/auth_token_spec.rb +++ b/spec/models/auth_token_spec.rb @@ -1,43 +1,46 @@ require 'spec_helper' describe AuthToken, "when new" do - before(:each) do - @auth_token = AuthToken.new - end it "should be invalid by default" do - @auth_token.should_not be_valid + subject.should_not be_valid end it "should require a domain" do - @auth_token.should have(1).error_on(:domain_id) + subject.valid? + expect( subject.errors[:domain_id].size ).to eq(1) end it "should require a user" do - @auth_token.should have(1).error_on(:user_id) + subject.valid? + expect( subject.errors[:user_id].size ).to eq(1) end it "should require an auth token" do - @auth_token.token.should_not be_nil + subject.token.should_not be_nil - @auth_token.token = nil - @auth_token.should have(1).error_on(:token) + subject.token = nil + subject.valid? + expect( subject.errors[:token].size ).to eq(1) end it "should require the permissions hash" do - @auth_token.permissions.should_not be_nil + subject.permissions.should_not be_nil - @auth_token.permissions = nil - @auth_token.should have(1).error_on(:permissions) + subject.permissions = nil + subject.valid? + expect( subject.errors[:permissions].size ).to eq(1) end it "should require an expiry time" do - @auth_token.should have(1).error_on(:expires_at) + subject.valid? + expect( subject.errors[:expires_at].size ).to eq(1) end it "should require an expiry time in the future" do - @auth_token.expires_at = 1.hour.ago - @auth_token.should have(1).error_on(:expires_at) + subject.expires_at = 1.hour.ago + subject.valid? + expect( subject.errors[:expires_at].size ).to eq(1) end end @@ -116,42 +119,42 @@ end it "should deny new RR's by default" do - @auth_token.allow_new_records?.should be_false + @auth_token.allow_new_records?.should be false end it "should allow for adding new RR" do @auth_token.allow_new_records = true - @auth_token.allow_new_records?.should be_true + @auth_token.allow_new_records?.should be true end it "should deny removing RR's by default" do - @auth_token.remove_records?.should be_false + @auth_token.remove_records?.should be false end it "should allow for removing RR's" do @auth_token.remove_records = true - @auth_token.remove_records?.should be_true + @auth_token.remove_records?.should be true a = FactoryGirl.create(:a, :domain => @domain) - @auth_token.can_remove?( a ).should be_false - @auth_token.can_remove?( 'example.com', 'A' ).should be_false + @auth_token.can_remove?( a ).should be false + @auth_token.can_remove?( 'example.com', 'A' ).should be false @auth_token.can_change( a ) - @auth_token.can_remove?( a ).should be_true - @auth_token.can_remove?( 'example.com', 'A' ).should be_true + @auth_token.can_remove?( a ).should be true + @auth_token.can_remove?( 'example.com', 'A' ).should be true end it "should allow for setting permissions to edit specific RR's (AR)" do a = FactoryGirl.create(:a, :domain => @domain) @auth_token.can_change( a ) - @auth_token.can_change?( 'example.com' ).should be_true - @auth_token.can_change?( 'example.com', 'MX' ).should be_false + @auth_token.can_change?( 'example.com' ).should be true + @auth_token.can_change?( 'example.com', 'MX' ).should be false mx = FactoryGirl.create(:mx, :domain => @domain) - @auth_token.can_change?( a ).should be_true - @auth_token.can_change?( mx ).should be_false + @auth_token.can_change?( a ).should be true + @auth_token.can_change?( mx ).should be false end it "should allow for setting permissions to edit specific RR's (name)" do @@ -160,10 +163,10 @@ @auth_token.can_change( 'mail.example.com' ) - @auth_token.can_change?( 'mail.example.com' ).should be_true - @auth_token.can_change?( mail ).should be_true + @auth_token.can_change?( 'mail.example.com' ).should be true + @auth_token.can_change?( mail ).should be true - @auth_token.can_change?( a ).should be_false + @auth_token.can_change?( a ).should be false end it "should allow for protecting certain RR's" do @@ -175,13 +178,13 @@ @auth_token.protect( mail ) @auth_token.protect( mx ) - @auth_token.can_change?( a ).should be_true - @auth_token.can_change?( 'example.com', 'A' ).should be_true + @auth_token.can_change?( a ).should be true + @auth_token.can_change?( 'example.com', 'A' ).should be true - @auth_token.can_change?( mx ).should be_false - @auth_token.can_change?( 'example.com', 'MX' ).should be_false + @auth_token.can_change?( mx ).should be false + @auth_token.can_change?( 'example.com', 'MX' ).should be false - @auth_token.can_change?( mail ).should be_false + @auth_token.can_change?( mail ).should be false end it "should allow for protecting RR's by type" do @@ -191,8 +194,8 @@ @auth_token.policy = :allow @auth_token.protect_type 'A' - @auth_token.can_change?( mail ).should be_false - @auth_token.can_change?( mx ).should be_true + @auth_token.can_change?( mail ).should be false + @auth_token.can_change?( mx ).should be true end it "should prevent removing RR's by type" do @@ -201,7 +204,7 @@ @auth_token.policy = :allow @auth_token.protect_type 'MX' - @auth_token.can_remove?( mx ).should be_false + @auth_token.can_remove?( mx ).should be false end it "should prevent adding RR's by type" do @@ -209,7 +212,7 @@ @auth_token.allow_new_records = true @auth_token.protect_type 'MX' - @auth_token.can_add?( MX.new( :name => '', :domain => @domain ) ).should be_false + @auth_token.can_add?( MX.new( :name => '', :domain => @domain ) ).should be false end it "should always protect NS records" do @@ -219,26 +222,26 @@ @auth_token.policy = :allow @auth_token.remove_records = true @auth_token.can_change( ns1 ) - @auth_token.can_change?( ns1 ).should be_false - @auth_token.can_remove?( ns2 ).should be_false + @auth_token.can_change?( ns1 ).should be false + @auth_token.can_remove?( ns2 ).should be false end it "should always protect SOA records" do @auth_token.policy = :allow @auth_token.remove_records = true @auth_token.can_change( @domain.soa_record ) - @auth_token.can_change?( @domain.soa_record ).should be_false - @auth_token.can_remove?( @domain.soa_record ).should be_false + @auth_token.can_change?( @domain.soa_record ).should be false + @auth_token.can_remove?( @domain.soa_record ).should be false end it "should provide a list of new RR types allowed" do @auth_token.new_types.should be_empty @auth_token.allow_new_records = true - @auth_token.new_types.include?('MX').should be_true + @auth_token.new_types.include?('MX').should be true @auth_token.protect_type 'MX' - @auth_token.new_types.include?('MX').should be_false + @auth_token.new_types.include?('MX').should be false end end @@ -265,12 +268,12 @@ end it "should correctly report the 'token' role" do - @auth_token.has_role?('token').should be_true - @auth_token.has_role?('admin').should be_false + @auth_token.has_role?('token').should be true + @auth_token.has_role?('admin').should be false end it "should correctly report permissions (deserialized)" do a = FactoryGirl.create(:a, :domain => @domain) - @auth_token.can_change?( a ).should be_true + @auth_token.can_change?( a ).should be true end end diff --git a/spec/models/cname_spec.rb b/spec/models/cname_spec.rb index f6fbc516..93810b5d 100644 --- a/spec/models/cname_spec.rb +++ b/spec/models/cname_spec.rb @@ -9,7 +9,8 @@ end it "should require content" do - subject.should have(2).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(2) end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index b94d6312..e3188a00 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -9,23 +9,27 @@ it "should not accept rubbish types" do subject.type = 'DOMINANCE' - subject.should have(1).error_on(:type) + subject.valid? + expect( subject.errors[:type].size ).to eq(1) end end context "new MASTER/NATIVE" do it "should require a name" do - subject.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should not allow duplicate names" do FactoryGirl.create(:domain) subject.name = "example.com" - subject.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should bail out on missing SOA fields" do - subject.should have(1).error_on( :primary_ns ) + subject.valid? + expect( subject.errors[:primary_ns].size ).to eq(1) end it "should be NATIVE by default" do @@ -41,12 +45,14 @@ subject { Domain.new( :type => 'SLAVE' ) } it "should require a master address" do - subject.should have(1).error_on(:master) + subject.valid? + expect( subject.errors[:master].size ).to eq(1) end it "should require a valid master address" do subject.master = 'foo' - subject.should have(1).error_on(:master) + subject.valid? + expect( subject.errors[:master].size ).to eq(1) subject.master = '127.0.0.1' subject.should have(:no).errors_on(:master) diff --git a/spec/models/macro_spec.rb b/spec/models/macro_spec.rb index 022420bb..c565eb98 100644 --- a/spec/models/macro_spec.rb +++ b/spec/models/macro_spec.rb @@ -5,13 +5,15 @@ context "when new" do it "should require a new" do - subject.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should have a unique name" do m = FactoryGirl.create(:macro) subject.name = m.name - subject.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should be disabled by default" do diff --git a/spec/models/macro_step_spec.rb b/spec/models/macro_step_spec.rb index 1cb94c20..d2deb4c5 100644 --- a/spec/models/macro_step_spec.rb +++ b/spec/models/macro_step_spec.rb @@ -8,11 +8,13 @@ end it "should require a macro" do - subject.should have(1).error_on(:macro_id) + subject.valid? + expect( subject.errors[:macro_id].size ).to eq(1) end it "should require an action" do - subject.should have(1).error_on(:action) + subject.valid? + expect( subject.errors[:action].size ).to eq(1) end it "should only accept allowed actions" do @@ -22,11 +24,13 @@ end subject.action = 'foo' - subject.should have(1).error_on(:action) + subject.valid? + expect( subject.errors[:action].size ).to eq(1) end it "should require a record type" do - subject.should have(1).error_on(:record_type) + subject.valid? + expect( subject.errors[:record_type].size ).to eq(1) end it "should only accept valid record types" do @@ -39,7 +43,8 @@ end subject.record_type = 'SOA' - subject.should have(1).error_on(:record_type) + subject.valid? + expect( subject.errors[:record_type].size ).to eq(1) end it "should not require a record name" do @@ -47,7 +52,8 @@ end it "should require content" do - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should be active by default" do @@ -58,14 +64,18 @@ it "from A records" do subject.record_type = 'A' subject.content = 'foo' - subject.should have(1).error_on(:content) - subject.should have(:no).errors_on(:name) + + subject.valid? + expect( subject.errors[:content].size ).to eq(1) + expect( subject.errors[:name].size ).to eq(0) end it "from MX records" do subject.record_type = 'MX' - subject.should have(1).error_on(:prio) - subject.should have(:no).errors_on(:name) + subject.valid? + + expect( subject.errors[:prio].size ).to eq(1) + expect( subject.errors[:name].size ).to eq(0) end end diff --git a/spec/models/mx_spec.rb b/spec/models/mx_spec.rb index eb658ea6..7431437f 100644 --- a/spec/models/mx_spec.rb +++ b/spec/models/mx_spec.rb @@ -8,21 +8,26 @@ end it "should require a priority" do - subject.should have(1).error_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) end it "should only allow positive, numeric priorities, between 0 and 65535 (inclusive)" do subject.prio = -10 - subject.should have(1).error_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) subject.prio = 65536 - subject.should have(1).error_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) subject.prio = 'low' - subject.should have(1).error_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) subject.prio = 10 - subject.should have(:no).errors_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(0) end it "should require content" do @@ -31,12 +36,14 @@ it "should not accept IP addresses as content" do subject.content = "127.0.0.1" - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should not accept spaces in content" do subject.content = 'spaced out.com' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should support priorities" do diff --git a/spec/models/ns_spec.rb b/spec/models/ns_spec.rb index 605193f4..a33093ef 100644 --- a/spec/models/ns_spec.rb +++ b/spec/models/ns_spec.rb @@ -7,7 +7,8 @@ end it "should require content" do - subject.should have(2).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(2) end end end diff --git a/spec/models/record_spec.rb b/spec/models/record_spec.rb index 267dbdaf..a30a821e 100644 --- a/spec/models/record_spec.rb +++ b/spec/models/record_spec.rb @@ -10,30 +10,36 @@ end it "should require a domain" do - subject.should have(1).error_on(:domain_id) + subject.valid? + expect( subject.errors[:domain_id].size ).to eq(1) end it "should require a ttl" do - subject.should have(1).error_on(:ttl) + subject.valid? + expect( subject.errors[:ttl].size ).to eq(1) end it "should only allow positive numeric ttl's" do subject.ttl = -100 - subject.should have(1).error_on(:ttl) + subject.valid? + expect( subject.errors[:ttl].size ).to eq(1) subject.ttl = '2d' - subject.should have(1).error_on(:ttl) + subject.valid? + expect( subject.errors[:ttl].size ).to eq(1) subject.ttl = 86400 - subject.should have(:no).errors_on(:ttl) + subject.valid? + expect( subject.errors[:ttl].size ).to eq(0) end it "should require a name" do - subject.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should not support priorities by default" do - subject.supports_prio?.should be_false + subject.supports_prio?.should be false end end @@ -55,7 +61,7 @@ record = FactoryGirl.create(:a, :domain => domain) serial = @soa.tap(&:reload).serial record.content = '10.0.0.1' - record.save.should be_true + record.save.should be true @soa.tap(&:reload).serial.should_not eql( serial ) end @@ -65,7 +71,8 @@ serial = @soa.tap(&:reload).serial - record.destroy.should be_true + record.destroy + expect( record.destroyed? ).to be true @soa.tap(&:reload).serial.should_not eql( serial ) end @@ -82,7 +89,7 @@ :content => '10.0.0.5', :ttl => 86400 ) - record.save.should be_true + record.save.should be true record = A.new( :domain => domain, @@ -90,7 +97,7 @@ :content => '10.0.0.6', :ttl => 86400 ) - record.save.should be_true + record.save.should be true record = A.new( :domain => domain, @@ -98,7 +105,7 @@ :content => '10.0.0.7', :ttl => 86400 ) - record.save.should be_true + record.save.should be true end # Our serial should have move just one position, not three @@ -123,7 +130,7 @@ :content => '10.0.0.5', :ttl => 86400 ) - record.save.should be_true + record.save.should be true @soa.reload @soa.serial.should_not eql(serial) @@ -134,7 +141,7 @@ :domain => domain, :content => '10.0.0.6' ) - record.save.should be_true + record.save.should be true record.name.should eql('example.com') end @@ -145,7 +152,7 @@ :name => 'test', :content => '10.0.0.6' ) - record.save.should be_true + record.save.should be true record.shortname.should eql('test') record.name.should eql('test.example.com') @@ -160,7 +167,7 @@ :name => 'ftp', :content => '10.0.0.6' ) - record.save.should be_true + record.save.should be true record.ttl.should be( 86400 ) end @@ -172,7 +179,7 @@ :content => '10.0.0.6', :ttl => 43200 ) - record.save.should be_true + record.save.should be true record.ttl.should be( 43200 ) end diff --git a/spec/models/record_template_spec.rb b/spec/models/record_template_spec.rb index 6c82c21f..9448dcc8 100644 --- a/spec/models/record_template_spec.rb +++ b/spec/models/record_template_spec.rb @@ -19,73 +19,87 @@ subject.should_not be_valid subject.content = '256.256.256.256' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = 'google.com' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) subject.content = '10.0.0.9' - subject.should have(:no).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "validations from CNAME" do subject.record_type = 'NS' subject.should_not be_valid - subject.should have(2).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(2) end it "validations from MX" do subject.record_type = 'MX' subject.should_not be_valid - subject.should have(1).error_on(:prio) - subject.should have(2).error_on(:content) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) + expect( subject.errors[:content].size ).to eq(2) subject.prio = -10 - subject.should have(1).error_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(1) # FIXME: Why is priority 0 at this stage? #subject.prio = 'low' #subject.should have(1).error_on(:prio) subject.prio = 10 - subject.should have(:no).errors_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(0) end it "validations from NS" do subject.record_type = 'NS' subject.should_not be_valid - subject.should have(2).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(2) end it "validations from TXT" do subject.record_type = 'TXT' subject.should_not be_valid - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "validations from SOA" do subject.record_type = 'SOA' subject.should_not be_valid - subject.should have(1).error_on(:primary_ns) + subject.valid? + expect( subject.errors[:primary_ns].size ).to eq(1) end it "validates contact address in SOA" do subject.record_type = 'SOA' - subject.should have(1).error_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(1) subject.contact = 'admin@example.com' - subject.should have(:no).errors_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(0) subject.contact = 'admin@%ZONE%' - subject.should have(:no).errors_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(0) subject.contact = 'admin' - subject.should have(1).error_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(1) end it "convenience methods from SOA" do diff --git a/spec/models/soa_spec.rb b/spec/models/soa_spec.rb index 362631ba..4da4671d 100644 --- a/spec/models/soa_spec.rb +++ b/spec/models/soa_spec.rb @@ -9,26 +9,32 @@ it "should be unique per domain" do subject.domain = FactoryGirl.create(:domain) - subject.should have(1).error_on(:domain_id) + subject.valid? + expect( subject.errors[:domain_id].size ).to eq(1) end it "should require a primary NS" do - subject.should have(1).error_on(:primary_ns) + subject.valid? + expect( subject.errors[:primary_ns].size ).to eq(1) end it "should require a contact" do - subject.should have(1).error_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(1) end it "should require a valid email address for the contact" do subject.contact = 'test' - subject.should have(1).error_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(1) subject.contact = 'test@example' - subject.should have(1).error_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(1) subject.contact = 'test@example.com' - subject.should have(:no).errors_on(:contact) + subject.valid? + expect( subject.errors[:contact].size ).to eq(0) end it "should flip the first period in the contact to an @" do @@ -45,28 +51,35 @@ it "should only accept positive integers as serials" do subject.serial = -2008040101 - subject.should have(1).error_on(:serial) + subject.valid? + expect( subject.errors[:serial].size ).to eq(1) subject.serial = 'ISBN123456789' - subject.should have(1).error_on(:serial) + subject.valid? + expect( subject.errors[:serial].size ).to eq(1) subject.serial = 2008040101 - subject.should have(:no).errors_on(:serial) + subject.valid? + expect( subject.errors[:serial].size ).to eq(0) end it "should require a refresh time" do - subject.should have(1).error_on(:refresh) + subject.valid? + expect( subject.errors[:refresh].size ).to eq(1) end it "should only accept positive integers as refresh time" do subject.refresh = -86400 - subject.should have(1).error_on(:refresh) + subject.valid? + expect( subject.errors[:refresh].size ).to eq(1) subject.refresh = '12h' - subject.should have(1).error_on(:refresh) + subject.valid? + expect( subject.errors[:refresh].size ).to eq(1) subject.refresh = 2008040101 - subject.should have(:no).errors_on(:refresh) + subject.valid? + expect( subject.errors[:refresh].size ).to eq(0) end it "should require a retry time" do @@ -75,48 +88,60 @@ it "should only accept positive integers as retry time" do subject.retry = -86400 - subject.should have(1).error_on(:retry) + subject.valid? + expect( subject.errors[:retry].size ).to eq(1) subject.retry = '15m' - subject.should have(1).error_on(:retry) + subject.valid? + expect( subject.errors[:retry].size ).to eq(1) subject.retry = 2008040101 - subject.should have(:no).errors_on(:retry) + subject.valid? + expect( subject.errors[:retry].size ).to eq(0) end it "should require a expiry time" do - subject.should have(1).error_on(:expire) + subject.valid? + expect( subject.errors[:expire].size ).to eq(1) end it "should only accept positive integers as expiry times" do subject.expire = -86400 - subject.should have(1).error_on(:expire) + subject.valid? + expect( subject.errors[:expire].size ).to eq(1) subject.expire = '2w' - subject.should have(1).error_on(:expire) + subject.valid? + expect( subject.errors[:expire].size ).to eq(1) subject.expire = 2008040101 - subject.should have(:no).errors_on(:expire) + subject.valid? + expect( subject.errors[:expire].size ).to eq(0) end it "should require a minimum time" do - subject.should have(1).error_on(:minimum) + subject.valid? + expect( subject.errors[:minimum].size ).to eq(1) end it "should only accept positive integers as minimum times" do subject.minimum = -86400 - subject.should have(1).error_on(:minimum) + subject.valid? + expect( subject.errors[:minimum].size ).to eq(1) subject.minimum = '3h' - subject.should have(1).error_on(:minimum) + subject.valid? + expect( subject.errors[:minimum].size ).to eq(1) subject.minimum = 10800 - subject.should have(:no).errors_on(:minimum) + subject.valid? + expect( subject.errors[:minimum].size ).to eq(0) end it "should not allow a minimum of more than 10800 seconds (RFC2308)" do subject.minimum = 84600 - subject.should have(1).error_on(:minimum) + subject.valid? + expect( subject.errors[:minimum].size ).to eq(1) end end diff --git a/spec/models/sshfp_spec.rb b/spec/models/sshfp_spec.rb index 5c946fdd..0dd17d0b 100644 --- a/spec/models/sshfp_spec.rb +++ b/spec/models/sshfp_spec.rb @@ -15,57 +15,68 @@ it "must accept a RSA key with a 40 digit hex SHA-1 fingerprint" do subject.content = '1 1 40ff0748d3c77616494546759a2095ecf13e6a3a' - subject.should have(:no).errors_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "must accept a RSA key with a less than 40 digit hex SHA-1 fingerprint" do subject.content = '1 1 40ff0748d3c77616494546759a2095ecf13e6a3' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must accept a RSA key with a more than 40 digit hex SHA-1 fingerprint" do subject.content = '1 1 40ff0748d3c77616494546759a2095ecf13e6a3a1' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must accept a DSA key with a 40 digit hex SHA-1 fingerprint" do subject.content = '2 1 d6d934e46c1c0993ab861d3302abdd1e11682e0e' - subject.should have(:no).errors_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "must not accept a DSA key with a less than 40 digit hex SHA-1 fingerprint" do subject.content = '2 1 d6d934e46c1c0993ab861d3302abdd1e11682e0' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a DSA key with a more than 40 digit hex SHA-1 fingerprint" do subject.content = '2 1 d6d934e46c1c0993ab861d3302abdd1e11682e0e3' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a key of type 0 (reserved)" do subject.content = '0 1 d6d934e46c1c0993ab861d3302abdd1e11682e0e' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a key of type higher than 3 (undefined)" do subject.content = '4 1 d6d934e46c1c0993ab861d3302abdd1e11682e0e' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a key with a fingerprint type 0 (reserved)" do subject.content = '1 0 d6d934e46c1c0993ab861d3302abdd1e11682e0e' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a key with a fingerprint type higher than 2 (undefined)" do subject.content = '1 3 d6d934e46c1c0993ab861d3302abdd1e11682e0e' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "must not accept a key with a fingerprint consisting of non-hex digits" do subject.content = '1 0 d6d934e46c1c0993ab861d3302abdd1e11682e0Y' - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end end end diff --git a/spec/models/txt_spec.rb b/spec/models/txt_spec.rb index 6f730343..fb00d2f6 100644 --- a/spec/models/txt_spec.rb +++ b/spec/models/txt_spec.rb @@ -8,7 +8,8 @@ end it "should require content" do - subject.should have(1).error_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(1) end it "should not tamper with content" do diff --git a/spec/models/zone_template_spec.rb b/spec/models/zone_template_spec.rb index 57612c90..a1acb6e5 100644 --- a/spec/models/zone_template_spec.rb +++ b/spec/models/zone_template_spec.rb @@ -2,58 +2,60 @@ describe ZoneTemplate, "when new" do - before(:each) do - @zone_template = ZoneTemplate.new - end - it "should be invalid by default" do - @zone_template.should_not be_valid + subject.should_not be_valid end it "should require a name" do - @zone_template.should have(1).error_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should have a unique name" do FactoryGirl.create(:zone_template) - @zone_template.name = "East Coast Data Center" - @zone_template.should have(1).error_on(:name) + subject.name = "East Coast Data Center" + subject.valid? + expect( subject.errors[:name].size ).to eq(1) end it "should require a TTL" do - @zone_template.ttl = nil - @zone_template.should have(1).error_on(:ttl) + subject.ttl = nil + subject.valid? + expect( subject.errors[:ttl].size ).to eq(1) end it "should not require optional owner" do - @zone_template.should have(:no).errors_on(:user_id) + subject.valid? + expect( subject.errors[:user_id].size ).to eq(0) end it "should require a master if it is a slave" do - @zone_template.type = 'SLAVE' - @zone_template.should have(1).error_on(:master) + subject.type = 'SLAVE' + subject.valid? + expect( subject.errors[:master].size ).to eq(1) end end describe ZoneTemplate, "when loaded" do + subject { FactoryGirl.create(:zone_template) } + before(:each) do - @zone_template = FactoryGirl.create(:zone_template) - FactoryGirl.create(:template_soa, :zone_template => @zone_template) + FactoryGirl.create(:template_soa, :zone_template => subject) end it "should have record templates" do - @zone_template.record_templates.should_not be_empty + subject.record_templates.should_not be_empty end it "should provide an easy way to build a zone" do - zone = @zone_template.build('example.org') + zone = subject.build('example.org') zone.should be_a_kind_of( Domain ) zone.should be_valid end it "should have a sense of validity" do - @zone_template.has_soa?.should be_true + subject.has_soa?.should be_true FactoryGirl.create( :zone_template, :name => 'West Coast Data Center' ).has_soa?.should_not be_true end @@ -61,17 +63,20 @@ describe ZoneTemplate, "with scopes" do + let(:quentin) { FactoryGirl.create(:quentin) } + + subject { FactoryGirl.create(:zone_template, :user => quentin) } + before(:each) do - @quentin = FactoryGirl.create(:quentin) - @zone_template = FactoryGirl.create(:zone_template, :user => @quentin) @other_template = FactoryGirl.create(:zone_template, :name => 'West Coast Data Center') end it "should only return a user's templates if not an admin" do - templates = ZoneTemplate.user(@quentin).all + subject # Sigh... + templates = ZoneTemplate.user(quentin).all templates.should_not be_empty templates.size.should be(1) - templates.each { |z| z.user.should eql( @quentin ) } + templates.each { |z| z.user.should eql( quentin ) } end it "should return all templates if the user is an admin" do @@ -84,20 +89,21 @@ templates = ZoneTemplate.with_soa.all templates.should be_empty - FactoryGirl.create(:template_soa, :zone_template => @zone_template) + FactoryGirl.create(:template_soa, :zone_template => subject) ZoneTemplate.with_soa.all.should_not be_empty end end describe ZoneTemplate, "when used to build a zone" do + subject { FactoryGirl.create(:zone_template) } + before(:each) do - @zone_template = FactoryGirl.create(:zone_template) - FactoryGirl.create(:template_soa, :zone_template => @zone_template) - FactoryGirl.create(:template_ns, :zone_template => @zone_template) - FactoryGirl.create(:template_ns, :content => 'ns2.%ZONE%', :zone_template => @zone_template) + FactoryGirl.create(:template_soa, :zone_template => subject) + FactoryGirl.create(:template_ns, :zone_template => subject) + FactoryGirl.create(:template_ns, :content => 'ns2.%ZONE%', :zone_template => subject) - @domain = @zone_template.build( 'example.org' ) + @domain = subject.build( 'example.org' ) end it "should create a valid new zone" do @@ -106,7 +112,7 @@ end it "should create the correct number of records (from templates)" do - @domain.records.size.should eql( @zone_template.record_templates.size ) + @domain.records.size.should eql( subject.record_templates.size ) end it "should create a SOA record" do @@ -128,16 +134,17 @@ describe ZoneTemplate, "when used to build a zone for a user" do + subject { FactoryGirl.create(:zone_template) } + before(:each) do @user = FactoryGirl.create(:quentin) - @zone_template = FactoryGirl.create(:zone_template, :user => @quentin) - FactoryGirl.create(:template_soa, :zone_template => @zone_template) - FactoryGirl.create(:template_ns, :zone_template => @zone_template) - FactoryGirl.create(:template_ns, :name => 'ns2.%ZONE%', :zone_template => @zone_template) - FactoryGirl.create(:template_cname, :zone_template => @zone_template) - FactoryGirl.create(:template_cname, :name => 'www.%ZONE%', :zone_template => @zone_template) + FactoryGirl.create(:template_soa, :zone_template => subject) + FactoryGirl.create(:template_ns, :zone_template => subject) + FactoryGirl.create(:template_ns, :name => 'ns2.%ZONE%', :zone_template => subject) + FactoryGirl.create(:template_cname, :zone_template => subject) + FactoryGirl.create(:template_cname, :name => 'www.%ZONE%', :zone_template => subject) - @domain = @zone_template.build( 'example.org', @user ) + @domain = subject.build( 'example.org', @user ) end it "should create a valid new zone" do @@ -150,7 +157,7 @@ end it "should create the correct number of records (from templates)" do - @domain.records.size.should eql( @zone_template.record_templates.size ) + @domain.records.size.should eql( subject.record_templates.size ) end it "should create a SOA record" do From f537d238214e99a3d1333075633b35fef6d0d15e Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 01:35:34 +0200 Subject: [PATCH 08/31] feat: 2.2 first class citizen --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f943fe05..3aadab2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,6 @@ script: "bundle exec rake spec" matrix: allow_failures: - - rvm: 2.2 - rvm: jruby-19mode - rvm: rbx-19mode - env: DB=sqlite From 70a6767a8b16869aaa60d5fe2c8e532199ae39bd Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 10:28:11 +0200 Subject: [PATCH 09/31] fix: bump mysql to 0.3.17 for Ruby 2.2. --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 24d54036..d8db9992 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ group :assets do end platforms :ruby do - gem 'mysql2', '~> 0.3.11' + gem 'mysql2', '~> 0.3.17' gem 'pg', '>= 0.9.0' gem 'sqlite3' gem 'therubyracer' diff --git a/Gemfile.lock b/Gemfile.lock index d583f16f..a3e2d739 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -152,7 +152,7 @@ GEM mocha (0.13.0) metaclass (~> 0.0.1) multi_json (1.10.1) - mysql2 (0.3.11) + mysql2 (0.3.17) nenv (0.1.1) nokogiri (1.6.3.1) mini_portile (= 0.6.0) From ccaa06d10f142457c92ce0e089e153a821d20b62 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 10:33:33 +0200 Subject: [PATCH 10/31] fix: bump sqlite3 to 1.3.10 for 2.2 compatibility --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index d8db9992..493fe200 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ end platforms :ruby do gem 'mysql2', '~> 0.3.17' gem 'pg', '>= 0.9.0' - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.10' gem 'therubyracer' end diff --git a/Gemfile.lock b/Gemfile.lock index a3e2d739..93c1b7b0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -237,7 +237,7 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.7) + sqlite3 (1.3.10) state_machine (1.1.2) strong_parameters (0.2.3) actionpack (~> 3.0) @@ -295,7 +295,7 @@ DEPENDENCIES rails (~> 3.2.21) rspec-rails (~> 2.99.0) sass-rails - sqlite3 + sqlite3 (~> 1.3.10) state_machine strong_parameters therubyracer From fb5039c08c61a2e1ff7a93885f5a0398da92136e Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 10:33:54 +0200 Subject: [PATCH 11/31] chore: bump pg gem to 0.18.1 --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 493fe200..e7f56525 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ end platforms :ruby do gem 'mysql2', '~> 0.3.17' - gem 'pg', '>= 0.9.0' + gem 'pg', '~> 0.18.1' gem 'sqlite3', '~> 1.3.10' gem 'therubyracer' end diff --git a/Gemfile.lock b/Gemfile.lock index 93c1b7b0..c7408f3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,7 +160,7 @@ GEM nenv (~> 0.1) shellany (~> 0.0) orm_adapter (0.5.0) - pg (0.15.0) + pg (0.18.1) polyglot (0.3.5) pry (0.10.1) coderay (~> 1.1.0) @@ -289,8 +289,8 @@ DEPENDENCIES inherited_resources jquery-rails mocha - mysql2 (~> 0.3.11) - pg (>= 0.9.0) + mysql2 (~> 0.3.17) + pg (~> 0.18.1) rabl rails (~> 3.2.21) rspec-rails (~> 2.99.0) From 0b55608b694e4ec1369155d4a4966ac653813f8e Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 14:13:54 +0200 Subject: [PATCH 12/31] fix: added test-unit to Gemfile for Ruby 2.2 --- Gemfile | 1 + Gemfile.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index e7f56525..e1bce12b 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,7 @@ end group :development, :test do gem "rspec-rails", "~> 2.99.0" gem 'RedCloth', '>= 4.1.1' + gem 'test-unit', :platform => :ruby_22 end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index c7408f3b..4ee9b07a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -298,6 +298,7 @@ DEPENDENCIES sqlite3 (~> 1.3.10) state_machine strong_parameters + test-unit therubyracer uglifier webrat From 7a8193d6093a67173d24980395a79b80476219ae Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 14:14:08 +0200 Subject: [PATCH 13/31] switch to 2.2.0 for development --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 7d2ed7c7..ccbccc3d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.4 +2.2.0 From 079a2af40dd1ee5cf0ba67fb81e2cfb155fa6a3a Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 14:33:04 +0200 Subject: [PATCH 14/31] fix: ensure a compatible bundler on travis-ci --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3aadab2a..c9d5e921 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: ruby +before_install: gem install bundler -v '~> 1.7.12' bundler_args: --without development rvm: From 859963473f9e5d5a18adfe71f3167e8c6958e67b Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 14:45:44 +0200 Subject: [PATCH 15/31] Revert "fix: ensure a compatible bundler on travis-ci" This reverts commit 079a2af40dd1ee5cf0ba67fb81e2cfb155fa6a3a. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c9d5e921..3aadab2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: ruby -before_install: gem install bundler -v '~> 1.7.12' bundler_args: --without development rvm: From 1beb72e212cbd9120edfd020db9db4d2ba3b84ba Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 14:47:05 +0200 Subject: [PATCH 16/31] remove :ruby_22 restriction on test-unit --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e1bce12b..1899d386 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,7 @@ end group :development, :test do gem "rspec-rails", "~> 2.99.0" gem 'RedCloth', '>= 4.1.1' - gem 'test-unit', :platform => :ruby_22 + gem 'test-unit' end group :test do From 3280c84120372b8187b489d969368a73d004fd37 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 16:55:45 +0200 Subject: [PATCH 17/31] chore: removed unused debugger gem --- Gemfile | 1 - Gemfile.lock | 9 --------- 2 files changed, 10 deletions(-) diff --git a/Gemfile b/Gemfile index 1899d386..0195df76 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,6 @@ gem 'acts_as_list' gem 'dynamic_form' group :development do - gem 'debugger', :platform => :mri_19 gem 'guard-rspec', :require => false #gem 'RedCloth', '>= 4.1.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 4ee9b07a..4f41084f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,6 @@ GEM coffee-script-source execjs coffee-script-source (1.4.0) - columnize (0.3.6) cucumber (1.2.1) builder (>= 2.1.2) diff-lcs (>= 1.1.3) @@ -69,13 +68,6 @@ GEM cucumber (>= 1.1.8) nokogiri (>= 1.5.0) database_cleaner (0.9.1) - debugger (1.4.0) - columnize (>= 0.3.1) - debugger-linecache (~> 1.1.1) - debugger-ruby_core_source (~> 1.2.0) - debugger-linecache (1.1.2) - debugger-ruby_core_source (>= 1.1.1) - debugger-ruby_core_source (1.2.0) devise (2.2.8) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -279,7 +271,6 @@ DEPENDENCIES coffee-rails cucumber-rails database_cleaner - debugger devise (~> 2.2.8) devise-encryptable dynamic_form From 99a298c1622c1752ff491e8e6e46ce02ec152af8 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 16:56:14 +0200 Subject: [PATCH 18/31] erm, test-unit again :| --- Gemfile | 2 +- Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0195df76..cb91bae6 100644 --- a/Gemfile +++ b/Gemfile @@ -36,9 +36,9 @@ group :development do end group :development, :test do + gem "test-unit" gem "rspec-rails", "~> 2.99.0" gem 'RedCloth', '>= 4.1.1' - gem 'test-unit' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 4f41084f..f4f772f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -154,6 +154,7 @@ GEM orm_adapter (0.5.0) pg (0.18.1) polyglot (0.3.5) + power_assert (0.2.2) pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -236,6 +237,8 @@ GEM activemodel (~> 3.0) activesupport (~> 3.0) railties (~> 3.0) + test-unit (3.0.9) + power_assert therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref From 22e60ff627531f163b1125f2b2b8c068e70f4cc1 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 18:32:18 +0200 Subject: [PATCH 19/31] chore: upgraded factory_girl --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f4f772f7..edc548ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,10 +80,10 @@ GEM erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) - factory_girl (4.2.0) + factory_girl (4.5.0) activesupport (>= 3.0.0) - factory_girl_rails (4.2.1) - factory_girl (~> 4.2.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) railties (>= 3.0.0) ffi (1.9.6) formatador (0.2.5) From 6ca237292626b7e278c2813b6a913727f3b491f1 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 18:33:44 +0200 Subject: [PATCH 20/31] fixed a few more deprecation warnings from rspec --- spec/models/domain_spec.rb | 12 ++++++++---- spec/models/macro_step_spec.rb | 15 ++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index e3188a00..b9bd11ca 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -37,7 +37,8 @@ end it "should not require a MASTER" do - subject.should have(:no).errors_on(:master) + subject.valid? + expect( subject.errors[:master].size ).to eq(0) end end @@ -55,11 +56,13 @@ expect( subject.errors[:master].size ).to eq(1) subject.master = '127.0.0.1' - subject.should have(:no).errors_on(:master) + subject.valid? + expect( subject.errors[:master].size ).to eq(0) end it "should not bail out on missing SOA fields" do - subject.should have(:no).errors_on( :primary_ns ) + subject.valid? + expect( subject.errors[:primary_ns].size ).to eq(0) end end @@ -103,7 +106,8 @@ end it "should not complain about missing SOA fields" do - subject.should have(:no).errors_on(:primary_ns) + subject.valid? + expect( subject.errors[:primary_ns].size ).to eq(0) end end diff --git a/spec/models/macro_step_spec.rb b/spec/models/macro_step_spec.rb index d2deb4c5..befee086 100644 --- a/spec/models/macro_step_spec.rb +++ b/spec/models/macro_step_spec.rb @@ -20,7 +20,8 @@ it "should only accept allowed actions" do [ 'create', 'remove', 'update' ].each do |valid_action| subject.action = valid_action - subject.should have(:no).errors_on(:action) + subject.valid? + expect( subject.errors[:action].size ).to eq(0) end subject.action = 'foo' @@ -39,7 +40,8 @@ next if known_record_type == 'SOA' subject.record_type = known_record_type - subject.should have(:no).errors_on(:record_type) + subject.valid? + expect( subject.errors[:record_type].size ).to eq(0) end subject.record_type = 'SOA' @@ -48,7 +50,8 @@ end it "should not require a record name" do - subject.should have(:no).errors_on(:name) + subject.valid? + expect( subject.errors[:name].size ).to eq(0) end it "should require content" do @@ -106,12 +109,14 @@ end it "should not require content" do - subject.should have(:no).errors_on(:content) + subject.valid? + expect( subject.errors[:content].size ).to eq(0) end it "should not require prio on MX" do subject.record_type = 'MX' - subject.should have(:no).errors_on(:prio) + subject.valid? + expect( subject.errors[:prio].size ).to eq(0) end end From b396de3ffca2af5723257b10fad1b518aa153c11 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 18:34:17 +0200 Subject: [PATCH 21/31] chore: cleanup of a factory --- spec/factories/domain_factory.rb | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/factories/domain_factory.rb b/spec/factories/domain_factory.rb index 8b1f3c02..fab07efe 100644 --- a/spec/factories/domain_factory.rb +++ b/spec/factories/domain_factory.rb @@ -1,12 +1,12 @@ FactoryGirl.define do - factory :domain, :class => 'Domain' do + factory :domain do name 'example.com' add_attribute :type, 'NATIVE' ttl 86400 # soa - primary_ns { |d| "ns1.#{d.name}" } - contact { |d| "admin@#{d.name}" } + primary_ns { "ns1.#{name}" } + contact { "admin@#{name}" } refresh 10800 self.retry 7200 # retry is a keyword in ruby expire 604800 @@ -25,40 +25,40 @@ # minimum 10800 #end - factory :ns, :class => NS do + factory :ns, :class => 'NS' do ttl 86400 - name { |r| r.domain.name } - content { |r| "ns1.#{r.domain.name}" } + name { domain.name } + content { "ns1.#{domain.name}" } end - factory :ns_a, :class => A do + factory :ns_a, :class => 'A' do ttl 86400 - name { |r| "ns1.#{r.domain.name}" } + name { "ns1.#{domain.name}" } content "10.0.0.1" end - factory :a, :class => A do + factory :a, :class => 'A' do ttl 86400 - name { |r| r.domain.name } + name { domain.name } content '10.0.0.3' end - factory :www, :class => A do + factory :www, :class => 'A' do ttl 86400 - name { |r| "www.#{r.domain.name}" } + name { "www.#{domain.name}" } content '10.0.0.3' end - factory :mx, :class => MX do + factory :mx, :class => 'MX' do ttl 86400 - name { |r| r.domain.name } - content { |r| "mail.#{r.domain.name}" } + name { domain.name } + content { "mail.#{domain.name}" } prio 10 end - factory :mx_a, :class => A do + factory :mx_a, :class => 'A' do ttl 86400 - name { |r| "mail.#{r.domain.name}" } + name { "mail.#{domain.name}" } content '10.0.0.4' end From ceafb696b3c3cd5fd9b68412b3ff1735f5c06cd8 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 18:38:51 +0200 Subject: [PATCH 22/31] Convert specs to RSpec 2.99.2 syntax with Transpec This conversion is done by Transpec 3.0.7 with the following command: transpec * 443 conversions from: obj.should to: expect(obj).to * 128 conversions from: obj.should_not to: expect(obj).not_to * 25 conversions from: be_true to: be_truthy * 22 conversions from: == expected to: eq(expected) * 7 conversions from: be_false to: be_falsey * 2 conversions from: > expected to: be > expected * 2 conversions from: lambda { }.should to: expect { }.to * 1 conversion from: < expected to: be < expected * 1 conversion from: lambda { }.should_not to: expect { }.not_to * 1 conversion from: obj.stub(:message) to: allow(obj).to receive(:message) * 1 conversion from: pending to: skip * 1 conversion from: pending 'is an example' { } to: skip 'is an example' { } * 1 addition of: RSpec.configure { |c| c.infer_spec_type_from_file_location! } For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/controllers/audits_controller_spec.rb | 6 +- .../auth_tokens_controller_spec.rb | 62 ++++----- spec/controllers/dashboard_controller_spec.rb | 2 +- spec/controllers/domains_controller_spec.rb | 80 ++++++------ .../macro_steps_controller_spec.rb | 20 +-- spec/controllers/macros_controller_spec.rb | 54 ++++---- .../record_template_controller_spec.rb | 2 +- spec/controllers/records_controller_spec.rb | 66 +++++----- spec/controllers/reports_controller_spec.rb | 28 ++-- spec/controllers/search_controller_spec.rb | 30 ++--- spec/controllers/sessions_controller_spec.rb | 18 +-- spec/controllers/templates_controller_spec.rb | 18 +-- spec/controllers/users_controller_spec.rb | 54 ++++---- spec/helpers/application_helper_spec.rb | 4 +- spec/helpers/audits_helper_spec.rb | 32 ++--- spec/helpers/macro_steps_helper_spec.rb | 2 +- spec/helpers/macros_helper_spec.rb | 2 +- spec/models/a_spec.rb | 2 +- spec/models/aaaa_spec.rb | 2 +- spec/models/auth_token_spec.rb | 120 +++++++++--------- spec/models/cname_spec.rb | 2 +- spec/models/domain_spec.rb | 52 ++++---- spec/models/macro_spec.rb | 10 +- spec/models/macro_step_spec.rb | 8 +- spec/models/mx_spec.rb | 6 +- spec/models/ns_spec.rb | 2 +- spec/models/record_spec.rb | 52 ++++---- spec/models/record_template_spec.rb | 54 ++++---- spec/models/soa_spec.rb | 54 ++++---- spec/models/spf_spec.rb | 2 +- spec/models/srv_spec.rb | 2 +- spec/models/sshfp_spec.rb | 2 +- spec/models/txt_spec.rb | 4 +- spec/models/user_spec.rb | 36 +++--- spec/models/zone_template_spec.rb | 70 +++++----- spec/spec_helper.rb | 11 ++ spec/views/audits/domain.html.haml_spec.rb | 8 +- spec/views/domains/_record.html.haml_spec.rb | 52 ++++---- .../domains/apply_macro.html.haml_spec.rb | 2 +- spec/views/domains/new.html.haml_spec.rb | 8 +- spec/views/domains/show.html.haml_spec.rb | 52 ++++---- spec/views/macro_steps/create.js.rjs_spec.rb | 8 +- spec/views/macro_steps/update.js.rjs_spec.rb | 10 +- spec/views/macros/edit.html.haml_spec.rb | 8 +- spec/views/macros/index.html.haml_spec.rb | 6 +- spec/views/macros/show.html.haml_spec.rb | 12 +- spec/views/search/results.html.haml_spec.rb | 10 +- spec/views/templates/edit.html.haml_spec.rb | 2 +- spec/views/templates/new.html.haml_spec.rb | 8 +- spec/views/templates/show.html.haml_spec.rb | 14 +- 50 files changed, 591 insertions(+), 580 deletions(-) diff --git a/spec/controllers/audits_controller_spec.rb b/spec/controllers/audits_controller_spec.rb index dc8f9b1b..28a710d5 100644 --- a/spec/controllers/audits_controller_spec.rb +++ b/spec/controllers/audits_controller_spec.rb @@ -9,14 +9,14 @@ it "should have a search form" do get :index - response.should render_template('audits/index') + expect(response).to render_template('audits/index') end it "should have a domain details page" do get :domain, :id => FactoryGirl.create(:domain).id - assigns(:domain).should_not be_nil + expect(assigns(:domain)).not_to be_nil - response.should render_template('audits/domain') + expect(response).to render_template('audits/domain') end end diff --git a/spec/controllers/auth_tokens_controller_spec.rb b/spec/controllers/auth_tokens_controller_spec.rb index 758b7f73..5519c3b5 100644 --- a/spec/controllers/auth_tokens_controller_spec.rb +++ b/spec/controllers/auth_tokens_controller_spec.rb @@ -5,11 +5,11 @@ it "should not allow access to admins or owners" do sign_in( FactoryGirl.create(:admin) ) post :create - response.code.should eql("302") + expect(response.code).to eql("302") sign_in(FactoryGirl.create(:quentin)) post :create - response.code.should eql("302") + expect(response.code).to eql("302") end it "should bail cleanly on missing auth_token" do @@ -17,7 +17,7 @@ post :create - response.code.should eql("422") + expect(response.code).to eql("422") end it "should bail cleanly on missing domains" do @@ -25,7 +25,7 @@ post :create, :auth_token => { :domain => 'example.org' } - response.code.should eql("404") + expect(response.code).to eql("404") end it "bail cleanly on invalid requests" do @@ -35,7 +35,7 @@ post :create, :auth_token => { :domain => 'example.com' } - response.should have_selector('error') + expect(response).to have_selector('error') end describe "generating tokens" do @@ -50,35 +50,35 @@ it "with allow_new set" do post :create, :auth_token => @params.merge(:allow_new => 'true') - response.should have_selector('token > expires') - response.should have_selector('token > auth_token') - response.should have_selector('token > url') + expect(response).to have_selector('token > expires') + expect(response).to have_selector('token > auth_token') + expect(response).to have_selector('token > url') - assigns(:auth_token).should_not be_nil - assigns(:auth_token).domain.should eql( @domain ) - assigns(:auth_token).should be_allow_new_records + expect(assigns(:auth_token)).not_to be_nil + expect(assigns(:auth_token).domain).to eql( @domain ) + expect(assigns(:auth_token)).to be_allow_new_records end it "with remove set" do a = FactoryGirl.create(:www, :domain => @domain) post :create, :auth_token => @params.merge(:remove => 'true', :record => ['www.example.com']) - response.should have_selector('token > expires') - response.should have_selector('token > auth_token') - response.should have_selector('token > url') + expect(response).to have_selector('token > expires') + expect(response).to have_selector('token > auth_token') + expect(response).to have_selector('token > url') - assigns(:auth_token).remove_records?.should be_true - assigns(:auth_token).can_remove?( a ).should be_true + expect(assigns(:auth_token).remove_records?).to be_truthy + expect(assigns(:auth_token).can_remove?( a )).to be_truthy end it "with policy set" do post :create, :auth_token => @params.merge(:policy => 'allow') - response.should have_selector('token > expires') - response.should have_selector('token > auth_token') - response.should have_selector('token > url') + expect(response).to have_selector('token > expires') + expect(response).to have_selector('token > auth_token') + expect(response).to have_selector('token > url') - assigns(:auth_token).policy.should eql(:allow) + expect(assigns(:auth_token).policy).to eql(:allow) end it "with protected records" do @@ -91,14 +91,14 @@ :policy => 'allow' ) - response.should have_selector('token > expires') - response.should have_selector('token > auth_token') - response.should have_selector('token > url') + expect(response).to have_selector('token > expires') + expect(response).to have_selector('token > auth_token') + expect(response).to have_selector('token > url') - assigns(:auth_token).should_not be_nil - assigns(:auth_token).can_change?( a ).should be_false - assigns(:auth_token).can_change?( mx ).should be_true - assigns(:auth_token).can_change?( www ).should be_false + expect(assigns(:auth_token)).not_to be_nil + expect(assigns(:auth_token).can_change?( a )).to be_falsey + expect(assigns(:auth_token).can_change?( mx )).to be_truthy + expect(assigns(:auth_token).can_change?( www )).to be_falsey end it "with protected record types" do @@ -106,7 +106,7 @@ post :create, :auth_token => @params.merge(:policy => 'allow', :protect_type => ['MX']) - assigns(:auth_token).can_change?( mx ).should be_false + expect(assigns(:auth_token).can_change?( mx )).to be_falsey end it "with allowed records" do @@ -116,9 +116,9 @@ post :create, :auth_token => @params.merge(:record => ['example.com']) - assigns(:auth_token).can_change?( www ).should be_false - assigns(:auth_token).can_change?( a ).should be_true - assigns(:auth_token).can_change?( mx ).should be_true + expect(assigns(:auth_token).can_change?( www )).to be_falsey + expect(assigns(:auth_token).can_change?( a )).to be_truthy + expect(assigns(:auth_token).can_change?( mx )).to be_truthy end end diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index 73a5e045..96288a24 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -11,7 +11,7 @@ end it "should have a list of the latest zones" do - assigns(:latest_domains).should_not be_empty + expect(assigns(:latest_domains)).not_to be_empty end end diff --git a/spec/controllers/domains_controller_spec.rb b/spec/controllers/domains_controller_spec.rb index d0fedfd9..d0c02f2b 100644 --- a/spec/controllers/domains_controller_spec.rb +++ b/spec/controllers/domains_controller_spec.rb @@ -9,9 +9,9 @@ get 'index' - response.should render_template('domains/index') - assigns(:domains).should_not be_empty - assigns(:domains).size.should be(Domain.count) + expect(response).to render_template('domains/index') + expect(assigns(:domains)).not_to be_empty + expect(assigns(:domains).size).to be(Domain.count) end it "should restrict zones for owners" do @@ -23,9 +23,9 @@ get 'index' - response.should render_template('domains/index') - assigns(:domains).should_not be_empty - assigns(:domains).size.should be(1) + expect(response).to render_template('domains/index') + expect(assigns(:domains)).not_to be_empty + expect(assigns(:domains).size).to be(1) end it "should display all zones as XML" do @@ -35,8 +35,8 @@ get :index, :format => 'xml' - assigns(:domains).should_not be_empty - response.should have_tag('domains') + expect(assigns(:domains)).not_to be_empty + expect(response).to have_tag('domains') end end @@ -52,7 +52,7 @@ get 'new' - response.should render_template('domains/new') + expect(response).to render_template('domains/new') end it "should not save a partial form" do @@ -63,8 +63,8 @@ post 'create', :domain => { :name => 'example.org' }, :zone_template => { :id => "" } }.to_not change( Domain, :count ) - response.should_not be_redirect - response.should render_template('domains/new') + expect(response).not_to be_redirect + expect(response).to render_template('domains/new') end it "should build from a zone template if selected" do @@ -75,9 +75,9 @@ post 'create', :domain => { :name => 'example.org', :zone_template_id => zone_template.id } }.to change( Domain, :count ).by(1) - assigns(:domain).should_not be_nil - response.should be_redirect - response.should redirect_to( domain_path(assigns(:domain)) ) + expect(assigns(:domain)).not_to be_nil + expect(response).to be_redirect + expect(response).to redirect_to( domain_path(assigns(:domain)) ) end it "should be redirected to the zone details after a successful save" do @@ -88,9 +88,9 @@ :expire => 604800, :minimum => 10800, :zone_template_id => "" } }.to change( Domain, :count ).by(1) - response.should be_redirect - response.should redirect_to( domain_path( assigns(:domain) ) ) - flash[:notice].should_not be_nil + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( assigns(:domain) ) ) + expect(flash[:notice]).not_to be_nil end it "should ignore the zone template if a slave is created" do @@ -105,10 +105,10 @@ } }.to change( Domain, :count ).by(1) - assigns(:domain).should be_slave - assigns(:domain).soa_record.should be_nil + expect(assigns(:domain)).to be_slave + expect(assigns(:domain).soa_record).to be_nil - response.should be_redirect + expect(response).to be_redirect end end @@ -127,7 +127,7 @@ domain.reload }.to change( domain, :user_id ) - response.should render_template('domains/change_owner') + expect(response).to render_template('domains/change_owner') end end @@ -143,18 +143,18 @@ it "should have a selection for the user" do get :apply_macro, :id => @domain.id - assigns(:domain).should_not be_nil - assigns(:macros).should_not be_empty + expect(assigns(:domain)).not_to be_nil + expect(assigns(:macros)).not_to be_empty - response.should render_template('domains/apply_macro') + expect(response).to render_template('domains/apply_macro') end it "should apply the selected macro" do post :apply_macro, :id => @domain.id, :macro_id => @macro.id - flash[:notice].should_not be_blank - response.should be_redirect - response.should redirect_to( domain_path( @domain ) ) + expect(flash[:notice]).not_to be_blank + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( @domain ) ) end end @@ -178,7 +178,7 @@ }.to change( Domain, :count ).by( 1 ) data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("id", "name", "type", "records") + expect(data.keys).to include("id", "name", "type", "records") end it "creating a zone with a template" do @@ -190,7 +190,7 @@ :format => "json" data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("id", "name", "type", "records") + expect(data.keys).to include("id", "name", "type", "records") end it "creating a zone with a named template" do @@ -202,7 +202,7 @@ :format => "json" data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("id", "name", "type", "records") + expect(data.keys).to include("id", "name", "type", "records") end it "creating a zone with invalid input" do @@ -213,8 +213,8 @@ }.to_not change( Domain, :count ) data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("errors") - data["errors"].should_not be_empty + expect(data.keys).to include("errors") + expect(data["errors"]).not_to be_empty end it "removing zones" do @@ -233,7 +233,7 @@ data = ActiveSupport::JSON.decode( response.body ) expect( data.size ).to eq(1) - data.first.keys.should include("id", "name") + expect(data.first.keys).to include("id", "name") end it "viewing a zone" do @@ -243,7 +243,7 @@ get :show, :id => domain.id, :format => 'json' data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("records") + expect(data.keys).to include("records") end it "getting a list of macros to apply" do @@ -260,10 +260,10 @@ post :apply_macro, :id => domain.id, :macro_id => macro.id, :format => 'json' - response.code.should == "202" + expect(response.code).to eq("202") data = ActiveSupport::JSON.decode( response.body ) - data.keys.should include("id", "name", "type", "records") + expect(data.keys).to include("id", "name", "type", "records") end end @@ -280,24 +280,24 @@ xit "should display the domain in the token" do get :show, :id => @domain.id - response.should render_template('domains/show') + expect(response).to render_template('domains/show') end xit "should restrict the domain to that of the token" do get :show, :id => rand(1_000_000) - assigns(:domain).should eql(@domain) + expect(assigns(:domain)).to eql(@domain) end xit "should not allow a list of domains" do get :index - response.should be_redirect + expect(response).to be_redirect end xit "should not accept updates to the domain" do put :update, :id => @domain, :domain => { :name => 'hack' } - response.should be_redirect + expect(response).to be_redirect end end diff --git a/spec/controllers/macro_steps_controller_spec.rb b/spec/controllers/macro_steps_controller_spec.rb index 33442cb5..75074d59 100644 --- a/spec/controllers/macro_steps_controller_spec.rb +++ b/spec/controllers/macro_steps_controller_spec.rb @@ -23,7 +23,7 @@ }, :format => 'js' }.to change(@macro.macro_steps(true), :count) - response.should render_template('macro_steps/create') + expect(response).to render_template('macro_steps/create') end it "should position a valid step correctly" do @@ -36,7 +36,7 @@ :position => '1' }, :format => 'js' - assigns(:macro_step).position.should == 1 + expect(assigns(:macro_step).position).to eq(1) end it "should not create an invalid step" do @@ -48,7 +48,7 @@ }, :format => 'js' }.to_not change(@macro.macro_steps(true), :count) - response.should render_template('macro_steps/create') + expect(response).to render_template('macro_steps/create') end it "should accept valid updates to steps" do @@ -57,9 +57,9 @@ :name => 'local' }, :format => 'js' - response.should render_template('macro_steps/update') + expect(response).to render_template('macro_steps/update') - @step.reload.name.should == 'local' + expect(@step.reload.name).to eq('local') end it "should not accept valid updates" do @@ -68,7 +68,7 @@ :name => '' }, :format => 'js' - response.should render_template('macro_steps/update') + expect(response).to render_template('macro_steps/update') end it "should re-position existing steps" do @@ -77,15 +77,15 @@ put :update, :macro_id => @macro.id, :id => @step.id, :macro_step => { :position => '2' } - @step.reload.position.should == 2 + expect(@step.reload.position).to eq(2) end it "should remove selected steps when asked" do delete :destroy, :macro_id => @macro, :id => @step.id, :format => 'js' - flash[:info].should_not be_blank - response.should be_redirect - response.should redirect_to(macro_path(@macro)) + expect(flash[:info]).not_to be_blank + expect(response).to be_redirect + expect(response).to redirect_to(macro_path(@macro)) expect { @step.reload }.to raise_error( ActiveRecord::RecordNotFound ) end diff --git a/spec/controllers/macros_controller_spec.rb b/spec/controllers/macros_controller_spec.rb index 401d7230..df205936 100644 --- a/spec/controllers/macros_controller_spec.rb +++ b/spec/controllers/macros_controller_spec.rb @@ -15,25 +15,25 @@ it "should have a list of macros" do get :index - assigns(:macros).should_not be_nil + expect(assigns(:macros)).not_to be_nil - response.should render_template('macros/index') + expect(response).to render_template('macros/index') end it "should have a detailed view of a macro" do get :show, :id => @macro.id - assigns(:macro).should == @macro + expect(assigns(:macro)).to eq(@macro) - response.should render_template('macros/show') + expect(response).to render_template('macros/show') end it "should have a form for creating new macros" do get :new - assigns(:macro).should be_a_new_record + expect(assigns(:macro)).to be_a_new_record - response.should render_template('macros/edit') + expect(response).to render_template('macros/edit') end it "should create valid macros" do @@ -45,9 +45,9 @@ } }.to change(Macro, :count).by(1) - flash[:notice].should_not be_nil - response.should be_redirect - response.should redirect_to( macro_path(assigns(:macro) ) ) + expect(flash[:notice]).not_to be_nil + expect(response).to be_redirect + expect(response).to redirect_to( macro_path(assigns(:macro) ) ) end it "should render the form on invalid macros" do @@ -55,17 +55,17 @@ :name => '' } - flash[:info].should be_nil - response.should_not be_redirect - response.should render_template('macros/edit') + expect(flash[:info]).to be_nil + expect(response).not_to be_redirect + expect(response).to render_template('macros/edit') end it "should have an edit form for macros" do get :edit, :id => @macro.id - assigns(:macro).should == @macro + expect(assigns(:macro)).to eq(@macro) - response.should render_template('macros/edit') + expect(response).to render_template('macros/edit') end it "should accept valid updates to macros" do @@ -74,9 +74,9 @@ @macro.reload }.to change(@macro, :name) - flash[:notice].should_not be_nil - response.should be_redirect - response.should redirect_to( macro_path( @macro ) ) + expect(flash[:notice]).not_to be_nil + expect(response).to be_redirect + expect(response).to redirect_to( macro_path( @macro ) ) end it "should reject invalid updates" do @@ -85,18 +85,18 @@ @macro.reload }.to_not change(@macro, :name) - flash[:notice].should be_blank - response.should_not be_redirect - response.should render_template('macros/edit') + expect(flash[:notice]).to be_blank + expect(response).not_to be_redirect + expect(response).to render_template('macros/edit') end it "should remove a macro if asked to" do delete :destroy, :id => @macro.id - assigns(:macro).should be_frozen - flash[:notice].should_not be_nil - response.should be_redirect - response.should redirect_to( macros_path ) + expect(assigns(:macro)).to be_frozen + expect(flash[:notice]).not_to be_nil + expect(response).to be_redirect + expect(response).to redirect_to( macros_path ) end end @@ -113,10 +113,10 @@ it "should have a form to create a new macro" do get :new - assigns(:users).should be_nil - assigns(:macro).should be_a_new_record + expect(assigns(:users)).to be_nil + expect(assigns(:macro)).to be_a_new_record - response.should render_template('macros/edit') + expect(response).to render_template('macros/edit') end end diff --git a/spec/controllers/record_template_controller_spec.rb b/spec/controllers/record_template_controller_spec.rb index fa7e2f70..ca05e1ce 100644 --- a/spec/controllers/record_template_controller_spec.rb +++ b/spec/controllers/record_template_controller_spec.rb @@ -27,7 +27,7 @@ } target_soa.reload - target_soa.primary_ns.should eql('ns1.provider.net') + expect(target_soa.primary_ns).to eql('ns1.provider.net') end end diff --git a/spec/controllers/records_controller_spec.rb b/spec/controllers/records_controller_spec.rb index b8a6ebc4..c512900e 100644 --- a/spec/controllers/records_controller_spec.rb +++ b/spec/controllers/records_controller_spec.rb @@ -22,14 +22,14 @@ { :type => 'SPF', :pending => true } ].each do |record| it "should create a #{record[:type]} record when valid" do - pending "Still need test for #{record[:type]}" if record.delete(:pending) + skip "Still need test for #{record[:type]}" if record.delete(:pending) expect { xhr :post, :create, :domain_id => @domain.id, :record => record }.to change( @domain.records, :count ).by(1) - assigns(:domain).should_not be_nil - assigns(:record).should_not be_nil + expect(assigns(:domain)).not_to be_nil + expect(assigns(:record)).not_to be_nil end end @@ -37,7 +37,7 @@ @soa = @domain.soa_record serial = @soa.serial xhr :post, :create, :domain_id => @domain.id, :record => {:name =>'test', :ttl=>3600, :type=>'A', :content=>'127.0.0.1'} - @soa.tap(&:reload).serial.should eql(serial + 1) + expect(@soa.tap(&:reload).serial).to eql(serial + 1) end it "shouldn't save when invalid" do @@ -50,7 +50,7 @@ xhr :post, :create, :domain_id => @domain.id, :record => params - response.should render_template( 'records/create' ) + expect(response).to render_template( 'records/create' ) end it "should update when valid" do @@ -65,7 +65,7 @@ xhr :put, :update, :id => record.id, :domain_id => @domain.id, :record => params - response.should render_template("records/update") + expect(response).to render_template("records/update") end it "should increment the serial on update" do @@ -73,7 +73,7 @@ @soa = @domain.soa_record serial = @soa.serial xhr :put, :update, :id => record.id, :domain_id => @domain.id, :record => {:content => '0.0.0.0'} - @soa.tap(&:reload).serial.should eql(serial + 1) + expect(@soa.tap(&:reload).serial).to eql(serial + 1) end it "shouldn't update when invalid" do @@ -91,15 +91,15 @@ record.reload }.to_not change( record, :content ) - response.should_not be_redirect - response.should render_template( "records/update" ) + expect(response).not_to be_redirect + expect(response).to render_template( "records/update" ) end it "should destroy when requested to do so" do delete :destroy, :domain_id => @domain.id, :id => FactoryGirl.create(:mx, :domain => @domain).id - response.should be_redirect - response.should redirect_to( domain_path( @domain ) ) + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( @domain ) ) end it "should increment the serial on delete" do @@ -107,7 +107,7 @@ @soa = @domain.soa_record serial = @soa.serial delete :destroy, :domain_id => @domain.id, :id => record.id - @soa.tap(&:reload).serial.should eql(serial + 1) + expect(@soa.tap(&:reload).serial).to eql(serial + 1) end end @@ -125,7 +125,7 @@ } target_soa.reload - target_soa.contact.should eql('dnsadmin@example.com') + expect(target_soa.contact).to eql('dnsadmin@example.com') end end @@ -168,8 +168,8 @@ xhr :post, :create, :domain_id => @domain.id, :record => params }.to_not change( @domain.records, :size ) - response.should_not be_success - response.code.should == "403" + expect(response).not_to be_success + expect(response.code).to eq("403") end xit "should not allow updating NS records" do @@ -189,8 +189,8 @@ record.reload }.to_not change( record, :content ) - response.should_not be_success - response.code.should == "403" + expect(response).not_to be_success + expect(response.code).to eq("403") end xit "should create when allowed" do @@ -208,14 +208,14 @@ xhr :post, :create, :domain_id => @domain.id, :record => params }.to change( @domain.records, :size ) - response.should be_success + expect(response).to be_success - assigns(:domain).should_not be_nil - assigns(:record).should_not be_nil + expect(assigns(:domain)).not_to be_nil + expect(assigns(:record)).not_to be_nil # Ensure the token han been updated - @token.can_change?( 'test', 'A' ).should be_true - @token.can_remove?( 'test', 'A' ).should be_true + expect(@token.can_change?( 'test', 'A' )).to be_truthy + expect(@token.can_remove?( 'test', 'A' )).to be_truthy end xit "should not create if not allowed" do @@ -232,8 +232,8 @@ xhr :post, :create, :domain_id => @domain.id, :record => params }.to_not change( @domain.records, :size ) - response.should_not be_success - response.code.should == "403" + expect(response).not_to be_success + expect(response.code).to eq("403") end xit "should update when allowed" do @@ -253,8 +253,8 @@ record.reload }.to change( record, :content ) - response.should be_success - response.should render_template("update") + expect(response).to be_success + expect(response).to render_template("update") end xit "should not update if not allowed" do @@ -273,8 +273,8 @@ record.reload }.to_not change( record, :content ) - response.should_not be_success - response.code.should == "403" + expect(response).not_to be_success + expect(response.code).to eq("403") end xit "should destroy when allowed" do @@ -287,8 +287,8 @@ delete :destroy, :domain_id => @domain.id, :id => record.id }.to change( @domain.records, :size ).by(-1) - response.should be_redirect - response.should redirect_to( domain_path( @domain ) ) + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( @domain ) ) end xit "should not destroy records if not allowed" do @@ -299,8 +299,8 @@ delete :destroy, :domain_id => @domain.id, :id => record.id }.to_not change( @domain.records, :count ) - response.should_not be_success - response.code.should == "403" + expect(response).not_to be_success + expect(response.code).to eq("403") end xit "should not allow tampering with other domains" do @@ -315,6 +315,6 @@ xhr :post, :create, :domain_id => FactoryGirl.create(:domain, :name => 'example.net').id, :record => record - response.code.should == "403" + expect(response.code).to eq("403") end end diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index f2c298d5..2a521a06 100755 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -12,17 +12,17 @@ it "should display all users to the admin" do get 'index' - response.should render_template('reports/index') - assigns(:users).should_not be_empty - assigns(:users).size.should be(1) + expect(response).to render_template('reports/index') + expect(assigns(:users)).not_to be_empty + expect(assigns(:users).size).to be(1) end it "should display total system domains and total domains to the admin" do get 'index' - response.should render_template('reports/index') - assigns(:total_domains).should be(Domain.count) - assigns(:system_domains).should be(1) + expect(response).to render_template('reports/index') + expect(assigns(:total_domains)).to be(Domain.count) + expect(assigns(:system_domains)).to be(1) end end @@ -37,16 +37,16 @@ get 'results', :q => "a" - response.should render_template('reports/results') - assigns(:results).should_not be_empty - assigns(:results).size.should be(3) + expect(response).to render_template('reports/results') + expect(assigns(:results)).not_to be_empty + expect(assigns(:results).size).to be(3) end it "should redirect to reports/index if the search query is empty" do get 'results' , :q => "" - response.should be_redirect - response.should redirect_to( reports_path ) + expect(response).to be_redirect + expect(response).to redirect_to( reports_path ) end end @@ -59,9 +59,9 @@ it "should show a user reports" do get "view" , :id => FactoryGirl.create(:aaron).id - response.should render_template("reports/view") - assigns(:user).should_not be_nil - assigns(:user).login.should == 'aaron' + expect(response).to render_template("reports/view") + expect(assigns(:user)).not_to be_nil + expect(assigns(:user).login).to eq('aaron') end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 91f2cd50..9ede5a09 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -13,22 +13,22 @@ it "should return results when searched legally" do get :results, :q => 'exa' - assigns(:results).should_not be_nil - response.should render_template('search/results') + expect(assigns(:results)).not_to be_nil + expect(response).to render_template('search/results') end it "should handle whitespace in the query" do get :results, :q => ' exa ' - assigns(:results).should_not be_nil - response.should render_template('results') + expect(assigns(:results)).not_to be_nil + expect(response).to render_template('results') end it "should redirect to the index page when nothing has been searched for" do get :results, :q => '' - response.should be_redirect - response.should redirect_to( root_path ) + expect(response).to be_redirect + expect(response).to redirect_to( root_path ) end it "should redirect to the domain page if only one result is found" do @@ -36,8 +36,8 @@ get :results, :q => 'slave-example.com' - response.should be_redirect - response.should redirect_to( domain_path( domain ) ) + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( domain ) ) end end @@ -53,20 +53,20 @@ it "should return an empty JSON response for no results" do get :results, :q => 'amazon', :format => 'json' - assigns(:results).should be_empty + expect(assigns(:results)).to be_empty - response.body.should == "[]" + expect(response.body).to eq("[]") end it "should return a JSON set of results" do get :results, :q => 'example', :format => 'json' - assigns(:results).should_not be_empty + expect(assigns(:results)).not_to be_empty json = ActiveSupport::JSON.decode( response.body ) - json.size.should be(2) - json.first["domain"].keys.should include('id', 'name') - json.first["domain"]["name"].should match(/example/) - json.first["domain"]["id"].to_s.should match(/\d+/) + expect(json.size).to be(2) + expect(json.first["domain"].keys).to include('id', 'name') + expect(json.first["domain"]["name"]).to match(/example/) + expect(json.first["domain"]["id"].to_s).to match(/\d+/) end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index a6f8c5d0..e0f8f39c 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -10,29 +10,29 @@ xit 'accepts and redirects' do post :token, :token => '5zuld3g9dv76yosy' - session[:token_id].should_not be_nil - controller.send(:token_user?).should be_true - response.should be_redirect - response.should redirect_to( domain_path( @domain ) ) + expect(session[:token_id]).not_to be_nil + expect(controller.send(:token_user?)).to be_truthy + expect(response).to be_redirect + expect(response).to redirect_to( domain_path( @domain ) ) end xit 'fails login and does not redirect' do post :token, :token => 'bad_token' - session[:token_id].should be_nil - response.should be_success + expect(session[:token_id]).to be_nil + expect(response).to be_success end xit 'logs out' do tokenize_as(@token) get :destroy - session[:token_id].should be_nil - response.should redirect_to( session_path ) + expect(session[:token_id]).to be_nil + expect(response).to redirect_to( session_path ) end xit 'fails expired cookie login' do @token.update_attribute :expires_at, 5.minutes.ago get :new - controller.send(:token_user?).should_not be_true + expect(controller.send(:token_user?)).not_to be_truthy end end diff --git a/spec/controllers/templates_controller_spec.rb b/spec/controllers/templates_controller_spec.rb index 134829da..8d303de1 100644 --- a/spec/controllers/templates_controller_spec.rb +++ b/spec/controllers/templates_controller_spec.rb @@ -10,16 +10,16 @@ get :index - assigns(:zone_templates).should_not be_empty - assigns(:zone_templates).size.should be( ZoneTemplate.count ) + expect(assigns(:zone_templates)).not_to be_empty + expect(assigns(:zone_templates).size).to be( ZoneTemplate.count ) end it "should have a detailed view of a template" do get :show, :id => FactoryGirl.create(:zone_template).id - assigns(:zone_template).should_not be_nil + expect(assigns(:zone_template)).not_to be_nil - response.should render_template('templates/show') + expect(response).to render_template('templates/show') end it "should redirect to the template on create" do @@ -27,7 +27,7 @@ post :create, :zone_template => { :name => 'Foo' } }.to change( ZoneTemplate, :count ).by(1) - response.should redirect_to( zone_template_path( assigns(:zone_template) ) ) + expect(response).to redirect_to( zone_template_path( assigns(:zone_template) ) ) end end @@ -44,14 +44,14 @@ get :index - assigns(:zone_templates).should_not be_empty - assigns(:zone_templates).size.should be(1) + expect(assigns(:zone_templates)).not_to be_empty + expect(assigns(:zone_templates).size).to be(1) end it "should not have a list of users when showing the new form" do get :new - assigns(:users).should be_nil + expect(assigns(:users)).to be_nil end end @@ -65,6 +65,6 @@ get :index, :format => "xml" - response.should have_tag('zone-templates > zone-template') + expect(response).to have_tag('zone-templates > zone-template') end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 2f8c6fa8..0484777a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -6,7 +6,7 @@ it "should require a login" do get 'index' - response.should redirect_to( new_user_session_path ) + expect(response).to redirect_to( new_user_session_path ) end end @@ -19,22 +19,22 @@ it "should show a list of current users" do get 'index' - response.should render_template( 'users/index') - assigns(:users).should_not be_empty + expect(response).to render_template( 'users/index') + expect(assigns(:users)).not_to be_empty end it 'should load a users details' do get 'show', :id => @admin.id - response.should render_template( 'users/show' ) - assigns(:user).should_not be_nil + expect(response).to render_template( 'users/show' ) + expect(assigns(:user)).not_to be_nil end it 'should have a form for creating a new user' do get 'new' - response.should render_template( 'users/new' ) - assigns(:user).should_not be_nil + expect(response).to render_template( 'users/new' ) + expect(assigns(:user)).not_to be_nil end it "should create a new administrator" do @@ -46,10 +46,10 @@ :admin => 'true' } - assigns(:user).should be_an_admin + expect(assigns(:user)).to be_an_admin - response.should be_redirect - response.should redirect_to( user_path( assigns(:user) ) ) + expect(response).to be_redirect + expect(response).to redirect_to( user_path( assigns(:user) ) ) end it 'should create a new administrator with token privs' do @@ -62,11 +62,11 @@ :auth_tokens => '1' } - assigns(:user).admin?.should be_true - assigns(:user).auth_tokens?.should be_true + expect(assigns(:user).admin?).to be_truthy + expect(assigns(:user).auth_tokens?).to be_truthy - response.should be_redirect - response.should redirect_to( user_path( assigns(:user) ) ) + expect(response).to be_redirect + expect(response).to redirect_to( user_path( assigns(:user) ) ) end it "should create a new owner" do @@ -77,10 +77,10 @@ :password_confirmation => 'secret', } - assigns(:user).should_not be_an_admin + expect(assigns(:user)).not_to be_an_admin - response.should be_redirect - response.should redirect_to( user_path( assigns(:user) ) ) + expect(response).to be_redirect + expect(response).to redirect_to( user_path( assigns(:user) ) ) end it 'should create a new owner ignoring token privs' do @@ -92,35 +92,35 @@ :auth_tokens => '1' } - assigns(:user).should_not be_an_admin - assigns(:user).auth_tokens?.should be_false + expect(assigns(:user)).not_to be_an_admin + expect(assigns(:user).auth_tokens?).to be_falsey - response.should be_redirect - response.should redirect_to( user_path( assigns(:user) ) ) + expect(response).to be_redirect + expect(response).to redirect_to( user_path( assigns(:user) ) ) end it 'should update a user without password changes' do user = FactoryGirl.create(:quentin) - lambda { + expect { post :update, :id => user.id, :user => { :email => 'new@example.com', :password => '', :password_confirmation => '' } user.reload - }.should change( user, :email ) + }.to change( user, :email ) - response.should be_redirect - response.should redirect_to( user_path( user ) ) + expect(response).to be_redirect + expect(response).to redirect_to( user_path( user ) ) end it 'should be able to suspend users' do @user = FactoryGirl.create(:quentin) put 'suspend', :id => @user.id - response.should be_redirect - response.should redirect_to( users_path ) + expect(response).to be_redirect + expect(response).to redirect_to( users_path ) end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index bfafc91d..115bacf0 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -4,13 +4,13 @@ describe "link_to_cancel" do it "on new records should link to index" do html = helper.link_to_cancel( Macro.new ) - html.should have_tag('a[href="/macros"]', :content => 'Cancel') + expect(html).to have_tag('a[href="/macros"]', :content => 'Cancel') end it "on existing records should link to show" do macro = FactoryGirl.create(:macro) html = helper.link_to_cancel( macro ) - html.should have_tag("a[href='/macros/#{macro.id}']", :content => 'Cancel') + expect(html).to have_tag("a[href='/macros/#{macro.id}']", :content => 'Cancel') end end diff --git a/spec/helpers/audits_helper_spec.rb b/spec/helpers/audits_helper_spec.rb index d025e1e9..0ffdc857 100644 --- a/spec/helpers/audits_helper_spec.rb +++ b/spec/helpers/audits_helper_spec.rb @@ -3,17 +3,17 @@ describe AuditsHelper, "display_hash" do it "should handle a blank changes hash" do - helper.display_hash( nil ).should eql('') + expect(helper.display_hash( nil )).to eql('') end it "should have a way to display the changes hash with blank stipped" do result = helper.display_hash( 'key' => 'value', :blank => nil ) - result.should eql("key: value") + expect(result).to eql("key: value") end it "should seperate items in the change hash with breaks" do result = helper.display_hash( 'one' => 'one', 'two' => 'two' ) - result.should match(/
/) + expect(result).to match(/
/) end end @@ -27,7 +27,7 @@ results = helper.link_to_domain_audit( audit ) - results.should match(/1 create by admin/) + expect(results).to match(/1 create by admin/) end end @@ -37,7 +37,7 @@ results = helper.link_to_domain_audit( audit ) - results.should match(/1 create by admin/) + expect(results).to match(/1 create by admin/) end end @@ -49,7 +49,7 @@ results = helper.link_to_domain_audit( audit ) - results.should match(/2 destroy by admin/) + expect(results).to match(/2 destroy by admin/) end end @@ -61,7 +61,7 @@ results = helper.link_to_domain_audit( audit ) - results.should match(/2 destroy by admin/) + expect(results).to match(/2 destroy by admin/) end end @@ -76,7 +76,7 @@ audit = record.audits.first result = helper.link_to_record_audit( audit ) - result.should match(/A \(example\.com\) 1 create by admin/) + expect(result).to match(/A \(example\.com\) 1 create by admin/) end end @@ -87,7 +87,7 @@ audit = record.audits.first result = helper.link_to_record_audit( audit ) - result.should match(/A \(example\.com\) 1 create by admin/) + expect(result).to match(/A \(example\.com\) 1 create by admin/) end end @@ -99,7 +99,7 @@ audit = record.audits.last result = helper.link_to_record_audit( audit ) - result.should match(/A \(example\.com\) 2 destroy by admin/) + expect(result).to match(/A \(example\.com\) 2 destroy by admin/) end end @@ -111,7 +111,7 @@ audit = record.audits.last result = helper.link_to_record_audit( audit ) - result.should match(/A \(example\.com\) 2 destroy by admin/) + expect(result).to match(/A \(example\.com\) 2 destroy by admin/) end end @@ -127,7 +127,7 @@ ) result = helper.link_to_record_audit( audit ) - result.should match(/A \(example\.com\) 1 create by admin/) + expect(result).to match(/A \(example\.com\) 1 create by admin/) end it "should handle removed records without a 'type' key in the changes hash" do @@ -141,7 +141,7 @@ ) result = helper.link_to_record_audit( audit ) - result.should match(/\[UNKNOWN\] \(local\.example\.com\) 1 destroy by admin/) + expect(result).to match(/\[UNKNOWN\] \(local\.example\.com\) 1 destroy by admin/) end end @@ -158,7 +158,7 @@ :audited_changes => { 'name' => 'local.example.com' } ) - helper.audit_user( audit ).should == 'admin' + expect(helper.audit_user( audit )).to eq('admin') end it "should display usernames if present" do @@ -171,7 +171,7 @@ :audited_changes => { 'name' => 'local.example.com' } ) - helper.audit_user( audit ).should == 'foo' + expect(helper.audit_user( audit )).to eq('foo') end it "should not bork on missing user information" do @@ -183,6 +183,6 @@ :audited_changes => { 'name' => 'local.example.com' } ) - helper.audit_user( audit ).should == 'UNKNOWN' + expect(helper.audit_user( audit )).to eq('UNKNOWN') end end diff --git a/spec/helpers/macro_steps_helper_spec.rb b/spec/helpers/macro_steps_helper_spec.rb index 24a8e560..847085e3 100644 --- a/spec/helpers/macro_steps_helper_spec.rb +++ b/spec/helpers/macro_steps_helper_spec.rb @@ -5,7 +5,7 @@ #Delete this example and add some real ones or delete this file it "should be included in the object returned by #helper" do included_modules = (class << helper; self; end).send :included_modules - included_modules.should include(MacroStepsHelper) + expect(included_modules).to include(MacroStepsHelper) end end diff --git a/spec/helpers/macros_helper_spec.rb b/spec/helpers/macros_helper_spec.rb index d73d688c..1ffa9f59 100644 --- a/spec/helpers/macros_helper_spec.rb +++ b/spec/helpers/macros_helper_spec.rb @@ -5,7 +5,7 @@ #Delete this example and add some real ones or delete this file it "should be included in the object returned by #helper" do included_modules = (class << helper; self; end).send :included_modules - included_modules.should include(MacrosHelper) + expect(included_modules).to include(MacrosHelper) end end diff --git a/spec/models/a_spec.rb b/spec/models/a_spec.rb index 70ac17aa..fc73d55b 100644 --- a/spec/models/a_spec.rb +++ b/spec/models/a_spec.rb @@ -5,7 +5,7 @@ context "new record" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should only accept valid IPv4 addresses as content" do diff --git a/spec/models/aaaa_spec.rb b/spec/models/aaaa_spec.rb index 67827e30..5ee55c83 100644 --- a/spec/models/aaaa_spec.rb +++ b/spec/models/aaaa_spec.rb @@ -5,7 +5,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should only accept IPv6 address as content" diff --git a/spec/models/auth_token_spec.rb b/spec/models/auth_token_spec.rb index 1abb908f..6fc9d813 100644 --- a/spec/models/auth_token_spec.rb +++ b/spec/models/auth_token_spec.rb @@ -3,7 +3,7 @@ describe AuthToken, "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require a domain" do @@ -17,7 +17,7 @@ end it "should require an auth token" do - subject.token.should_not be_nil + expect(subject.token).not_to be_nil subject.token = nil subject.valid? @@ -25,7 +25,7 @@ end it "should require the permissions hash" do - subject.permissions.should_not be_nil + expect(subject.permissions).not_to be_nil subject.permissions = nil subject.valid? @@ -54,36 +54,36 @@ it "should extract the name and RR class from Record objects" do record = FactoryGirl.create(:a, :domain => @domain) name, type = @auth_token.send(:get_name_and_type_from_param, record ) - name.should eql('example.com') - type.should eql('A') + expect(name).to eql('example.com') + expect(type).to eql('A') end it "should correctly set the name and RR class from string input" do name, type = @auth_token.send(:get_name_and_type_from_param, 'example.com', 'A' ) - name.should eql('example.com') - type.should eql('A') + expect(name).to eql('example.com') + expect(type).to eql('A') end it "should correctly set the name and wildcard RR from string input" do name, type = @auth_token.send(:get_name_and_type_from_param, 'example.com' ) - name.should eql('example.com') - type.should eql('*') + expect(name).to eql('example.com') + expect(type).to eql('*') name, type = @auth_token.send(:get_name_and_type_from_param, 'example.com', nil ) - name.should eql('example.com') - type.should eql('*') + expect(name).to eql('example.com') + expect(type).to eql('*') end it "should append the domain name to string records missing it" do name, type = @auth_token.send(:get_name_and_type_from_param, 'mail', nil ) - name.should eql('mail.example.com') - type.should eql('*') + expect(name).to eql('mail.example.com') + expect(type).to eql('*') end it 'should take the domain name exactly if given a blank name string' do name, type = @auth_token.send(:get_name_and_type_from_param, '') - name.should eql('example.com') - type.should eql('*') + expect(name).to eql('example.com') + expect(type).to eql('*') end end @@ -99,62 +99,62 @@ end it "should have a default policy of 'deny'" do - @auth_token.policy.should eql(:deny) + expect(@auth_token.policy).to eql(:deny) end it "should accept a default policy" do @auth_token.policy = :allow - @auth_token.policy.should eql(:allow) + expect(@auth_token.policy).to eql(:allow) end it "should only accept valid policies" do - lambda { + expect { @auth_token.policy = :allow @auth_token.policy = :deny - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @auth_token.policy = :open_sesame - }.should raise_error + }.to raise_error end it "should deny new RR's by default" do - @auth_token.allow_new_records?.should be false + expect(@auth_token.allow_new_records?).to be false end it "should allow for adding new RR" do @auth_token.allow_new_records = true - @auth_token.allow_new_records?.should be true + expect(@auth_token.allow_new_records?).to be true end it "should deny removing RR's by default" do - @auth_token.remove_records?.should be false + expect(@auth_token.remove_records?).to be false end it "should allow for removing RR's" do @auth_token.remove_records = true - @auth_token.remove_records?.should be true + expect(@auth_token.remove_records?).to be true a = FactoryGirl.create(:a, :domain => @domain) - @auth_token.can_remove?( a ).should be false - @auth_token.can_remove?( 'example.com', 'A' ).should be false + expect(@auth_token.can_remove?( a )).to be false + expect(@auth_token.can_remove?( 'example.com', 'A' )).to be false @auth_token.can_change( a ) - @auth_token.can_remove?( a ).should be true - @auth_token.can_remove?( 'example.com', 'A' ).should be true + expect(@auth_token.can_remove?( a )).to be true + expect(@auth_token.can_remove?( 'example.com', 'A' )).to be true end it "should allow for setting permissions to edit specific RR's (AR)" do a = FactoryGirl.create(:a, :domain => @domain) @auth_token.can_change( a ) - @auth_token.can_change?( 'example.com' ).should be true - @auth_token.can_change?( 'example.com', 'MX' ).should be false + expect(@auth_token.can_change?( 'example.com' )).to be true + expect(@auth_token.can_change?( 'example.com', 'MX' )).to be false mx = FactoryGirl.create(:mx, :domain => @domain) - @auth_token.can_change?( a ).should be true - @auth_token.can_change?( mx ).should be false + expect(@auth_token.can_change?( a )).to be true + expect(@auth_token.can_change?( mx )).to be false end it "should allow for setting permissions to edit specific RR's (name)" do @@ -163,10 +163,10 @@ @auth_token.can_change( 'mail.example.com' ) - @auth_token.can_change?( 'mail.example.com' ).should be true - @auth_token.can_change?( mail ).should be true + expect(@auth_token.can_change?( 'mail.example.com' )).to be true + expect(@auth_token.can_change?( mail )).to be true - @auth_token.can_change?( a ).should be false + expect(@auth_token.can_change?( a )).to be false end it "should allow for protecting certain RR's" do @@ -178,13 +178,13 @@ @auth_token.protect( mail ) @auth_token.protect( mx ) - @auth_token.can_change?( a ).should be true - @auth_token.can_change?( 'example.com', 'A' ).should be true + expect(@auth_token.can_change?( a )).to be true + expect(@auth_token.can_change?( 'example.com', 'A' )).to be true - @auth_token.can_change?( mx ).should be false - @auth_token.can_change?( 'example.com', 'MX' ).should be false + expect(@auth_token.can_change?( mx )).to be false + expect(@auth_token.can_change?( 'example.com', 'MX' )).to be false - @auth_token.can_change?( mail ).should be false + expect(@auth_token.can_change?( mail )).to be false end it "should allow for protecting RR's by type" do @@ -194,8 +194,8 @@ @auth_token.policy = :allow @auth_token.protect_type 'A' - @auth_token.can_change?( mail ).should be false - @auth_token.can_change?( mx ).should be true + expect(@auth_token.can_change?( mail )).to be false + expect(@auth_token.can_change?( mx )).to be true end it "should prevent removing RR's by type" do @@ -204,7 +204,7 @@ @auth_token.policy = :allow @auth_token.protect_type 'MX' - @auth_token.can_remove?( mx ).should be false + expect(@auth_token.can_remove?( mx )).to be false end it "should prevent adding RR's by type" do @@ -212,7 +212,7 @@ @auth_token.allow_new_records = true @auth_token.protect_type 'MX' - @auth_token.can_add?( MX.new( :name => '', :domain => @domain ) ).should be false + expect(@auth_token.can_add?( MX.new( :name => '', :domain => @domain ) )).to be false end it "should always protect NS records" do @@ -222,26 +222,26 @@ @auth_token.policy = :allow @auth_token.remove_records = true @auth_token.can_change( ns1 ) - @auth_token.can_change?( ns1 ).should be false - @auth_token.can_remove?( ns2 ).should be false + expect(@auth_token.can_change?( ns1 )).to be false + expect(@auth_token.can_remove?( ns2 )).to be false end it "should always protect SOA records" do @auth_token.policy = :allow @auth_token.remove_records = true @auth_token.can_change( @domain.soa_record ) - @auth_token.can_change?( @domain.soa_record ).should be false - @auth_token.can_remove?( @domain.soa_record ).should be false + expect(@auth_token.can_change?( @domain.soa_record )).to be false + expect(@auth_token.can_remove?( @domain.soa_record )).to be false end it "should provide a list of new RR types allowed" do - @auth_token.new_types.should be_empty + expect(@auth_token.new_types).to be_empty @auth_token.allow_new_records = true - @auth_token.new_types.include?('MX').should be true + expect(@auth_token.new_types.include?('MX')).to be true @auth_token.protect_type 'MX' - @auth_token.new_types.include?('MX').should be false + expect(@auth_token.new_types.include?('MX')).to be false end end @@ -253,27 +253,27 @@ end it "should authenticate current tokens" do - AuthToken.authenticate( '5zuld3g9dv76yosy' ).should eql( @auth_token ) + expect(AuthToken.authenticate( '5zuld3g9dv76yosy' )).to eql( @auth_token ) end it "should not authenticate expired tokens" do - AuthToken.authenticate( 'invalid' ).should be_nil + expect(AuthToken.authenticate( 'invalid' )).to be_nil end it "should have an easy way to test if it expired" do - @auth_token.should_not be_expired + expect(@auth_token).not_to be_expired @auth_token.expire - @auth_token.expires_at.should <( Time.now ) - @auth_token.should be_expired + expect(@auth_token.expires_at).to be <( Time.now ) + expect(@auth_token).to be_expired end it "should correctly report the 'token' role" do - @auth_token.has_role?('token').should be true - @auth_token.has_role?('admin').should be false + expect(@auth_token.has_role?('token')).to be true + expect(@auth_token.has_role?('admin')).to be false end it "should correctly report permissions (deserialized)" do a = FactoryGirl.create(:a, :domain => @domain) - @auth_token.can_change?( a ).should be true + expect(@auth_token.can_change?( a )).to be true end end diff --git a/spec/models/cname_spec.rb b/spec/models/cname_spec.rb index 93810b5d..b4094a91 100644 --- a/spec/models/cname_spec.rb +++ b/spec/models/cname_spec.rb @@ -5,7 +5,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require content" do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index b9bd11ca..c161a93e 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -4,7 +4,7 @@ context "'untyped'" do it "should be NATIVE by default" do - subject.type.should == 'NATIVE' + expect(subject.type).to eq('NATIVE') end it "should not accept rubbish types" do @@ -33,7 +33,7 @@ end it "should be NATIVE by default" do - subject.type.should eql('NATIVE') + expect(subject.type).to eql('NATIVE') end it "should not require a MASTER" do @@ -70,39 +70,39 @@ subject { FactoryGirl.create(:domain) } it "should have a name" do - subject.name.should eql('example.com') + expect(subject.name).to eql('example.com') end it "should have an SOA record" do - subject.soa_record.should be_a_kind_of( SOA ) + expect(subject.soa_record).to be_a_kind_of( SOA ) end it "should have NS records" do ns1 = FactoryGirl.create(:ns, :domain => subject) ns2 = FactoryGirl.create(:ns, :domain => subject) ns = subject.ns_records - ns.should be_a_kind_of( Array ) - ns.should include( ns1 ) - ns.should include( ns2 ) + expect(ns).to be_a_kind_of( Array ) + expect(ns).to include( ns1 ) + expect(ns).to include( ns2 ) end it "should have MX records" do mx_f = FactoryGirl.create(:mx, :domain => subject) mx = subject.mx_records - mx.should be_a_kind_of( Array ) - mx.should include( mx_f ) + expect(mx).to be_a_kind_of( Array ) + expect(mx).to include( mx_f ) end it "should have A records" do a_f = FactoryGirl.create(:a, :domain => subject) a = subject.a_records - a.should be_a_kind_of( Array ) - a.should include( a_f ) + expect(a).to be_a_kind_of( Array ) + expect(a).to include( a_f ) end it "should give access to all records excluding the SOA" do FactoryGirl.create(:a, :domain => subject) - subject.records_without_soa.size.should be( subject.records.size - 1 ) + expect(subject.records_without_soa.size).to be( subject.records.size - 1 ) end it "should not complain about missing SOA fields" do @@ -122,19 +122,19 @@ quentin_domain aaron_domain - Domain.user( admin ).all.should include(quentin_domain) - Domain.user( admin ).all.should include(aaron_domain) + expect(Domain.user( admin ).all).to include(quentin_domain) + expect(Domain.user( admin ).all).to include(aaron_domain) end it "should restrict owners" do quentin_domain aaron_domain - Domain.user( quentin ).all.should include(quentin_domain) - Domain.user( quentin ).all.should_not include(aaron_domain) + expect(Domain.user( quentin ).all).to include(quentin_domain) + expect(Domain.user( quentin ).all).not_to include(aaron_domain) - Domain.user( aaron ).all.should_not include(quentin_domain) - Domain.user( aaron ).all.should include(aaron_domain) + expect(Domain.user( aaron ).all).not_to include(quentin_domain) + expect(Domain.user( aaron ).all).to include(aaron_domain) end it "should restrict authentication tokens" @@ -150,9 +150,9 @@ subject.expire = 604800 subject.minimum = 10800 - subject.save.should be_true - subject.soa_record.should_not be_nil - subject.soa_record.primary_ns.should eql('ns1.example.org') + expect(subject.save).to be_truthy + expect(subject.soa_record).not_to be_nil + expect(subject.soa_record.primary_ns).to eql('ns1.example.org') end end @@ -163,8 +163,8 @@ subject.name = 'example.org' subject.master = '127.0.0.1' - subject.save.should be_true - subject.soa_record.should be_nil + expect(subject.save).to be_truthy + expect(subject.soa_record).to be_nil end end @@ -185,15 +185,15 @@ end it "should return results for admins" do - Domain.search('exa', 1, FactoryGirl.create(:admin)).should_not be_empty + expect(Domain.search('exa', 1, FactoryGirl.create(:admin))).not_to be_empty end it "should return results for users" do - Domain.search('exa', 1, quentin).should_not be_empty + expect(Domain.search('exa', 1, quentin)).not_to be_empty end it "should return unscoped results" do - Domain.search('exa', 1).should_not be_empty + expect(Domain.search('exa', 1)).not_to be_empty end end end diff --git a/spec/models/macro_spec.rb b/spec/models/macro_spec.rb index c565eb98..c6e3bd7c 100644 --- a/spec/models/macro_spec.rb +++ b/spec/models/macro_spec.rb @@ -17,7 +17,7 @@ end it "should be disabled by default" do - subject.should_not be_active + expect(subject).not_to be_active end end @@ -37,7 +37,7 @@ it "should create new RR's" do @macro.apply_to( @target ) - @target.a_records.map(&:shortname).should include('foo') + expect(@target.a_records.map(&:shortname)).to include('foo') end it "should update existing RR's" do @@ -61,17 +61,17 @@ it "should remove existing RR's (wild card)" do FactoryGirl.create(:mx, :domain => @target) - @target.mx_records(true).should_not be_empty + expect(@target.mx_records(true)).not_to be_empty @macro.apply_to( @target ) - @target.mx_records(true).should be_empty + expect(@target.mx_records(true)).to be_empty end it "should not create RR's that were supposed to be updated but doesn't exist" do @macro.apply_to( @target ) - @target.reload.a_records.detect { |a| a.name =~ /^admin/ }.should be_nil + expect(@target.reload.a_records.detect { |a| a.name =~ /^admin/ }).to be_nil end end diff --git a/spec/models/macro_step_spec.rb b/spec/models/macro_step_spec.rb index befee086..fd475917 100644 --- a/spec/models/macro_step_spec.rb +++ b/spec/models/macro_step_spec.rb @@ -4,7 +4,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require a macro" do @@ -60,7 +60,7 @@ end it "should be active by default" do - subject.should be_active + expect(subject).to be_active end describe "should inherit validations" do @@ -99,7 +99,7 @@ end it "should have a position" do - @macro_step.position.should_not be_blank + expect(@macro_step.position).not_to be_blank end end @@ -130,7 +130,7 @@ } record = subject.build - record.should be_an_instance_of( A ) + expect(record).to be_an_instance_of( A ) end end diff --git a/spec/models/mx_spec.rb b/spec/models/mx_spec.rb index 7431437f..2d529380 100644 --- a/spec/models/mx_spec.rb +++ b/spec/models/mx_spec.rb @@ -4,7 +4,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require a priority" do @@ -31,7 +31,7 @@ end it "should require content" do - subject.should have(2).error_on(:content) + expect(subject).to have(2).error_on(:content) end it "should not accept IP addresses as content" do @@ -47,7 +47,7 @@ end it "should support priorities" do - subject.supports_prio?.should be_true + expect(subject.supports_prio?).to be_truthy end end diff --git a/spec/models/ns_spec.rb b/spec/models/ns_spec.rb index a33093ef..68bac517 100644 --- a/spec/models/ns_spec.rb +++ b/spec/models/ns_spec.rb @@ -3,7 +3,7 @@ describe NS do context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require content" do diff --git a/spec/models/record_spec.rb b/spec/models/record_spec.rb index a30a821e..5fc2021a 100644 --- a/spec/models/record_spec.rb +++ b/spec/models/record_spec.rb @@ -6,7 +6,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require a domain" do @@ -39,7 +39,7 @@ end it "should not support priorities by default" do - subject.supports_prio?.should be false + expect(subject.supports_prio?).to be false end end @@ -54,16 +54,16 @@ record = FactoryGirl.create(:a, :domain => domain) - @soa.tap(&:reload).serial.should_not eql( serial ) + expect(@soa.tap(&:reload).serial).not_to eql( serial ) end it "should update the serial on the SOA on change" do record = FactoryGirl.create(:a, :domain => domain) serial = @soa.tap(&:reload).serial record.content = '10.0.0.1' - record.save.should be true + expect(record.save).to be true - @soa.tap(&:reload).serial.should_not eql( serial ) + expect(@soa.tap(&:reload).serial).not_to eql( serial ) end it "should update the serial on the SOA when deleted" do @@ -74,7 +74,7 @@ record.destroy expect( record.destroyed? ).to be true - @soa.tap(&:reload).serial.should_not eql( serial ) + expect(@soa.tap(&:reload).serial).not_to eql( serial ) end it "should be able to restrict the serial number to one change (multiple updates)" do @@ -89,7 +89,7 @@ :content => '10.0.0.5', :ttl => 86400 ) - record.save.should be true + expect(record.save).to be true record = A.new( :domain => domain, @@ -97,7 +97,7 @@ :content => '10.0.0.6', :ttl => 86400 ) - record.save.should be true + expect(record.save).to be true record = A.new( :domain => domain, @@ -105,13 +105,13 @@ :content => '10.0.0.7', :ttl => 86400 ) - record.save.should be true + expect(record.save).to be true end # Our serial should have move just one position, not three @soa.reload - @soa.serial.should_not be( serial ) - @soa.serial.to_s.should eql( Time.now.strftime( "%Y%m%d" ) + '01' ) + expect(@soa.serial).not_to be( serial ) + expect(@soa.serial.to_s).to eql( Time.now.strftime( "%Y%m%d" ) + '01' ) end end @@ -130,10 +130,10 @@ :content => '10.0.0.5', :ttl => 86400 ) - record.save.should be true + expect(record.save).to be true @soa.reload - @soa.serial.should_not eql(serial) + expect(@soa.serial).not_to eql(serial) end it "should inherit the name from the parent domain if not provided" do @@ -141,9 +141,9 @@ :domain => domain, :content => '10.0.0.6' ) - record.save.should be true + expect(record.save).to be true - record.name.should eql('example.com') + expect(record.name).to eql('example.com') end it "should append the domain name to the name if not present" do @@ -152,24 +152,24 @@ :name => 'test', :content => '10.0.0.6' ) - record.save.should be true + expect(record.save).to be true - record.shortname.should eql('test') - record.name.should eql('test.example.com') + expect(record.shortname).to eql('test') + expect(record.name).to eql('test.example.com') end it "should inherit the TTL from the parent domain if not provided" do ttl = domain.ttl - ttl.should be( 86400 ) + expect(ttl).to be( 86400 ) record = A.new( :domain => domain, :name => 'ftp', :content => '10.0.0.6' ) - record.save.should be true + expect(record.save).to be true - record.ttl.should be( 86400 ) + expect(record.ttl).to be( 86400 ) end it "should prefer own TTL over that of parent domain" do @@ -179,9 +179,9 @@ :content => '10.0.0.6', :ttl => 43200 ) - record.save.should be true + expect(record.save).to be true - record.ttl.should be( 43200 ) + expect(record.ttl).to be( 43200 ) end end @@ -190,11 +190,11 @@ subject { FactoryGirl.create(:a, :domain => domain) } it "should have a full name" do - subject.name.should eql('example.com') + expect(subject.name).to eql('example.com') end it "should have a short name" do - subject.shortname.should be_blank + expect(subject.shortname).to be_blank end end @@ -202,7 +202,7 @@ subject { FactoryGirl.create(:a, :domain => domain) } it "should have a root tag of the record type" do - subject.to_xml.should match(//) + expect(subject.to_xml).to match(//) end end diff --git a/spec/models/record_template_spec.rb b/spec/models/record_template_spec.rb index 9448dcc8..04c6c06e 100644 --- a/spec/models/record_template_spec.rb +++ b/spec/models/record_template_spec.rb @@ -4,7 +4,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end end @@ -16,7 +16,7 @@ it "validations from A" do subject.record_type = 'A' - subject.should_not be_valid + expect(subject).not_to be_valid subject.content = '256.256.256.256' subject.valid? @@ -33,7 +33,7 @@ it "validations from CNAME" do subject.record_type = 'NS' - subject.should_not be_valid + expect(subject).not_to be_valid subject.valid? expect( subject.errors[:content].size ).to eq(2) @@ -41,7 +41,7 @@ it "validations from MX" do subject.record_type = 'MX' - subject.should_not be_valid + expect(subject).not_to be_valid subject.valid? expect( subject.errors[:prio].size ).to eq(1) @@ -62,7 +62,7 @@ it "validations from NS" do subject.record_type = 'NS' - subject.should_not be_valid + expect(subject).not_to be_valid subject.valid? expect( subject.errors[:content].size ).to eq(2) @@ -70,7 +70,7 @@ it "validations from TXT" do subject.record_type = 'TXT' - subject.should_not be_valid + expect(subject).not_to be_valid subject.valid? expect( subject.errors[:content].size ).to eq(1) @@ -78,7 +78,7 @@ it "validations from SOA" do subject.record_type = 'SOA' - subject.should_not be_valid + expect(subject).not_to be_valid subject.valid? expect( subject.errors[:primary_ns].size ).to eq(1) @@ -112,9 +112,9 @@ subject.expire = 604800 subject.minimum = 10800 - subject.content.should eql('ns1.%ZONE% admin@%ZONE% 0 7200 1800 604800 10800') - subject.should be_valid - subject.save.should be_true + expect(subject.content).to eql('ns1.%ZONE% admin@%ZONE% 0 7200 1800 604800 10800') + expect(subject).to be_valid + expect(subject.save).to be_truthy end end @@ -128,28 +128,28 @@ template = FactoryGirl.create(:template_soa, :zone_template => @zone_template) record = template.build( 'example.org' ) - record.should_not be_nil - record.should be_a_kind_of( SOA ) - record.primary_ns.should == 'ns1.example.org' - record.contact.should == 'admin@example.org' + expect(record).not_to be_nil + expect(record).to be_a_kind_of( SOA ) + expect(record.primary_ns).to eq('ns1.example.org') + expect(record.contact).to eq('admin@example.org') end it "an NS should replace the %ZONE% token with the provided domain name" do template = FactoryGirl.create(:template_ns, :zone_template => @zone_template) record = template.build( 'example.org' ) - record.should_not be_nil - record.should be_a_kind_of( NS ) - record.content.should eql('ns1.example.org') + expect(record).not_to be_nil + expect(record).to be_a_kind_of( NS ) + expect(record.content).to eql('ns1.example.org') end it "a MX should replace the %ZONE% token with provided domain name" do template = FactoryGirl.create(:template_mx, :zone_template => @zone_template) record = template.build( 'example.org' ) - record.should_not be_nil - record.should be_a_kind_of( MX ) - record.content.should eql('mail.example.org') + expect(record).not_to be_nil + expect(record).to be_a_kind_of( MX ) + expect(record.content).to eql('mail.example.org') end end @@ -162,9 +162,9 @@ record_template = RecordTemplate.new( :zone_template => @zone_template ) record_template.record_type = 'A' record_template.content = '10.0.0.1' - record_template.save.should be_true + expect(record_template.save).to be_truthy - record_template.ttl.should be(@zone_template.ttl) + expect(record_template.ttl).to be(@zone_template.ttl) end it "should prefer own TTL over that of the ZoneTemplate" do @@ -172,9 +172,9 @@ record_template.record_type = 'A' record_template.content = '10.0.0.1' record_template.ttl = 43200 - record_template.save.should be_true + expect(record_template.save).to be_truthy - record_template.ttl.should be(43200) + expect(record_template.ttl).to be(43200) end end @@ -182,8 +182,8 @@ it "should have SOA convenience, if an SOA template" do zone_template = FactoryGirl.create(:zone_template) record_template = FactoryGirl.create(:template_soa, :zone_template => zone_template) - record_template.primary_ns.should eql('ns1.%ZONE%') - record_template.retry.should be(7200) + expect(record_template.primary_ns).to eql('ns1.%ZONE%') + expect(record_template.retry).to be(7200) end end @@ -196,7 +196,7 @@ record_template.save record_template.reload - record_template.primary_ns.should eql('ns1.provider.net') + expect(record_template.primary_ns).to eql('ns1.provider.net') end end end diff --git a/spec/models/soa_spec.rb b/spec/models/soa_spec.rb index 4da4671d..68350a91 100644 --- a/spec/models/soa_spec.rb +++ b/spec/models/soa_spec.rb @@ -4,7 +4,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should be unique per domain" do @@ -39,14 +39,14 @@ it "should flip the first period in the contact to an @" do subject.contact = 'test.example.com' - subject.contact.should == 'test@example.com' + expect(subject.contact).to eq('test@example.com') subject.contact = 'test@example.com' - subject.contact.should == 'test@example.com' + expect(subject.contact).to eq('test@example.com') end it "should have an autogenerated serial" do - subject.serial.should_not be_nil + expect(subject.serial).not_to be_nil end it "should only accept positive integers as serials" do @@ -83,7 +83,7 @@ end it "should require a retry time" do - subject.should have(1).error_on(:retry) + expect(subject).to have(1).error_on(:retry) end it "should only accept positive integers as retry time" do @@ -163,13 +163,13 @@ end it "should have the convenience fields populated before save" do - @soa.primary_ns.should eql('ns1.example.com') + expect(@soa.primary_ns).to eql('ns1.example.com') end it "should create a content field from the convenience fields" do - @soa.save.should be_true + expect(@soa.save).to be_truthy - @soa.content.should match(/ns1\.example\.com dnsadmin@example.com \d+ 7200 1800 604800 10800/) + expect(@soa.content).to match(/ns1\.example\.com dnsadmin@example.com \d+ 7200 1800 604800 10800/) end end @@ -181,38 +181,38 @@ it "should have an easy way to update (without saving)" do serial = @soa.serial - serial.should_not be_nil + expect(serial).not_to be_nil @soa.update_serial - @soa.serial.should_not be( serial ) - @soa.serial.should >( serial ) + expect(@soa.serial).not_to be( serial ) + expect(@soa.serial).to be >( serial ) @soa.reload - @soa.serial.should eql( serial ) + expect(@soa.serial).to eql( serial ) end it "should have an easy way to update (with saving)" do serial = @soa.serial - serial.should_not be_nil + expect(serial).not_to be_nil @soa.update_serial! - @soa.serial.should_not be( serial ) - @soa.serial.should >( serial ) + expect(@soa.serial).not_to be( serial ) + expect(@soa.serial).to be >( serial ) @soa.reload - @soa.serial.should_not be( serial ) + expect(@soa.serial).not_to be( serial ) end it "should update in sequence for the same day" do date_segment = Time.now.strftime( "%Y%m%d" ) - @soa.serial.to_s.should eql( date_segment + '00' ) + expect(@soa.serial.to_s).to eql( date_segment + '00' ) 10.times { @soa.update_serial! } - @soa.serial.to_s.should eql( date_segment + '10' ) + expect(@soa.serial.to_s).to eql( date_segment + '10' ) end end @@ -222,24 +222,24 @@ end it "should make an soa tag" do - @soa.to_xml.should match(//) + expect(@soa.to_xml).to match(//) end it "should have the custom soa attributes present" do xml = @soa.to_xml - xml.should match(/ true - xml.should_not match(/<\?xml/) + expect(xml).not_to match(/<\?xml/) end end end diff --git a/spec/models/spf_spec.rb b/spec/models/spf_spec.rb index fbe65746..7cfa9cc5 100644 --- a/spec/models/spf_spec.rb +++ b/spec/models/spf_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' describe SPF do - pending "should have tests" + skip "should have tests" end diff --git a/spec/models/srv_spec.rb b/spec/models/srv_spec.rb index 992d6528..39aea72e 100644 --- a/spec/models/srv_spec.rb +++ b/spec/models/srv_spec.rb @@ -2,6 +2,6 @@ describe SRV do it "should support priorities" do - subject.supports_prio?.should be_true + expect(subject.supports_prio?).to be_truthy end end diff --git a/spec/models/sshfp_spec.rb b/spec/models/sshfp_spec.rb index 0dd17d0b..dbce0c7d 100644 --- a/spec/models/sshfp_spec.rb +++ b/spec/models/sshfp_spec.rb @@ -10,7 +10,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "must accept a RSA key with a 40 digit hex SHA-1 fingerprint" do diff --git a/spec/models/txt_spec.rb b/spec/models/txt_spec.rb index fb00d2f6..14bf9ab0 100644 --- a/spec/models/txt_spec.rb +++ b/spec/models/txt_spec.rb @@ -4,7 +4,7 @@ context "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require content" do @@ -14,7 +14,7 @@ it "should not tamper with content" do subject.content = %Q{"google.com"} - subject.content.should eql(%Q{"google.com"}) + expect(subject.content).to eql(%Q{"google.com"}) end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d9363f0a..1f7603c7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,17 +5,17 @@ it 'suspends user' do quentin = FactoryGirl.create(:quentin) quentin.suspend! - quentin.should be_suspended + expect(quentin).to be_suspended end it 'does not authenticate suspended user' it 'deletes user' do quentin = FactoryGirl.create(:quentin) - quentin.deleted_at.should be_nil + expect(quentin.deleted_at).to be_nil quentin.delete! #quentin.deleted_at.should_not be_nil - quentin.should be_deleted + expect(quentin).to be_deleted end it 'does not authenticate deleted users' @@ -29,7 +29,7 @@ it 'reverts to active state' do @user.unsuspend! - @user.should be_active + expect(@user).to be_active end end @@ -45,15 +45,15 @@ end it "should have domains" do - @user.domains.should_not be_empty + expect(@user.domains).not_to be_empty end it "should have templates" do - @user.zone_templates.should_not be_empty + expect(@user.zone_templates).not_to be_empty end it "should not have auth_tokens" do - @user.auth_tokens?.should be_false + expect(@user.auth_tokens?).to be_falsey end end @@ -64,31 +64,31 @@ end it "should not own domains" do - @admin.domains.should be_empty + expect(@admin.domains).to be_empty end it "should not own zone templates" do - @admin.zone_templates.should be_empty + expect(@admin.zone_templates).to be_empty end it "should have auth tokens" do - @admin.auth_tokens?.should be_true + expect(@admin.auth_tokens?).to be_truthy end end describe User, "and roles" do it "should have a admin boolean flag" do - FactoryGirl.create(:admin).admin.should be_true - FactoryGirl.create(:quentin).admin.should be_false + expect(FactoryGirl.create(:admin).admin).to be_truthy + expect(FactoryGirl.create(:quentin).admin).to be_falsey end it "should have a way to easily find active owners" do FactoryGirl.create(:quentin) candidates = User.active_owners candidates.each do |user| - user.should be_active - user.should_not be_admin + expect(user).to be_active + expect(user).not_to be_admin end end end @@ -101,14 +101,14 @@ domain =FactoryGirl.create(:domain) audit = domain.audits.first - audit.user.should eql( admin ) - audit.username.should be_nil + expect(audit.user).to eql( admin ) + expect(audit.username).to be_nil admin.destroy audit.reload - audit.user.should eql( 'admin' ) - audit.username.should eql('admin') + expect(audit.user).to eql( 'admin' ) + expect(audit.username).to eql('admin') end end end diff --git a/spec/models/zone_template_spec.rb b/spec/models/zone_template_spec.rb index a1acb6e5..beaf50a4 100644 --- a/spec/models/zone_template_spec.rb +++ b/spec/models/zone_template_spec.rb @@ -3,7 +3,7 @@ describe ZoneTemplate, "when new" do it "should be invalid by default" do - subject.should_not be_valid + expect(subject).not_to be_valid end it "should require a name" do @@ -45,19 +45,19 @@ end it "should have record templates" do - subject.record_templates.should_not be_empty + expect(subject.record_templates).not_to be_empty end it "should provide an easy way to build a zone" do zone = subject.build('example.org') - zone.should be_a_kind_of( Domain ) - zone.should be_valid + expect(zone).to be_a_kind_of( Domain ) + expect(zone).to be_valid end it "should have a sense of validity" do - subject.has_soa?.should be_true + expect(subject.has_soa?).to be_truthy - FactoryGirl.create( :zone_template, :name => 'West Coast Data Center' ).has_soa?.should_not be_true + expect(FactoryGirl.create( :zone_template, :name => 'West Coast Data Center' ).has_soa?).not_to be_truthy end end @@ -74,23 +74,23 @@ it "should only return a user's templates if not an admin" do subject # Sigh... templates = ZoneTemplate.user(quentin).all - templates.should_not be_empty - templates.size.should be(1) - templates.each { |z| z.user.should eql( quentin ) } + expect(templates).not_to be_empty + expect(templates.size).to be(1) + templates.each { |z| expect(z.user).to eql( quentin ) } end it "should return all templates if the user is an admin" do templates = ZoneTemplate.user(FactoryGirl.create(:admin)).all - templates.should_not be_empty - templates.size.should be( ZoneTemplate.count ) + expect(templates).not_to be_empty + expect(templates.size).to be( ZoneTemplate.count ) end it "should return only valid records" do templates = ZoneTemplate.with_soa.all - templates.should be_empty + expect(templates).to be_empty FactoryGirl.create(:template_soa, :zone_template => subject) - ZoneTemplate.with_soa.all.should_not be_empty + expect(ZoneTemplate.with_soa.all).not_to be_empty end end @@ -107,27 +107,27 @@ end it "should create a valid new zone" do - @domain.should be_valid - @domain.should be_a_kind_of( Domain ) + expect(@domain).to be_valid + expect(@domain).to be_a_kind_of( Domain ) end it "should create the correct number of records (from templates)" do - @domain.records.size.should eql( subject.record_templates.size ) + expect(@domain.records.size).to eql( subject.record_templates.size ) end it "should create a SOA record" do soa = @domain.soa_record - soa.should_not be_nil - soa.should be_a_kind_of( SOA ) - soa.primary_ns.should eql('ns1.example.org') + expect(soa).not_to be_nil + expect(soa).to be_a_kind_of( SOA ) + expect(soa.primary_ns).to eql('ns1.example.org') end it "should create two NS records" do ns = @domain.ns_records - ns.should be_a_kind_of( Array ) - ns.size.should be(2) + expect(ns).to be_a_kind_of( Array ) + expect(ns.size).to be(2) - ns.each { |r| r.should be_a_kind_of( NS ) } + ns.each { |r| expect(r).to be_a_kind_of( NS ) } end end @@ -148,36 +148,36 @@ end it "should create a valid new zone" do - @domain.should be_valid - @domain.should be_a_kind_of( Domain ) + expect(@domain).to be_valid + expect(@domain).to be_a_kind_of( Domain ) end it "should be owned by the user" do - @domain.user.should be( @user ) + expect(@domain.user).to be( @user ) end it "should create the correct number of records (from templates)" do - @domain.records.size.should eql( subject.record_templates.size ) + expect(@domain.records.size).to eql( subject.record_templates.size ) end it "should create a SOA record" do soa = @domain.soa_record - soa.should_not be_nil - soa.should be_a_kind_of( SOA ) - soa.primary_ns.should eql('ns1.example.org') + expect(soa).not_to be_nil + expect(soa).to be_a_kind_of( SOA ) + expect(soa.primary_ns).to eql('ns1.example.org') end it "should create two NS records" do ns = @domain.ns_records - ns.should be_a_kind_of( Array ) - ns.size.should be(2) + expect(ns).to be_a_kind_of( Array ) + expect(ns.size).to be(2) - ns.each { |r| r.should be_a_kind_of( NS ) } + ns.each { |r| expect(r).to be_a_kind_of( NS ) } end it "should create the correct CNAME's from the template" do cnames = @domain.cname_records - cnames.size.should be(2) + expect(cnames.size).to be(2) end end @@ -192,10 +192,10 @@ end it "should be able to return all templates" do - ZoneTemplate.find(:all).size.should be( ZoneTemplate.count ) + expect(ZoneTemplate.find(:all).size).to be( ZoneTemplate.count ) end it "should respect required validations" do - ZoneTemplate.find(:all, :require_soa => true).size.should be( 1 ) + expect(ZoneTemplate.find(:all, :require_soa => true).size).to be( 1 ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 30e0b8ba..c8c0089a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,4 +28,15 @@ config.include Devise::TestHelpers, :type => :controller config.include SignInHelpers, :type => :controller config.include Webrat::HaveTagMatcher + + # rspec-rails 3 will no longer automatically infer an example group's spec type + # from the file location. You can explicitly opt-in to the feature using this + # config option. + # To explicitly tag specs without using automatic inference, set the `:type` + # metadata manually: + # + # describe ThingsController, :type => :controller do + # # Equivalent to being in spec/controllers + # end + config.infer_spec_type_from_file_location! end diff --git a/spec/views/audits/domain.html.haml_spec.rb b/spec/views/audits/domain.html.haml_spec.rb index 5f5748b5..6d108bd7 100644 --- a/spec/views/audits/domain.html.haml_spec.rb +++ b/spec/views/audits/domain.html.haml_spec.rb @@ -13,7 +13,7 @@ render - rendered.should have_tag("em", :content => "No revisions found for the domain") + expect(rendered).to have_tag("em", :content => "No revisions found for the domain") end it "should handle audit entries on the domain" do @@ -30,7 +30,7 @@ assign(:domain, @domain) render - rendered.should have_tag("ul > li > a", :content => "1 create by") + expect(rendered).to have_tag("ul > li > a", :content => "1 create by") end end @@ -49,7 +49,7 @@ render - rendered.should have_tag("em", :content => "No revisions found for any resource records of the domain") + expect(rendered).to have_tag("em", :content => "No revisions found for any resource records of the domain") end it "should handle audit entries" do @@ -57,7 +57,7 @@ render - rendered.should have_tag("ul > li > a", :content => "1 create by admin") + expect(rendered).to have_tag("ul > li > a", :content => "1 create by admin") end end diff --git a/spec/views/domains/_record.html.haml_spec.rb b/spec/views/domains/_record.html.haml_spec.rb index d3fe53dd..d122502b 100644 --- a/spec/views/domains/_record.html.haml_spec.rb +++ b/spec/views/domains/_record.html.haml_spec.rb @@ -12,24 +12,24 @@ end it "should have a marker row (used by AJAX)" do - rendered.should have_tag("tr#marker_ns_#{@record.id}") + expect(rendered).to have_tag("tr#marker_ns_#{@record.id}") end it "should have a row with the record details" do - rendered.should have_tag("tr#show_ns_#{@record.id} > td", :content => "") # shortname - rendered.should have_tag("tr#show_ns_#{@record.id} > td", :content => "") # ttl - rendered.should have_tag("tr#show_ns_#{@record.id} > td", :content => "NS") # shortname - rendered.should have_tag("tr#show_ns_#{@record.id} > td", :content => "") # prio - rendered.should have_tag("tr#show_ns_#{@record.id} > td", :content => "ns1.example.com") + expect(rendered).to have_tag("tr#show_ns_#{@record.id} > td", :content => "") # shortname + expect(rendered).to have_tag("tr#show_ns_#{@record.id} > td", :content => "") # ttl + expect(rendered).to have_tag("tr#show_ns_#{@record.id} > td", :content => "NS") # shortname + expect(rendered).to have_tag("tr#show_ns_#{@record.id} > td", :content => "") # prio + expect(rendered).to have_tag("tr#show_ns_#{@record.id} > td", :content => "ns1.example.com") end it "should have a row for editing record details" do - rendered.should have_tag("tr#edit_ns_#{@record.id} > td[colspan='7'] > form") + expect(rendered).to have_tag("tr#edit_ns_#{@record.id} > td[colspan='7'] > form") end it "should have links to edit/remove the record" do - rendered.should have_tag("a[onclick^=editRecord]") - rendered.should have_tag("a > img[src*=database_delete]") + expect(rendered).to have_tag("a[onclick^=editRecord]") + expect(rendered).to have_tag("a > img[src*=database_delete]") end end @@ -43,25 +43,25 @@ end it "should not have tooltips ready" do - rendered.should_not have_tag("div#record-template-edit-#{@record.id}") - rendered.should_not have_tag("div#record-template-delete-#{@record.id}") + expect(rendered).not_to have_tag("div#record-template-edit-#{@record.id}") + expect(rendered).not_to have_tag("div#record-template-delete-#{@record.id}") end it "should have a row with the record details" do - rendered.should have_tag("tr#show_a_#{@record.id} > td", :content => "") # shortname - rendered.should have_tag("tr#show_a_#{@record.id} > td", :content => "") # ttl - rendered.should have_tag("tr#show_a_#{@record.id} > td", :content => "A") - rendered.should have_tag("tr#show_a_#{@record.id} > td", :content => "") # prio - rendered.should have_tag("tr#show_a_#{@record.id} > td", :content => "foo") + expect(rendered).to have_tag("tr#show_a_#{@record.id} > td", :content => "") # shortname + expect(rendered).to have_tag("tr#show_a_#{@record.id} > td", :content => "") # ttl + expect(rendered).to have_tag("tr#show_a_#{@record.id} > td", :content => "A") + expect(rendered).to have_tag("tr#show_a_#{@record.id} > td", :content => "") # prio + expect(rendered).to have_tag("tr#show_a_#{@record.id} > td", :content => "foo") end it "should not have a row for editing record details" do - rendered.should_not have_tag("tr#edit_ns_#{@record.id} > td[colspan='7'] > form") + expect(rendered).not_to have_tag("tr#edit_ns_#{@record.id} > td[colspan='7'] > form") end it "should not have links to edit/remove the record" do - rendered.should_not have_tag("a[onclick^=editRecord]") - rendered.should_not have_tag("a > img[src*=database_delete]") + expect(rendered).not_to have_tag("a[onclick^=editRecord]") + expect(rendered).not_to have_tag("a > img[src*=database_delete]") end end @@ -78,8 +78,8 @@ render :partial => 'domains/record', :object => record - rendered.should_not have_tag("a[onclick^=editRecord]") - rendered.should_not have_tag("tr#edit_ns_#{record.id}") + expect(rendered).not_to have_tag("a[onclick^=editRecord]") + expect(rendered).not_to have_tag("tr#edit_ns_#{record.id}") end it "should not allow removing NS records" do @@ -87,16 +87,16 @@ render :partial => 'domains/record', :object => record - rendered.should_not have_tag("a > img[src*=database_delete]") + expect(rendered).not_to have_tag("a > img[src*=database_delete]") end it "should allow edit records that aren't protected" do record = FactoryGirl.create(:a, :domain => @domain) render :partial => 'domains/record', :object => record - rendered.should have_tag("a[onclick^=editRecord]") - rendered.should_not have_tag("a > img[src*=database_delete]") - rendered.should have_tag("tr#edit_a_#{record.id}") + expect(rendered).to have_tag("a[onclick^=editRecord]") + expect(rendered).not_to have_tag("a > img[src*=database_delete]") + expect(rendered).to have_tag("tr#edit_a_#{record.id}") end it "should allow removing records if permitted" do @@ -110,7 +110,7 @@ render :partial => 'domains/record', :object => record - rendered.should have_tag("a > img[src*=database_delete]") + expect(rendered).to have_tag("a > img[src*=database_delete]") end end end diff --git a/spec/views/domains/apply_macro.html.haml_spec.rb b/spec/views/domains/apply_macro.html.haml_spec.rb index da71c979..f8007691 100644 --- a/spec/views/domains/apply_macro.html.haml_spec.rb +++ b/spec/views/domains/apply_macro.html.haml_spec.rb @@ -12,7 +12,7 @@ end it "should have a selection of macros" do - rendered.should have_tag('select[name=macro_id]') + expect(rendered).to have_tag('select[name=macro_id]') end end diff --git a/spec/views/domains/new.html.haml_spec.rb b/spec/views/domains/new.html.haml_spec.rb index ce5c6762..76f754ad 100644 --- a/spec/views/domains/new.html.haml_spec.rb +++ b/spec/views/domains/new.html.haml_spec.rb @@ -13,8 +13,8 @@ render - rendered.should have_selector("a[href='#{new_zone_template_path}']") - rendered.should_not have_selector("select[name*=zone_template_id]") + expect(rendered).to have_selector("a[href='#{new_zone_template_path}']") + expect(rendered).not_to have_selector("select[name*=zone_template_id]") end it "should have a list of zone templates to select from" do @@ -23,8 +23,8 @@ render - rendered.should have_selector("select[name*=zone_template_id]") - rendered.should_not have_selector("a[href='#{new_zone_template_path}']") + expect(rendered).to have_selector("select[name*=zone_template_id]") + expect(rendered).not_to have_selector("a[href='#{new_zone_template_path}']") end end diff --git a/spec/views/domains/show.html.haml_spec.rb b/spec/views/domains/show.html.haml_spec.rb index 31d2b133..93005e50 100644 --- a/spec/views/domains/show.html.haml_spec.rb +++ b/spec/views/domains/show.html.haml_spec.rb @@ -14,8 +14,8 @@ end it "should have the domain name in the title and dominant on the page" do - rendered.should have_tag( "title", :content => "example.com" ) - rendered.should have_tag( "h1", :content => "example.com" ) + expect(rendered).to have_tag( "title", :content => "example.com" ) + expect(rendered).to have_tag( "h1", :content => "example.com" ) end end @@ -32,20 +32,20 @@ end it "should display the owner" do - rendered.should have_tag( "div#owner-info" ) + expect(rendered).to have_tag( "div#owner-info" ) end it "should allow changing the SOA" do - rendered.should have_tag( "div#soa-form") + expect(rendered).to have_tag( "div#soa-form") end it "should have a form for adding new records" do - rendered.should have_tag( "div#record-form-div" ) + expect(rendered).to have_tag( "div#record-form-div" ) end it "should have not have an additional warnings for removing" do - rendered.should_not have_tag('div#warning-message') - rendered.should_not have_tag('a[onclick*=deleteDomain]') + expect(rendered).not_to have_tag('div#warning-message') + expect(rendered).not_to have_tag('a[onclick*=deleteDomain]') end end @@ -62,12 +62,12 @@ end it "should offer to remove the domain" do - rendered.should have_tag( "a img[id$=delete-zone]" ) + expect(rendered).to have_tag( "a img[id$=delete-zone]" ) end it "should have have an additional warnings for removing" do - rendered.should have_tag('div#warning-message') - rendered.should have_tag('a[onclick*=deleteDomain]') + expect(rendered).to have_tag('div#warning-message') + expect(rendered).to have_tag('a[onclick*=deleteDomain]') end end @@ -84,24 +84,24 @@ end it "should display the owner" do - rendered.should_not have_tag( "div#ownerinfo" ) + expect(rendered).not_to have_tag( "div#ownerinfo" ) end it "should allow for changing the SOA" do - rendered.should have_tag( "div#soa-form" ) + expect(rendered).to have_tag( "div#soa-form" ) end it "should have a form for adding new records" do - rendered.should have_tag( "div#record-form-div" ) + expect(rendered).to have_tag( "div#record-form-div" ) end it "should offer to remove the domain" do - rendered.should have_tag( "a img[id$=delete-zone]" ) + expect(rendered).to have_tag( "a img[id$=delete-zone]" ) end it "should have not have an additional warnings for removing" do - rendered.should_not have_tag('div#warning-message') - rendered.should_not have_tag('a[onclick*=deleteDomain]') + expect(rendered).not_to have_tag('div#warning-message') + expect(rendered).not_to have_tag('a[onclick*=deleteDomain]') end end @@ -119,20 +119,20 @@ end it "should show the master address" do - rendered.should have_tag('#domain-name td', :content => "Master server") - rendered.should have_tag('#domain-name td', :content => @domain.master) + expect(rendered).to have_tag('#domain-name td', :content => "Master server") + expect(rendered).to have_tag('#domain-name td', :content => @domain.master) end it "should not allow for changing the SOA" do - rendered.should_not have_tag( "div#soa-form" ) + expect(rendered).not_to have_tag( "div#soa-form" ) end it "should not have a form for adding new records" do - rendered.should_not have_tag( "div#record-form-div" ) + expect(rendered).not_to have_tag( "div#record-form-div" ) end it "should offer to remove the domain" do - rendered.should have_tag( "a img[id$=delete-zone]" ) + expect(rendered).to have_tag( "a img[id$=delete-zone]" ) end end @@ -149,20 +149,20 @@ it "should not offer to remove the domain" do render - rendered.should_not have_tag( "a img[id$=delete-zone]" ) + expect(rendered).not_to have_tag( "a img[id$=delete-zone]" ) end it "should not offer to edit the SOA" do render - rendered.should_not have_tag( "a[onclick^=showSOAEdit]") - rendered.should_not have_tag( "div#soa-form" ) + expect(rendered).not_to have_tag( "a[onclick^=showSOAEdit]") + expect(rendered).not_to have_tag( "div#soa-form" ) end it "should only allow new record if permitted (FALSE)" do render - rendered.should_not have_tag( "div#record-form-div" ) + expect(rendered).not_to have_tag( "div#record-form-div" ) end it "should only allow new records if permitted (TRUE)" do @@ -173,7 +173,7 @@ view.stubs(:current_token).returns( token ) render - rendered.should have_tag( "div#record-form-div" ) + expect(rendered).to have_tag( "div#record-form-div" ) end end end diff --git a/spec/views/macro_steps/create.js.rjs_spec.rb b/spec/views/macro_steps/create.js.rjs_spec.rb index aa7e8f2e..254c22e5 100644 --- a/spec/views/macro_steps/create.js.rjs_spec.rb +++ b/spec/views/macro_steps/create.js.rjs_spec.rb @@ -11,11 +11,11 @@ end xit "should insert errors into the page" do - response.should have_rjs(:replace_html, 'record-form-error') + expect(response).to have_rjs(:replace_html, 'record-form-error') end xit "should have a error flash" do - response.should include_text(%{showflash("error"}) + expect(response).to include_text(%{showflash("error"}) end end @@ -28,11 +28,11 @@ end xit "should display a notice flash" do - response.should include_text(%{showflash("info"} ) + expect(response).to include_text(%{showflash("info"} ) end xit "should insert the steps into the table" do - response.should have_rjs(:insert, :bottom, 'steps-table') + expect(response).to have_rjs(:insert, :bottom, 'steps-table') end end diff --git a/spec/views/macro_steps/update.js.rjs_spec.rb b/spec/views/macro_steps/update.js.rjs_spec.rb index 5e83fb6c..b5025b33 100644 --- a/spec/views/macro_steps/update.js.rjs_spec.rb +++ b/spec/views/macro_steps/update.js.rjs_spec.rb @@ -13,13 +13,13 @@ end xit "should display a notice" do - response.should include_text(%{showflash("info"}) + expect(response).to include_text(%{showflash("info"}) end xit "should update the steps table" do - response.should have_rjs(:remove, "show_macro_step_#{@macro_step.id}") - response.should have_rjs(:remove, "edit_macro_step_#{@macro_step.id}") - response.should have_rjs(:replace, "marker_macro_step_#{@macro_step.id}") + expect(response).to have_rjs(:remove, "show_macro_step_#{@macro_step.id}") + expect(response).to have_rjs(:remove, "edit_macro_step_#{@macro_step.id}") + expect(response).to have_rjs(:replace, "marker_macro_step_#{@macro_step.id}") end end @@ -35,7 +35,7 @@ xit "should display an error" do - response.should have_rjs(:replace_html, "error_macro_step_#{@macro_step.id}") + expect(response).to have_rjs(:replace_html, "error_macro_step_#{@macro_step.id}") end end diff --git a/spec/views/macros/edit.html.haml_spec.rb b/spec/views/macros/edit.html.haml_spec.rb index bdf1679a..94f1bc37 100644 --- a/spec/views/macros/edit.html.haml_spec.rb +++ b/spec/views/macros/edit.html.haml_spec.rb @@ -3,7 +3,7 @@ describe "macros/edit.html.haml" do before(:each) do admin = FactoryGirl.build_stubbed( :admin ) - view.stub( :current_user ).and_return( admin ) + allow(view).to receive( :current_user ).and_return( admin ) end context "for new macros" do @@ -13,7 +13,7 @@ end it "should behave accordingly" do - rendered.should have_tag('h1', :content => 'New Macro') + expect(rendered).to have_tag('h1', :content => 'New Macro') end end @@ -26,7 +26,7 @@ end it "should behave accordingly" do - rendered.should have_tag('h1', :content => 'Update Macro') + expect(rendered).to have_tag('h1', :content => 'Update Macro') end end @@ -39,7 +39,7 @@ end it "should display the errors" do - rendered.should have_tag('div.errorExplanation') + expect(rendered).to have_tag('div.errorExplanation') end end diff --git a/spec/views/macros/index.html.haml_spec.rb b/spec/views/macros/index.html.haml_spec.rb index c5b2eb09..78b0a004 100644 --- a/spec/views/macros/index.html.haml_spec.rb +++ b/spec/views/macros/index.html.haml_spec.rb @@ -8,8 +8,8 @@ render - rendered.should have_tag('h1', :content => 'Macros') - render.should have_tag("table a[href^='/macro']") + expect(rendered).to have_tag('h1', :content => 'Macros') + expect(render).to have_tag("table a[href^='/macro']") end it "should indicate no macros are present" do @@ -17,7 +17,7 @@ render - rendered.should have_tag('em', :content => "don't have any macros") + expect(rendered).to have_tag('em', :content => "don't have any macros") end end diff --git a/spec/views/macros/show.html.haml_spec.rb b/spec/views/macros/show.html.haml_spec.rb index 5b1f7b75..9bd0146a 100644 --- a/spec/views/macros/show.html.haml_spec.rb +++ b/spec/views/macros/show.html.haml_spec.rb @@ -11,18 +11,18 @@ end it "should have the name of the macro" do - rendered.should have_tag('h1', :content => @macro.name) + expect(rendered).to have_tag('h1', :content => @macro.name) end it "should have an overview table" do - rendered.should have_tag('table.grid td', :content => "Name") - rendered.should have_tag('table.grid td', :content => "Description") - rendered.should have_tag('table.grid td', :content => "Active") + expect(rendered).to have_tag('table.grid td', :content => "Name") + expect(rendered).to have_tag('table.grid td', :content => "Description") + expect(rendered).to have_tag('table.grid td', :content => "Active") end it "should have a list of steps" do - rendered.should have_tag('h1', :content => 'Macro Steps') - rendered.should have_tag('table#steps-table td', :content => "1") + expect(rendered).to have_tag('h1', :content => 'Macro Steps') + expect(rendered).to have_tag('table#steps-table td', :content => "1") end end diff --git a/spec/views/search/results.html.haml_spec.rb b/spec/views/search/results.html.haml_spec.rb index 768e8113..c0d04b2f 100644 --- a/spec/views/search/results.html.haml_spec.rb +++ b/spec/views/search/results.html.haml_spec.rb @@ -13,7 +13,7 @@ render - rendered.should have_tag("strong", :content => "No domains found") + expect(rendered).to have_tag("strong", :content => "No domains found") end it "should handle results within the pagination limit" do @@ -21,14 +21,14 @@ zone = Domain.new zone.id = i zone.name = "zone-#{i}.com" - zone.save( :validate => false ).should be_true + expect(zone.save( :validate => false )).to be_truthy end assign(:results, Domain.search( 'zone', 1, @admin )) render - rendered.should have_tag("table a", :content => "zone-1.com") + expect(rendered).to have_tag("table a", :content => "zone-1.com") end it "should handle results with pagination and scoping" do @@ -36,14 +36,14 @@ zone = Domain.new zone.id = i zone.name = "domain-#{i}.com" - zone.save( :validate => false ).should be_true + expect(zone.save( :validate => false )).to be_truthy end assign(:results, Domain.search( 'domain', 1, @admin )) render - rendered.should have_tag("table a", :content => "domain-1.com") + expect(rendered).to have_tag("table a", :content => "domain-1.com") end end diff --git a/spec/views/templates/edit.html.haml_spec.rb b/spec/views/templates/edit.html.haml_spec.rb index 959786b9..57347e51 100644 --- a/spec/views/templates/edit.html.haml_spec.rb +++ b/spec/views/templates/edit.html.haml_spec.rb @@ -12,7 +12,7 @@ it "should show the correct title" do render - rendered.should have_tag('h1.underline', :content => 'Update Zone Template') + expect(rendered).to have_tag('h1.underline', :content => 'Update Zone Template') end end diff --git a/spec/views/templates/new.html.haml_spec.rb b/spec/views/templates/new.html.haml_spec.rb index 882245ef..a63c3028 100644 --- a/spec/views/templates/new.html.haml_spec.rb +++ b/spec/views/templates/new.html.haml_spec.rb @@ -12,25 +12,25 @@ render - rendered.should have_tag('select#zone_template_user_id') + expect(rendered).to have_tag('select#zone_template_user_id') end it "should render without a list of users" do render - rendered.should_not have_tag('select#zone_template_user_id') + expect(rendered).not_to have_tag('select#zone_template_user_id') end it "should render with a missing list of users (nil)" do render - rendered.should_not have_tag('select#zone_template_user_id') + expect(rendered).not_to have_tag('select#zone_template_user_id') end it "should show the correct title" do render - rendered.should have_tag('h1.underline', :content => 'New Zone Template') + expect(rendered).to have_tag('h1.underline', :content => 'New Zone Template') end end diff --git a/spec/views/templates/show.html.haml_spec.rb b/spec/views/templates/show.html.haml_spec.rb index dc08b48c..9f307998 100644 --- a/spec/views/templates/show.html.haml_spec.rb +++ b/spec/views/templates/show.html.haml_spec.rb @@ -13,23 +13,23 @@ end it "should have the template name" do - rendered.should have_tag('h1', :content => @zone_template.name) + expect(rendered).to have_tag('h1', :content => @zone_template.name) end it "should have a table with template overview" do - rendered.should have_selector('table.grid td', :content => 'Name') - rendered.should have_selector('table.grid td', :content => 'TTL') + expect(rendered).to have_selector('table.grid td', :content => 'Name') + expect(rendered).to have_selector('table.grid td', :content => 'TTL') end it "should have the record templates" do - rendered.should have_selector('h1', :content => 'Record templates') - rendered.should have_selector('table#record-table') + expect(rendered).to have_selector('h1', :content => 'Record templates') + expect(rendered).to have_selector('table#record-table') end it "should not have an SOA warning" do violated "ZoneTemplate does not have SOA" unless @zone_template.has_soa? - rendered.should_not have_selector('div#soa-warning') + expect(rendered).not_to have_selector('div#soa-warning') end end @@ -44,7 +44,7 @@ end it "should have an SOA warning" do - rendered.should have_tag('div#soa-warning') + expect(rendered).to have_tag('div#soa-warning') end end From 576e53dd75c55e90919b28170c742a196d1a6f4b Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 18:52:11 +0200 Subject: [PATCH 23/31] chore: bump to rspec 3.1 --- Gemfile | 2 +- Gemfile.lock | 59 +++++++++++++++++++++------------------------------- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index cb91bae6..ee3243d4 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ end group :development, :test do gem "test-unit" - gem "rspec-rails", "~> 2.99.0" + gem "rspec-rails", "~> 3.1.0" gem 'RedCloth', '>= 4.1.1' end diff --git a/Gemfile.lock b/Gemfile.lock index edc548ec..d942f2fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,17 +39,14 @@ GEM bcrypt-ruby (3.1.5) bcrypt (>= 3.1.3) builder (3.0.4) - capybara (2.0.1) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - selenium-webdriver (~> 2.0) - xpath (~> 1.0.0) + xpath (~> 2.0) celluloid (0.16.0) timers (~> 4.0.0) - childprocess (0.3.6) - ffi (~> 1.0, >= 1.0.6) coderay (1.1.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -127,8 +124,6 @@ GEM thor (~> 0.14) json (1.8.2) libv8 (3.16.14.7) - libwebsocket (0.1.6.1) - websocket listen (2.8.5) celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) @@ -140,14 +135,14 @@ GEM metaclass (0.0.1) method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.6.0) + mini_portile (0.6.2) mocha (0.13.0) metaclass (~> 0.0.1) multi_json (1.10.1) mysql2 (0.3.17) nenv (0.1.1) - nokogiri (1.6.3.1) - mini_portile (= 0.6.0) + nokogiri (1.6.5) + mini_portile (~> 0.6.0) notiffany (0.0.3) nenv (~> 0.1) shellany (~> 0.0) @@ -193,36 +188,31 @@ GEM ref (1.0.5) responders (1.1.2) railties (>= 3.2, < 4.2) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-collection_matchers (1.1.2) - rspec-expectations (>= 2.99.0.beta1) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.3) - rspec-rails (2.99.0) + rspec (3.1.0) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-core (3.1.7) + rspec-support (~> 3.1.0) + rspec-expectations (3.1.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.1.0) + rspec-mocks (3.1.3) + rspec-support (~> 3.1.0) + rspec-rails (3.1.0) actionpack (>= 3.0) - activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-collection_matchers - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rubyzip (0.9.9) + rspec-core (~> 3.1.0) + rspec-expectations (~> 3.1.0) + rspec-mocks (~> 3.1.0) + rspec-support (~> 3.1.0) + rspec-support (3.1.2) sass (3.2.3) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.26.0) - childprocess (>= 0.2.5) - libwebsocket (~> 0.1.3) - multi_json (~> 1.0) - rubyzip shellany (0.0.1) slop (3.6.0) sprockets (2.2.3) @@ -259,9 +249,8 @@ GEM nokogiri (>= 1.2.0) rack (>= 1.0) rack-test (>= 0.5.3) - websocket (1.0.4) will_paginate (3.0.7) - xpath (1.0.0) + xpath (2.0.0) nokogiri (~> 1.3) PLATFORMS @@ -287,7 +276,7 @@ DEPENDENCIES pg (~> 0.18.1) rabl rails (~> 3.2.21) - rspec-rails (~> 2.99.0) + rspec-rails (~> 3.1.0) sass-rails sqlite3 (~> 1.3.10) state_machine From 14937364391c5cf0e264ca4bca3ee5a84cdb5548 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 20:12:46 +0200 Subject: [PATCH 24/31] chore: upgrade cucumber --- Gemfile.lock | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d942f2fd..f999b864 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,15 +55,18 @@ GEM coffee-script-source execjs coffee-script-source (1.4.0) - cucumber (1.2.1) + cucumber (1.3.18) builder (>= 2.1.2) diff-lcs (>= 1.1.3) - gherkin (~> 2.11.0) - json (>= 1.4.6) - cucumber-rails (1.3.0) - capybara (>= 1.1.2) - cucumber (>= 1.1.8) - nokogiri (>= 1.5.0) + gherkin (~> 2.12) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.1) + cucumber-rails (1.4.2) + capybara (>= 1.1.2, < 3) + cucumber (>= 1.3.8, < 2) + mime-types (>= 1.16, < 3) + nokogiri (~> 1.5) + rails (>= 3, < 5) database_cleaner (0.9.1) devise (2.2.8) bcrypt-ruby (~> 3.0) @@ -84,8 +87,8 @@ GEM railties (>= 3.0.0) ffi (1.9.6) formatador (0.2.5) - gherkin (2.11.5) - json (>= 1.4.6) + gherkin (2.12.2) + multi_json (~> 1.3) guard (2.11.1) formatador (>= 0.2.4) listen (~> 2.7) @@ -139,6 +142,7 @@ GEM mocha (0.13.0) metaclass (~> 0.0.1) multi_json (1.10.1) + multi_test (0.1.1) mysql2 (0.3.17) nenv (0.1.1) nokogiri (1.6.5) From a93584b64a2099e2eaf20cbd8e6d04626b6b3302 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 20:21:11 +0200 Subject: [PATCH 25/31] feat: guard-cucumber in place --- Gemfile | 2 +- Gemfile.lock | 6 +++++ Guardfile | 9 +++++++ .../macro_definition_steps.rb | 24 ++++++++++++------- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index ee3243d4..5a1b99ff 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ gem 'dynamic_form' group :development do gem 'guard-rspec', :require => false - #gem 'RedCloth', '>= 4.1.1' + gem 'guard-cucumber', :require => false end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index f999b864..27fd4441 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,11 @@ GEM shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.0) + guard-cucumber (1.5.3) + cucumber (>= 1.3.0) + guard (>= 2.0.0) + guard-compat (~> 1.0) + nenv (~> 0.1) guard-rspec (4.5.0) guard (~> 2.1) guard-compat (~> 1.1) @@ -271,6 +276,7 @@ DEPENDENCIES devise-encryptable dynamic_form factory_girl_rails (~> 4.0) + guard-cucumber guard-rspec haml-rails inherited_resources diff --git a/Guardfile b/Guardfile index 6a1a2f0d..e9518c59 100644 --- a/Guardfile +++ b/Guardfile @@ -31,3 +31,12 @@ guard :rspec, cmd: 'bundle exec rspec' do watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } end + +guard "cucumber" do + watch(%r{^features/.+\.feature$}) + watch(%r{^features/support/.+$}) { "features" } + + watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m| + Dir[File.join("**/#{m[1]}.feature")][0] || "features" + end +end diff --git a/features/step_definitions/macro_definition_steps.rb b/features/step_definitions/macro_definition_steps.rb index 7d9bfcc3..cf51b72a 100644 --- a/features/step_definitions/macro_definition_steps.rb +++ b/features/step_definitions/macro_definition_steps.rb @@ -17,14 +17,14 @@ Given /^the macro "([^\"]*)" an? "([^\"]*)" record for "([^\"]*)" with "([^\"]*)"$/ do |action, type, name, content| # clean up the action by singularizing the components - action.gsub!(/s$/,'').gsub!('s_', '_') + action = action.gsub(/s$/,'').gsub('s_', '_') MacroStep.create!(:macro => @macro, :action => action, :record_type => type, :name => name, :content => content) end Given /^the macro "([^\"]*)" an "([^\"]*)" record for "([^\"]*)"$/ do |action, type, name| # clean up the action by singularizing the components - action.gsub!(/s$/,'').gsub!(/s_/, '') + action = action.gsub(/s$/,'').gsub('s_', '_') MacroStep.create!(:macro => @macro, :action => action, :record_type => type, :name => name) end @@ -43,27 +43,35 @@ Then /^the domain should have an? "([^\"]*)" record for "([^\"]*)" with "([^\"]*)"$/ do |type, name, content| records = @domain.send("#{type.downcase}_records", true) - records.should_not be_empty + expect( records ).to_not be_empty - records.detect { |r| r.name =~ /^#{name}\./ && r.content == content }.should_not be_nil + expect( + records.detect { |r| r.name =~ /^#{name}\./ && r.content == content } + ).to be_present end Then /^the domain should have an? "([^\"]*)" record with priority "([^\"]*)"$/ do |type, prio| records = @domain.send("#{type.downcase}_records", true) - records.should_not be_empty + expect( records ).to_not be_empty - records.detect { |r| r.prio == prio.to_i }.should_not be_nil + expect( + records.detect { |r| r.prio == prio.to_i } + ).to be_present end Then /^the domain should not have an? "([^\"]*)" record for "([^\"]*)" with "([^\"]*)"$/ do |type, name, content| records = @domain.send("#{type.downcase}_records", true) - records.detect { |r| r.name =~ /^#{name}\./ && r.content == content }.should be_nil + expect( + records.detect { |r| r.name =~ /^#{name}\./ && r.content == content } + ).to be_nil end Then /^the domain should not have an "([^\"]*)" record for "([^\"]*)"$/ do |type, name| records = @domain.send("#{type.downcase}_records", true) - records.detect { |r| r.name =~ /^#{name}\./ }.should be_nil + expect( + records.detect { |r| r.name =~ /^#{name}\./ } + ).to be_nil end From d8a2c1f37ac4edc0c48942a06522769bbad870e6 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 20:24:33 +0200 Subject: [PATCH 26/31] chore: formatting of feature --- features/macro_definitions.feature | 157 ++++++++++++++--------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/features/macro_definitions.feature b/features/macro_definitions.feature index ff7f0d00..52e8d1ec 100644 --- a/features/macro_definitions.feature +++ b/features/macro_definitions.feature @@ -1,92 +1,91 @@ Feature: Test the database operations of macros -Test the impact different types have on existing and non-existing records -Test the interpolation of %ZONE% in content + Test the impact different types have on existing and non-existing records + Test the interpolation of %ZONE% in content + Scenario: Macro to create records + Given I have a domain + Given I have a macro + And the macro "creates" an "A" record for "www" with "127.0.0.1" + When I apply the macro + Then the domain should have an "A" record for "www" with "127.0.0.1" -Scenario: Macro to create records -Given I have a domain -Given I have a macro -And the macro "creates" an "A" record for "www" with "127.0.0.1" -When I apply the macro -Then the domain should have an "A" record for "www" with "127.0.0.1" + Scenario: Macro to create interpolated records + Given I have a domain named "example.com" + Given I have a macro + And the macro "creates" a "CNAME" record for "ghs" with "%ZONE%.googleapps.com" + When I apply the macro + Then the domain should have a "CNAME" record for "ghs" with "example.com.googleapps.com" + Scenario: Macro to update existing records + Given I have a domain + And the domain has an "A" record for "www" with "127.0.0.1" + Given I have a macro + And the macro "updates" an "A" record for "www" with "127.0.0.2" + When I apply the macro + Then the domain should have an "A" record for "www" with "127.0.0.2" + And the domain should not have an "A" record for "www" with "127.0.0.1" -Scenario: Macro to create interpolated records -Given I have a domain named "example.com" -Given I have a macro -And the macro "creates" a "CNAME" record for "ghs" with "%ZONE%.googleapps.com" -When I apply the macro -Then the domain should have a "CNAME" record for "ghs" with "example.com.googleapps.com" + Scenario: Macro to update existing records with zone interpolation + Given I have a domain named "example.com" + And the domain has a "CNAME" record for "ghs" with "something.googleapps.com" + Given I have a macro + And the macro "updates" a "CNAME" record for "ghs" with "%ZONE%.googleapps.com" + When I apply the macro + Then the domain should have a "CNAME" record for "ghs" with "example.com.googleapps.com" -Scenario: Macro to update existing records -Given I have a domain -And the domain has an "A" record for "www" with "127.0.0.1" -Given I have a macro -And the macro "updates" an "A" record for "www" with "127.0.0.2" -When I apply the macro -Then the domain should have an "A" record for "www" with "127.0.0.2" -And the domain should not have an "A" record for "www" with "127.0.0.1" + Scenario: Macro to remove existing records + Given I have a domain + And the domain has an "A" record for "www" with "127.0.0.1" + Given I have a macro + And the macro "removes" an "A" record for "www" + When I apply the macro + Then the domain should not have an "A" record for "www" -Scenario: Macro to update existing records with zone interpolation -Given I have a domain named "example.com" -And the domain has a "CNAME" record for "ghs" with "something.googleapps.com" -Given I have a macro -And the macro "updates" a "CNAME" record for "ghs" with "%ZONE%.googleapps.com" -When I apply the macro -Then the domain should have a "CNAME" record for "ghs" with "example.com.googleapps.com" + Scenario: Macro to remove all records by type + Given I have a domain + And the domain has an "A" record for "www" with "127.0.0.1" + And the domain has an "A" record for "ftp" with "127.0.0.2" + Given I have a macro + And the macro "removes" an "A" record for "*" + When I apply the macro + Then the domain should not have an "A" record for "www" + And the domain should not have an "A" record for "ftp" -Scenario: Macro to remove existing records -Given I have a domain -And the domain has an "A" record for "www" with "127.0.0.1" -Given I have a macro -And the macro "removes" an "A" record for "www" -When I apply the macro -Then the domain should not have an "A" record for "www" + Scenario: Macro to update non-existing records + Given I have a domain + Given I have a macro + And the macro "updates" an "A" record for "www" with "127.0.0.1" + When I apply the macro + Then the domain should not have an "A" record for "www" -Scenario: Macro to remove all records by type -Given I have a domain -And the domain has an "A" record for "www" with "127.0.0.1" -And the domain has an "A" record for "ftp" with "127.0.0.2" -Given I have a macro -And the macro "removes" an "A" record for "*" -When I apply the macro -Then the domain should not have an "A" record for "www" -And the domain should not have an "A" record for "ftp" + Scenario: Macro to remove non-existing records + Given I have a domain + Given I have a macro + And the macro "removes" an "A" record for "www" + When I apply the macro + Then the domain should not have an "A" record for "www" -Scenario: Macro to update non-existing records -Given I have a domain -Given I have a macro -And the macro "updates" an "A" record for "www" with "127.0.0.1" -When I apply the macro -Then the domain should not have an "A" record for "www" + Scenario: Macro to create/update existing records + Given I have a domain + And the domain has an "A" record for "www" with "127.0.0.1" + Given I have a macro + And the macro "creates_updates" an "A" record for "www" with "127.0.0.2" + When I apply the macro + Then the domain should have an "A" record for "www" with "127.0.0.2" -Scenario: Macro to remove non-existing records -Given I have a domain -Given I have a macro -And the macro "removes" an "A" record for "www" -When I apply the macro -Then the domain should not have an "A" record for "www" + Scenario: Macro to create/update non-existing records + Given I have a domain + Given I have a macro + And the macro "creates_updates" an "A" record for "www" with "127.0.0.1" + When I apply the macro + Then the domain should have an "A" record for "www" with "127.0.0.1" -Scenario: Macro to create/update existing records -Given I have a domain -And the domain has an "A" record for "www" with "127.0.0.1" -Given I have a macro -And the macro "creates_updates" an "A" record for "www" with "127.0.0.2" -When I apply the macro -Then the domain should have an "A" record for "www" with "127.0.0.2" + Scenario: Macro to create multiple records of the same kind + Given I have a domain + Given I have a macro + And the macro "creates" an "MX" record with "mail" with priority "10" + And the macro "creates" an "MX" record with "backup" with priority "20" + When I apply the macro + Then the domain should have an "MX" record with priority "10" + And the domain should have an "MX" record with priority "20" -Scenario: Macro to create/update non-existing records -Given I have a domain -Given I have a macro -And the macro "creates_updates" an "A" record for "www" with "127.0.0.1" -When I apply the macro -Then the domain should have an "A" record for "www" with "127.0.0.1" - -Scenario: Macro to create multiple records of the same kind -Given I have a domain -Given I have a macro -And the macro "creates" an "MX" record with "mail" with priority "10" -And the macro "creates" an "MX" record with "backup" with priority "20" -When I apply the macro -Then the domain should have an "MX" record with priority "10" -And the domain should have an "MX" record with priority "20" From 0d9e008011fe45a6bfa8b9d787afd50da4945147 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Tue, 13 Jan 2015 20:26:42 +0200 Subject: [PATCH 27/31] chore: fresh cucumber configuration --- features/step_definitions/.gitkeep | 0 features/support/env.rb | 28 ++++++++++++++++++---------- lib/tasks/cucumber.rake | 14 +++++++------- 3 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 features/step_definitions/.gitkeep diff --git a/features/step_definitions/.gitkeep b/features/step_definitions/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/features/support/env.rb b/features/support/env.rb index 6c40c8f1..64ddf610 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,20 +1,19 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. require 'cucumber/rails' -# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In -# order to ease the transition to Capybara we set the default here. If you'd -# prefer to use XPath just remove this line and adjust any selectors in your -# steps to use the XPath syntax. -Capybara.default_selector = :css +# Capybara defaults to CSS3 selectors rather than XPath. +# If you'd prefer to use XPath, just uncomment this line and adjust any +# selectors in your step definitions to use the XPath syntax. +# Capybara.default_selector = :xpath # By default, any exception happening in your Rails application will bubble up -# to Cucumber so that your scenario will fail. This is a different from how -# your application behaves in the production environment, where an error page will +# to Cucumber so that your scenario will fail. This is a different from how +# your application behaves in the production environment, where an error page will # be rendered instead. # # Sometimes we want to override this default behaviour and allow Rails to rescue @@ -41,10 +40,19 @@ # See the DatabaseCleaner documentation for details. Example: # # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do -# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]} +# # { :except => [:widgets] } may not do what you expect here +# # as Cucumber::Rails::Database.javascript_strategy overrides +# # this setting. +# DatabaseCleaner.strategy = :truncation # end # # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do # DatabaseCleaner.strategy = :transaction # end # + +# Possible values are :truncation and :transaction +# The :transaction strategy is faster, but might give you threading problems. +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature +Cucumber::Rails::Database.javascript_strategy = :truncation + diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 83f79471..9f53ce49 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. @@ -14,19 +14,19 @@ begin require 'cucumber/rake/task' namespace :cucumber do - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t| t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. t.fork = true # You may get faster startup if you set this to false t.profile = 'default' end - Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| + Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t| t.binary = vendored_cucumber_bin t.fork = true # You may get faster startup if you set this to false t.profile = 'wip' end - Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| + Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t| t.binary = vendored_cucumber_bin t.fork = true # You may get faster startup if you set this to false t.profile = 'rerun' @@ -50,8 +50,8 @@ begin STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" end - # In case we don't have ActiveRecord, append a no-op task that we can depend upon. - task 'db:test:prepare' do + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. + task 'test:prepare' do end task :stats => 'cucumber:statsetup' From 1e9eaa1c2f6b21e7f6944cc23287792654b67b0f Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Mon, 30 Mar 2015 22:10:08 +0200 Subject: [PATCH 28/31] chore: notify gitter of build status --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3aadab2a..fb8bffd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,3 +31,8 @@ matrix: - env: DB=sqlite sudo: false + +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/fd712cc811935fc71415 From bc213b7a4a814a6e4f003a97d7f3152f88840216 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Mon, 30 Mar 2015 22:10:38 +0200 Subject: [PATCH 29/31] chore: access rubygems over https --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 5a1b99ff..5365b150 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'http://rubygems.org' +source 'https://rubygems.org' gem 'rails', '~> 3.2.21' diff --git a/Gemfile.lock b/Gemfile.lock index 27fd4441..661b281c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: RedCloth (4.2.9) actionmailer (3.2.21) From 18a007f4e04cbda71ec4761b13dc8f6205ed021e Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Mon, 30 Mar 2015 22:10:58 +0200 Subject: [PATCH 30/31] feat: added gitter badge to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index be874d18..bcee9da7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Thanks for your support and understanding. [![Build Status](https://travis-ci.org/kennethkalmer/powerdns-on-rails.png?branch=master)](https://travis-ci.org/kennethkalmer/powerdns-on-rails) [![Code Climate](https://codeclimate.com/github/kennethkalmer/powerdns-on-rails.png)](https://codeclimate.com/github/kennethkalmer/powerdns-on-rails) [![Dependency Status](https://gemnasium.com/kennethkalmer/powerdns-on-rails.png)](https://gemnasium.com/kennethkalmer/powerdns-on-rails) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kennethkalmer/powerdns-on-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) PowerDNS on Rails is a Ruby on Rails application made to manage [PowerDNS](http://www.powerdns.com/) installations using the generic MySQL/PostgreSQL backends. From d33e40ebf0da19123ced1f74c2deaeb1b1edb851 Mon Sep 17 00:00:00 2001 From: Kenneth Kalmer Date: Mon, 30 Mar 2015 22:13:30 +0200 Subject: [PATCH 31/31] feat: rake defaults to all tests, and use ci task on travis --- .travis.yml | 2 +- Rakefile | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fb8bffd9..61a512d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_script: - bundle exec rake db:migrate - bundle exec rake db:seed -script: "bundle exec rake spec" +script: "bundle exec rake ci" matrix: allow_failures: diff --git a/Rakefile b/Rakefile index 3faca57b..f1f4499b 100644 --- a/Rakefile +++ b/Rakefile @@ -5,3 +5,6 @@ require File.expand_path('../config/application', __FILE__) require 'rake' PowerdnsOnRails::Application.load_tasks + +task :default => [ :spec, :cucumber ] +task :ci => [ :spec, :cucumber ]