Skip to content

Commit

Permalink
Merge pull request #1466 from theodi/staging
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
Floppy committed Jun 15, 2017
2 parents 2ada98b + 4fffc0a commit 9d4d3e2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
> Please provide a general summary of the issue in the Issue Title above
> fill out the headings below as applicable to the issue you are reporting,
> deleting as appropriate but offering us as much detail as you can to help us resolve the issue
### Expected Behaviour
> What should happen?
### Desired Behaviour (for enhancement suggestions only)
> if relevant include images or hyperlinks to other resources that clarify the enhancement you're seeking
### Current Behaviour (for problems)
> What currently happens that isn't expected behaviour?
### Steps to Reproduce (for problems)
> Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant
1.
2.
3.
4.

### Your Environment
> Include as many relevant details about the environment you experienced the bug in - this will help us resolve the bug more expediently
* Environment name and version (e.g. Chrome 39, node.js 5.4):
* Operating System and version (desktop or mobile):
6 changes: 5 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ class User < ActiveRecord::Base
has_many :received_claims, class_name: 'Claim', foreign_key: 'user_id'
has_many :certification_campaigns

attr_accessible :name, :short_name, :email, :password, :password_confirmation, :default_jurisdiction, :organization, :agreed_to_terms, :preferred_locale
attr_accessible :name, :short_name, :email, :password, :password_confirmation, :default_jurisdiction, :organization, :agreed_to_terms, :preferred_locale, :inhuman

before_save :ensure_authentication_token

validates :agreed_to_terms, acceptance: {accept: true}, allow_nil: true
validates :preferred_locale, inclusion: {in: I18n.available_locales.map(&:to_s)}

# Spam filtering only
attr_accessor :inhuman
validates :inhuman, inclusion: { :in => ["0"] }, allow_nil: true

def self.engaged_users
User.where("confirmed_at IS NOT NULL").select { |u| !u.datasets.blank? }
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/devise/registrations/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
= f.check_box :agreed_to_terms
= t('authentication.agree_to_terms', terms_link: link_to(t('authentication.terms'), terms_page_path)).html_safe

= f.submit t("authentication.sign_up"), :class => 'btn btn-primary'
= f.check_box :inhuman, :style => "display: none;", :value => 0
= f.submit t("authentication.sign_up"), :class => 'btn btn-primary'
4 changes: 2 additions & 2 deletions features/agreeing_to_terms.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Feature: agreeing to terms of use
Scenario: I need to agree to the terms of use to save my details
When I enter an organization of "Example Org"
And I do not agree to the terms
And I enter my password
And I enter my current password
And I click save
Then there is an error message about agreeing to terms
And my changes are not saved

Scenario: I agree to terms of use and save my details
When I enter an organization of "Example Org"
And I agree to the terms
And I enter my password
And I enter my current password
And I click save
Then there is no error message
And my changes are saved
Expand Down
23 changes: 23 additions & 0 deletions features/registering_account.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: registering a new account

Background:
Given I visit the home page
And I click "Register"

Scenario: I can sign up for an account successfully
When I enter my email address
And I enter my password
And I confirm my password
And I agree to the terms
And I click sign up
Then an account should be created

Scenario: Dumb bots that autotick boxes can't make accounts
When I enter my email address
And I enter my password
And I confirm my password
And I agree to the terms
And I tick the inhuman box
And I click sign up
Then an account should not be created
And there is an error message about being human
38 changes: 38 additions & 0 deletions features/step_definitions/user_details.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Given(/^I visit the home page$/) do
visit '/'
end

Given(/^I visit the edit account page$/) do
visit edit_user_registration_path(@user)
end
Expand All @@ -15,14 +19,31 @@
first('#user_agreed_to_terms').set(false)
end

When(/^I enter my email address$/) do
@email = "email@example.com"
first('#user_email').set(@email)
end

When(/^I confirm my password$/) do
first('#user_password_confirmation').set('password')
end

When(/^I enter my password$/) do
first('#user_password').set('password')
end

When(/^I enter my current password$/) do
first('#user_current_password').set('password')
end

When(/^I click save$/) do
click_on 'Update my profile'
end

When(/^I click sign up$/) do
first('#register input[type=submit]').click
end

Then(/^there is an error message about agreeing to terms$/) do
assert_text('Errors occurred')
end
Expand All @@ -31,10 +52,27 @@
assert_no_text('Errors occurred')
end

When(/^I tick the inhuman box$/) do
first('#user_inhuman', visible: false).set(true)
end

Then(/^there is an error message about being human$/) do
assert_text('Errors occurred')
end

Then(/^my changes are saved$/) do
assert_equal @organization, @user.reload.organization
end

Then(/^my changes are not saved$/) do
refute_equal @organization, @user.reload.organization
end

Then(/^an account should be created$/) do
assert_equal 1, User.count
assert_equal @email, User.first.email
end

Then(/^an account should not be created$/) do
assert_equal 0, User.count
end

0 comments on commit 9d4d3e2

Please sign in to comment.