Permalink
Browse files

Add specs & features for the mock activation/deactivation functionality.

  • Loading branch information...
1 parent 1a2e0f2 commit 978bec4dd7eb33244ddfca3807d8dd386cc862f0 @iridakos committed Apr 10, 2016
@@ -1,7 +1,8 @@
Feature: There is a mocks page with options to do stuff
Background:
- * There are 3 mocks
+ * There are 3 active mocks
+ * There are 3 inactive mocks
* I visit the mocks page
* I should see a link with text 'Create new mock'
* I should not see a link with text 'View all mocks'
@@ -40,3 +41,31 @@ Scenario: I can select to delete a mock
And I accept the javascript confirmation
Then I should be on the mocks page
And There should not be an entry for mock with id 1
+
+@selenium @javascript
+Scenario: I can activate a mock
+ When I click the activate link for mock with id 4
+ Then I should see a javascript confirmation with text 'Are you sure you want to activate this mock?'
+ When I dismiss the javascript confirmation
+ Then I should be on the mocks page
+ And There should be an entry for mock with id 4
+ When I click the activate link for mock with id 4
+ And I accept the javascript confirmation
+ Then I should be on the mocks page
+ When I click the deactivate link for mock with id 4
+ Then I should see a javascript confirmation with text 'Are you sure you want to deactivate this mock?'
+ And I dismiss the javascript confirmation
+
+@selenium @javascript
+Scenario: I can deactivate a mock
+ When I click the deactivate link for mock with id 1
+ Then I should see a javascript confirmation with text 'Are you sure you want to deactivate this mock?'
+ When I dismiss the javascript confirmation
+ Then I should be on the mocks page
+ And There should be an entry for mock with id 1
+ When I click the deactivate link for mock with id 1
+ And I accept the javascript confirmation
+ Then I should be on the mocks page
+ When I click the activate link for mock with id 4
+ Then I should see a javascript confirmation with text 'Are you sure you want to activate this mock?'
+ And I dismiss the javascript confirmation
@@ -4,8 +4,12 @@
When /^I accept the javascript confirmation$/ do
page.driver.browser.switch_to.alert.accept
+ # FIXME: we sleep here to allow the rails url helpers to be successfully reloaded with the new routes
+ sleep 2
end
When /^I dismiss the javascript confirmation$/ do
page.driver.browser.switch_to.alert.dismiss
+ # FIXME: we sleep here to allow the rails url helpers to be successfully reloaded with the new routes
+ sleep 2
end
@@ -1,6 +1,9 @@
-Given /^There are (\d*) mocks$/ do |number|
+Given /^There are (\d*)(?: )?(active|inactive)? mocks$/ do |number, active_status|
+ active = active_status != 'inactive'
+ count = Duckrails::Mock.count
number.to_i.times do |i|
- FactoryGirl.create :mock, route_path: "/cucumber/#{i}", name: "Mock:#{i}", id: i
+ index = i + count
+ FactoryGirl.create :mock, route_path: "/cucumber/#{index}", name: "Mock:#{index}", id: index, active: active
end
end
@@ -12,6 +15,14 @@
page.find("table.mocks tbody tr[data-mock-id='#{mock_id}']").find('a.delete').click
end
+When /^I click the activate link for mock with id (\d*)$/ do |mock_id|
+ page.find("table.mocks tbody tr[data-mock-id='#{mock_id}']").find('a.activate').click
+end
+
+When /^I click the deactivate link for mock with id (\d*)$/ do |mock_id|
+ page.find("table.mocks tbody tr[data-mock-id='#{mock_id}']").find('a.deactivate').click
+end
+
Then /^There should( not)? be an entry for mock with id (\d*)$/ do |should_not, mock_id|
should_mode = should_not ? :not_to : :to
expect(page).send should_mode, have_css("table.mocks tbody tr[data-mock-id='#{mock_id}']")
@@ -7,6 +7,8 @@ module Duckrails
it { should execute_before_action :load_mock, :on => :edit, with: { id: 'foo' } }
it { should execute_before_action :load_mock, :on => :update, with: { id: 'foo' } }
it { should execute_before_action :load_mock, :on => :destroy, with: { id: 'foo' } }
+ it { should execute_before_action :load_mock, :on => :activate, with: { id: 'foo' } }
+ it { should execute_before_action :load_mock, :on => :deactivate, with: { id: 'foo' } }
it { should_not execute_before_action :load_mock, :on => :index }
it { should_not execute_before_action :load_mock, :on => :new }
@@ -31,6 +33,8 @@ module Duckrails
it { should execute_after_action :reload_routes, :on => :update, with: { id: mock.id } }
it { should execute_after_action :reload_routes, :on => :create }
it { should execute_after_action :reload_routes, :on => :destroy, with: { id: mock.id } }
+ it { should execute_after_action :reload_routes, :on => :activate, with: { id: mock.id } }
+ it { should execute_after_action :reload_routes, :on => :deactivate, with: { id: mock.id } }
it { should_not execute_after_action :reload_routes, :on => :index }
it { should_not execute_after_action :reload_routes, :on => :new }
end
@@ -226,7 +230,40 @@ module Duckrails
it { should redirect_to duckrails_mocks_path }
end
+ end
+
+ describe 'put #activate' do
+ let(:mock) { FactoryGirl.create :mock, active: false }
+
+ before do
+ expect(mock).to receive(:activate!).and_call_original
+ allow(Mock).to receive(:find).twice.and_return(mock)
+
+ put :activate, id: mock.id
+ end
+ describe 'response' do
+ subject { response }
+
+ it { should redirect_to duckrails_mocks_path }
+ end
+ end
+
+ describe 'put #deactivate' do
+ let(:mock) { FactoryGirl.create :mock, active: true }
+
+ before do
+ expect(mock).to receive(:deactivate!).and_call_original
+ allow(Mock).to receive(:find).twice.and_return(mock)
+
+ put :deactivate, id: mock.id
+ end
+
+ describe 'response' do
+ subject { response }
+
+ it { should redirect_to duckrails_mocks_path }
+ end
end
describe '#serve_mock' do
@@ -17,6 +17,14 @@
expect(get: '/duckrails/mocks/1/edit').to route_to(controller: 'duckrails/mocks', action: 'edit', id: '1')
end
+ it 'should route to mocks activate' do
+ expect(put: '/duckrails/mocks/1/activate').to route_to(controller: 'duckrails/mocks', action: 'activate', id: '1')
+ end
+
+ it 'should route to mocks deactivate' do
+ expect(put: '/duckrails/mocks/1/deactivate').to route_to(controller: 'duckrails/mocks', action: 'deactivate', id: '1')
+ end
+
it 'should route to mocks update' do
expect(put: '/duckrails/mocks/1').to route_to(controller: 'duckrails/mocks', action: 'update', id: '1')
expect(patch: '/duckrails/mocks/1').to route_to(controller: 'duckrails/mocks', action: 'update', id: '1')
@@ -102,7 +102,7 @@
context 'with existing record' do
let(:mock) { FactoryGirl.create :mock }
- it { should have_css "a[href='#{duckrails_mock_path(mock)}'][data-method='delete'][data-confirm='#{t(:delete_mock_confirmation)}']", text: t(:delete) }
+ it { should have_css "a[href='#{duckrails_mock_path(mock)}'][data-method='delete'][data-confirm='#{t(:mock_deletion_confirmation)}']", text: t(:delete) }
end
context 'with new record' do
@@ -6,9 +6,15 @@
let(:page) { Capybara::Node::Simple.new(rendered) }
before do
- 3.times do |i|
- FactoryGirl.create(:mock, name: "Mock-#{i + 1}", route_path: "/duck/#{i}")
- end if with_mocks
+ if with_mocks
+ 3.times do |i|
+ FactoryGirl.create(:mock, name: "Mock-#{i + 1}", route_path: "/duck/#{i + 1}")
+ end
+
+ 2.times do |i|
+ FactoryGirl.create(:mock, name: "Mock-#{i + 4}", route_path: "/duck/#{i + 4}", active: false)
+ end
+ end
assign :mocks, Duckrails::Mock.page(0).per(per_page)
@@ -38,6 +44,7 @@
it { should have_css 'thead th', text: t(:mock_name) }
it { should have_css 'thead th', text: t(:mock_method) }
it { should have_css 'thead th', text: t(:mock_route) }
+ it { should have_css 'thead th.text-center', text: t(:mock_active) }
it { should have_css 'thead th', text: t(:mock_actions) }
it 'should display all mocks' do
@@ -52,6 +59,9 @@
expect(subject).to have_css "tbody tr[data-mock-id='#{mock.id}'] td.actions a[href='#{view.edit_duckrails_mock_path(mock)}']"
expect(subject).to have_css "tbody tr[data-mock-id='#{mock.id}'] td.actions a[href='#{view.duckrails_mock_path(mock)}'][data-method='delete']"
end
+
+ expect(subject).to have_css 'tbody td span.active i.fa.fa-check-square-o', count: 3
+ expect(subject).to have_css 'tbody td span.inactive i.fa.fa-square-o', count: 2
end
end

0 comments on commit 978bec4

Please sign in to comment.