-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Ruby Tests and Specs | ||
|
||
on: | ||
push: | ||
branches: master | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.2 | ||
bundler-cache: true | ||
working-directory: ./rblib | ||
|
||
- name: Run tests | ||
working-directory: ./rblib | ||
run: bundle exec rake test:commonlib | ||
|
||
- name: Run specs | ||
working-directory: ./rblib | ||
run: bundle exec rake spec:commonlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rake' | ||
|
||
gem 'rspec' | ||
gem 'test-unit' | ||
|
||
gem 'mocha' | ||
gem 'open4' | ||
gem 'unidecoder' | ||
gem 'webmock' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.8.4) | ||
public_suffix (>= 2.0.2, < 6.0) | ||
crack (0.4.5) | ||
rexml | ||
diff-lcs (1.5.0) | ||
hashdiff (1.0.1) | ||
mocha (2.0.4) | ||
ruby2_keywords (>= 0.0.5) | ||
open4 (1.3.4) | ||
power_assert (2.0.3) | ||
public_suffix (5.0.3) | ||
rake (13.0.6) | ||
rexml (3.2.6) | ||
rspec (3.12.0) | ||
rspec-core (~> 3.12.0) | ||
rspec-expectations (~> 3.12.0) | ||
rspec-mocks (~> 3.12.0) | ||
rspec-core (3.12.2) | ||
rspec-support (~> 3.12.0) | ||
rspec-expectations (3.12.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-mocks (3.12.6) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-support (3.12.1) | ||
ruby2_keywords (0.0.5) | ||
test-unit (3.6.1) | ||
power_assert | ||
unidecoder (1.1.2) | ||
webmock (3.18.1) | ||
addressable (>= 2.8.0) | ||
crack (>= 0.3.2) | ||
hashdiff (>= 0.4.0, < 2.0.0) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
mocha | ||
open4 | ||
rake | ||
rspec | ||
test-unit | ||
unidecoder | ||
webmock | ||
|
||
BUNDLED WITH | ||
2.4.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
#!/bin/sh | ||
|
||
while read line | ||
do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,43 +3,70 @@ | |
require 'config' | ||
require 'survey' | ||
require 'test/unit' | ||
|
||
# We should really use a synthetic config file for testing, but the survey | ||
# module requires a real running instance of the mySociety survey service | ||
# and so can’t really be tested in splendid isolation. Therefore we make an | ||
# educated guess at where we might find a config file that contains connection | ||
# details for a running instance of the service. | ||
MySociety::Config::set_file(File.join(File.dirname(__FILE__), "..", "..", "..", "config", "general")) | ||
require 'mocha/test_unit' | ||
require 'webmock/test_unit' | ||
|
||
class TestSurvey < Test::Unit::TestCase | ||
|
||
def setup | ||
MySociety::Config.stubs(:get). | ||
with('SURVEY_URL').returns('https://example.com/survey') | ||
|
||
MySociety::Config.stubs(:get). | ||
with('SURVEY_SECRET').returns('ABC123') | ||
|
||
MySociety::Config.stubs(:get). | ||
with('SSL_CA_PATH', '/etc/ssl/certs/').returns('/etc/ssl/certs/') | ||
|
||
@survey = MySociety::Survey.new "survey_test.rb", "[email protected]" | ||
end | ||
|
||
def test_submit_ok | ||
# Just check we can submit with no exceptions | ||
return_url = "http://localhost/" | ||
|
||
stub_request(:post, 'https://example.com/survey') | ||
.with do |req| | ||
data = URI.decode_www_form(req.body).to_h | ||
data['foo'] == 'bar' && data['return_url'] == return_url | ||
end | ||
.to_return(status: 302, headers: { 'Location' => return_url }) | ||
|
||
assert_equal(return_url, @survey.submit("foo" => "bar", "return_url" => return_url)) | ||
end | ||
|
||
def test_already_done_no | ||
stub_request(:post, 'https://example.com/survey') | ||
.to_return(status: 200, body: '0') | ||
|
||
survey_we_never_do = MySociety::Survey.new "survey_test.rb", "[email protected]" | ||
assert !survey_we_never_do.already_done? | ||
end | ||
|
||
def test_already_done_yes | ||
stub_request(:post, 'https://example.com/survey') | ||
.to_return(status: 200, body: '1') | ||
|
||
@survey.submit("foo" => "bar", "return_url" => "") | ||
assert @survey.already_done? | ||
end | ||
|
||
def test_allow_new_survey | ||
stub_request(:post, 'https://example.com/survey') | ||
.to_return(status: 200, body: '1') | ||
|
||
@survey.submit("foo" => "bar", "return_url" => "") | ||
assert @survey.already_done? | ||
|
||
stub_request(:post, 'https://example.com/survey') | ||
.to_return(status: 200, body: '0') | ||
|
||
@survey.allow_new_survey | ||
assert !@survey.already_done? | ||
|
||
stub_request(:post, 'https://example.com/survey') | ||
.to_return(status: 200, body: '1') | ||
|
||
@survey.submit("foo" => "bar", "return_url" => "") | ||
assert @survey.already_done? | ||
end | ||
|