From d9240aa4f8e6ace675eb583b50ed290507d46475 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 18 Aug 2014 12:26:55 +0300 Subject: [PATCH 1/3] Add feature testing support --- Gemfile | 11 +++-- Gemfile.lock | 51 +++++++++++++------- app/views/setting_groups/show.haml | 2 +- config/locales/en.yml | 2 +- spec/epp/contact_spec.rb | 28 +++++------ spec/fabricators/setting_fabricator.rb | 3 ++ spec/fabricators/setting_group_fabricator.rb | 7 +++ spec/features/setting_management_spec.rb | 37 ++++++++++++++ spec/models/contact_spec.rb | 2 +- spec/models/setting_group_spec.rb | 5 ++ spec/models/setting_spec.rb | 5 ++ spec/rails_helper.rb | 7 +++ 12 files changed, 123 insertions(+), 37 deletions(-) create mode 100644 spec/fabricators/setting_fabricator.rb create mode 100644 spec/fabricators/setting_group_fabricator.rb create mode 100644 spec/features/setting_management_spec.rb create mode 100644 spec/models/setting_group_spec.rb create mode 100644 spec/models/setting_spec.rb diff --git a/Gemfile b/Gemfile index fda2808be..d6d0e14a8 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,11 @@ group :development do end group :development, :test do + gem 'capybara', '~> 2.4.1' + # For feature testing + # gem 'capybara-webkit', '1.2.0' # Webkit driver didn't work with turbolinks + gem 'poltergeist', '~> 1.5.1' # We are using PhantomJS instead + # For cleaning db in feature and epp tests gem 'database_cleaner', '~> 1.3.0' @@ -73,11 +78,11 @@ group :development, :test do gem 'faker', '~> 1.3.0' # For debugging - gem 'pry' - gem 'pry-byebug' + gem 'pry', '~> 0.10.1' + gem 'pry-byebug', '~> 1.3.3' # Testing framework - gem 'rspec-rails', '~> 3.0.1' + gem 'rspec-rails', '~> 3.0.2' # Additional matchers for RSpec gem 'shoulda-matchers', '~> 2.6.1', require: false diff --git a/Gemfile.lock b/Gemfile.lock index f60a53d70..337aad499 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,6 +34,13 @@ GEM byebug (2.7.0) columnize (~> 0.3) debugger-linecache (~> 1.2) + capybara (2.4.1) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + cliver (0.3.2) coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) @@ -63,7 +70,7 @@ GEM railties (>= 4.0.1) hike (1.2.3) hpricot (0.8.6) - i18n (0.6.9) + i18n (0.6.11) isikukood (0.1.2) jbuilder (2.1.1) activesupport (>= 3.0.0, < 5) @@ -81,19 +88,24 @@ GEM method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.0) - minitest (5.3.5) + minitest (5.4.0) multi_json (1.10.1) nokogiri (1.6.2.1) mini_portile (= 0.6.0) pg (0.17.1) + poltergeist (1.5.1) + capybara (~> 2.1) + cliver (~> 0.3.1) + multi_json (~> 1.0) + websocket-driver (>= 0.2.0) polyglot (0.3.5) - pry (0.9.12.6) - coderay (~> 1.0) - method_source (~> 0.8) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) slop (~> 3.4) - pry-byebug (1.3.2) + pry-byebug (1.3.3) byebug (~> 2.7) - pry (~> 0.9.12) + pry (~> 0.10) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -117,14 +129,14 @@ GEM rdoc (4.1.1) json (~> 1.4) ref (1.0.5) - rspec-core (3.0.1) + rspec-core (3.0.4) rspec-support (~> 3.0.0) - rspec-expectations (3.0.1) + rspec-expectations (3.0.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.0.0) - rspec-mocks (3.0.1) + rspec-mocks (3.0.4) rspec-support (~> 3.0.0) - rspec-rails (3.0.1) + rspec-rails (3.0.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -132,7 +144,7 @@ GEM rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) - rspec-support (3.0.0) + rspec-support (3.0.4) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -145,7 +157,7 @@ GEM shoulda-matchers (2.6.1) activesupport (>= 3.0.0) simpleidn (0.0.5) - slop (3.5.0) + slop (3.6.0) spring (1.1.3) sprockets (2.11.0) hike (~> 1.2) @@ -167,7 +179,7 @@ GEM polyglot (>= 0.3.1) turbolinks (2.2.2) coffee-rails - tzinfo (1.2.1) + tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.5.1) execjs (>= 0.3.0) @@ -177,12 +189,16 @@ GEM rack raindrops (~> 0.7) uuidtools (2.1.4) + websocket-driver (0.3.4) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES bootstrap-sass (~> 3.2.0.1) + capybara (~> 2.4.1) coffee-rails (~> 4.0.0) database_cleaner (~> 1.3.0) epp (~> 1.4.0) @@ -194,10 +210,11 @@ DEPENDENCIES jquery-rails nokogiri (~> 1.6.2.1) pg - pry - pry-byebug + poltergeist (~> 1.5.1) + pry (~> 0.10.1) + pry-byebug (~> 1.3.3) rails (= 4.1.4) - rspec-rails (~> 3.0.1) + rspec-rails (~> 3.0.2) sass-rails (~> 4.0.3) sdoc (~> 0.4.0) shoulda-matchers (~> 2.6.1) diff --git a/app/views/setting_groups/show.haml b/app/views/setting_groups/show.haml index f9baf4ac3..6f3e897c3 100644 --- a/app/views/setting_groups/show.haml +++ b/app/views/setting_groups/show.haml @@ -12,7 +12,7 @@ - @setting_group.settings.each do |setting| = f.fields_for :settings, setting do |sf| %tr - %td= t("settings.codes.#{sf.object.code}") + %td= sf.label :value, t("settings.codes.#{sf.object.code}") %td= sf.text_field(:value, autocomplete: 'off') .row .col-md-12.text-right diff --git a/config/locales/en.yml b/config/locales/en.yml index 152605419..a55e39c28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -86,7 +86,7 @@ en: setting_groups: codes: - domain_statuses: 'Domain statuses' + domain_validation: 'Domain validation' index: setting_group: 'Setting group' diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index bc28db8de..ece1f4d78 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -52,7 +52,7 @@ describe 'EPP Contact', epp: true do expect(id.text).to eq('sh8013') #5 seconds for what-ever weird lag reasons might happen expect(crDate.text.to_time).to be_within(5).of(Time.now) - + end it 'does not create duplicate contact' do @@ -62,7 +62,7 @@ describe 'EPP Contact', epp: true do expect(response[:result_code]).to eq('2302') expect(response[:msg]).to eq('Contact id already exists') - + expect(Contact.count).to eq(1) end end @@ -72,22 +72,22 @@ describe 'EPP Contact', epp: true do it "fails if request is invalid" do response = epp_request('contacts/update_missing_attr.xml') #response = epp_request(contact_update_xml( {id: false} ), :xml) - + expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:msg]).to eq('Required parameter missing: id') expect(response[:results].count).to eq 1 end - + it 'stamps updated_by succesfully' do Fabricate(:contact, code: 'sh8013') - + expect(Contact.first.updated_by_id).to be nil - + response = epp_request(contact_update_xml, :xml) expect(Contact.first.updated_by_id).to eq 1 end - + it 'is succesful' do Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013') #response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml) @@ -99,19 +99,19 @@ describe 'EPP Contact', epp: true do expect(Contact.first.ident).to eq('J836954') expect(Contact.first.ident_type).to eq('passport') end - - it 'returns phone and email error' do + + it 'returns phone and email error' do Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013') #response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml) response = epp_request('contacts/update_with_errors.xml') - + expect(response[:results][0][:result_code]).to eq('2005') expect(response[:results][0][:msg]).to eq('Phone nr is invalid') - + expect(response[:results][1][:result_code]).to eq('2005') expect(response[:results][1][:msg]).to eq('Email is invalid') end - end + end context 'delete command' do it "fails if request is invalid" do @@ -151,7 +151,7 @@ describe 'EPP Contact', epp: true do it 'returns info about contact' do Fabricate(:contact, code: 'check-1234') - + response = epp_request(contact_check_xml( ids: [{ id: 'check-1234'}, { id: 'check-4321' }] ), :xml) expect(response[:result_code]).to eq('1000') @@ -165,7 +165,7 @@ describe 'EPP Contact', epp: true do expect(ids[1].text).to eq('check-4321') end end - + context 'info command' do it "fails if request invalid" do response = epp_request('contacts/delete_missing_attr.xml') diff --git a/spec/fabricators/setting_fabricator.rb b/spec/fabricators/setting_fabricator.rb new file mode 100644 index 000000000..415280d09 --- /dev/null +++ b/spec/fabricators/setting_fabricator.rb @@ -0,0 +1,3 @@ +Fabricator(:setting) do + code 'ns_min_count' +end diff --git a/spec/fabricators/setting_group_fabricator.rb b/spec/fabricators/setting_group_fabricator.rb new file mode 100644 index 000000000..953dfe490 --- /dev/null +++ b/spec/fabricators/setting_group_fabricator.rb @@ -0,0 +1,7 @@ +Fabricator(:setting_group) do + code 'domain_validation' + settings { [ + Fabricate(:setting, code: 'ns_min_count', value: 1), + Fabricate(:setting, code: 'ns_max_count', value: 13) + ]} +end diff --git a/spec/features/setting_management_spec.rb b/spec/features/setting_management_spec.rb new file mode 100644 index 000000000..decf5622a --- /dev/null +++ b/spec/features/setting_management_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +feature 'Setting management' do + background { Fabricate(:setting_group) } + + scenario 'User changes a setting', js: true do + visit root_path + + # This ensures javascript works correctly + expect(page).to have_no_link 'Setting groups' + click_on 'Settings' + expect(page).to have_link 'Setting groups' + + click_on 'Setting groups' + expect(page).to have_text('Domain validation') + click_on 'Edit settings' + expect(page).to have_text('Nameserver minimum count') + expect(page).to have_text('Nameserver maximum count') + + val_min = find_field('Nameserver minimum count').value + val_max = find_field('Nameserver maximum count').value + + expect(val_min).to eq('1') + expect(val_max).to eq('13') + + fill_in('Nameserver minimum count', with: '3') + fill_in('Nameserver maximum count', with: '10') + + click_on 'Save' + + val_min = find_field('Nameserver minimum count').value + val_max = find_field('Nameserver maximum count').value + + expect(val_min).to eq('3') + expect(val_max).to eq('10') + end +end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index c485ce362..d722ed33e 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -34,7 +34,7 @@ describe Contact do before(:each) { @contact = Fabricate(:contact) } it 'should return true' do - expect(@contact.valid?).to be true + expect(@contact.valid?).to be true end end end diff --git a/spec/models/setting_group_spec.rb b/spec/models/setting_group_spec.rb new file mode 100644 index 000000000..e9aa964c6 --- /dev/null +++ b/spec/models/setting_group_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe SettingGroup do + it { should have_many(:settings) } +end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb new file mode 100644 index 000000000..d079011f3 --- /dev/null +++ b/spec/models/setting_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +describe Setting do + it { should belong_to(:setting_group) } +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 05223eb07..d59f9ca97 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -4,6 +4,7 @@ require 'spec_helper' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'shoulda/matchers' +require 'capybara/poltergeist' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -39,6 +40,10 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end + config.before(:each, js: true) do + DatabaseCleaner.strategy = :truncation + end + config.before(:each) do DatabaseCleaner.start end @@ -47,6 +52,8 @@ RSpec.configure do |config| DatabaseCleaner.clean end + Capybara.javascript_driver = :poltergeist + # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. From 4d37e3a0c1cdf7c4757eef0250705f04ea6befca Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 18 Aug 2014 12:44:45 +0300 Subject: [PATCH 2/3] Add feature testing info to readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 61785502c..f2d405cc1 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,13 @@ Wait for the greeting message on the STD, then send EPP/TCP frame: sample1trid ``` + +Testing +--- +For feature testing PhantomJS is used. + +* (Download)[https://bitbucket.org/ariya/phantomjs/downloads/] the correct binary for your OS +* Move the binary to `/usr/local/bin` * Before running tests for the first time: `rake db:seed` * Run tests: `rake` * Run EPP tests: `rake test:epp` From 330a732382f9dbd2ff96b4573908292fa99d0633 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 18 Aug 2014 12:45:45 +0300 Subject: [PATCH 3/3] Link fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f2d405cc1..543049933 100644 --- a/README.md +++ b/README.md @@ -120,9 +120,9 @@ Wait for the greeting message on the STD, then send EPP/TCP frame: Testing --- -For feature testing PhantomJS is used. +For feature testing, PhantomJS is used. -* (Download)[https://bitbucket.org/ariya/phantomjs/downloads/] the correct binary for your OS +* [Download](https://bitbucket.org/ariya/phantomjs/downloads/) the correct binary for your OS * Move the binary to `/usr/local/bin` * Before running tests for the first time: `rake db:seed` * Run tests: `rake`