From c3a36670655a3518d3b6387742f3ae14202e9790 Mon Sep 17 00:00:00 2001 From: Nathan Woodhull Date: Thu, 12 Nov 2026 18:45:35 -0500 Subject: [PATCH 1/4] Allow json 3 The ~> 2.1 pin stopped consumers upgrading to json 3. The gem only calls JSON.parse and JSON.generate, which json 3 keeps unchanged. Co-Authored-By: Claude Opus 5.5 --- Gemfile | 2 +- VERSION | 2 +- nation_builder.gemspec | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index d6d0e76..7618237 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' # NationBuilder puts error messages in a different location. gem 'oauth2', git: 'https://github.com/controlshift/oauth2.git' -gem 'json', '~> 2.1' +gem 'json', '>= 2.1' gem 'activesupport', '>3.0.0' group :development do diff --git a/VERSION b/VERSION index 927734f..a618622 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.17 \ No newline at end of file +0.0.18 \ No newline at end of file diff --git a/nation_builder.gemspec b/nation_builder.gemspec index 69e4a35..a0bff39 100644 --- a/nation_builder.gemspec +++ b/nation_builder.gemspec @@ -2,16 +2,16 @@ # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- -# stub: nation_builder 0.0.17 ruby lib +# stub: nation_builder 0.0.18 ruby lib Gem::Specification.new do |s| s.name = "nation_builder".freeze - s.version = "0.0.17" + s.version = "0.0.18" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Nathan Woodhull".freeze, "Dan Schneiderman".freeze] - s.date = "2021-09-27" + s.date = "2026-11-12" s.description = "Ruby wrapper for NationBuilder API".freeze s.email = "nathan@controlshiftlabs.com".freeze s.extra_rdoc_files = [ @@ -59,7 +59,7 @@ Gem::Specification.new do |s| if s.respond_to? :add_runtime_dependency then s.add_runtime_dependency(%q.freeze, [">= 0"]) - s.add_runtime_dependency(%q.freeze, ["~> 2.1"]) + s.add_runtime_dependency(%q.freeze, [">= 2.1"]) s.add_runtime_dependency(%q.freeze, ["> 3.0.0"]) s.add_development_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) s.add_development_dependency(%q.freeze, ["~> 9.0", ">= 9.0.6"]) @@ -68,7 +68,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q.freeze, ["~> 2.4", ">= 2.4.7"]) else s.add_dependency(%q.freeze, [">= 0"]) - s.add_dependency(%q.freeze, ["~> 2.1"]) + s.add_dependency(%q.freeze, [">= 2.1"]) s.add_dependency(%q.freeze, ["> 3.0.0"]) s.add_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) s.add_dependency(%q.freeze, ["~> 9.0", ">= 9.0.6"]) From 11e9911ed869d370317bd5d7eb156dcf1a3980a0 Mon Sep 17 00:00:00 2001 From: Nathan Woodhull Date: Thu, 12 Nov 2026 18:45:56 -0500 Subject: [PATCH 2/4] Require oauth2 2.x Drop the old controlshift/oauth2 fork from the Gemfile. It only applied to this gem's own development; consumers already resolve oauth2 from rubygems, and agra runs this gem on oauth2 2.1. Co-Authored-By: Claude Opus 5.5 --- Gemfile | 3 +-- nation_builder.gemspec | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 7618237..693a763 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'http://rubygems.org' -# NationBuilder puts error messages in a different location. -gem 'oauth2', git: 'https://github.com/controlshift/oauth2.git' +gem 'oauth2', '~> 2.0' gem 'json', '>= 2.1' gem 'activesupport', '>3.0.0' diff --git a/nation_builder.gemspec b/nation_builder.gemspec index a0bff39..881bdc4 100644 --- a/nation_builder.gemspec +++ b/nation_builder.gemspec @@ -58,7 +58,7 @@ Gem::Specification.new do |s| end if s.respond_to? :add_runtime_dependency then - s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_runtime_dependency(%q.freeze, ["~> 2.0"]) s.add_runtime_dependency(%q.freeze, [">= 2.1"]) s.add_runtime_dependency(%q.freeze, ["> 3.0.0"]) s.add_development_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) @@ -67,7 +67,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["~> 2.4", ">= 2.4.7"]) else - s.add_dependency(%q.freeze, [">= 0"]) + s.add_dependency(%q.freeze, ["~> 2.0"]) s.add_dependency(%q.freeze, [">= 2.1"]) s.add_dependency(%q.freeze, ["> 3.0.0"]) s.add_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) From 98b5f519f9eac04c35ebccb9df43c613f2be5983 Mon Sep 17 00:00:00 2001 From: Nathan Woodhull Date: Thu, 12 Nov 2026 18:47:22 -0500 Subject: [PATCH 3/4] Update Ruby versions and gem packaging Replace juwelier with a plain gemspec and Bundler's gem tasks, with the version in NationBuilder::VERSION. Require Ruby 3.3+ and run CI on 3.3, 3.4 and 4.0 for pushes to main and pull requests. The pending People specs made a live password-grant request to a real nation on every run, because spec_helper allowed real connections. They now stub NationBuilder with WebMock and real connections are blocked. The public API is unchanged. Co-Authored-By: Claude Opus 5.5 --- .document | 5 -- .github/workflows/ci.yml | 18 +++-- .rspec | 1 + .ruby-gemset | 1 - .ruby-version | 1 - Gemfile | 16 ++--- README.md | 7 +- Rakefile | 49 +------------ VERSION | 1 - lib/nation_builder.rb | 1 + lib/nation_builder/version.rb | 3 + nation_builder.gemspec | 94 +++++-------------------- spec/client_spec.rb | 2 +- spec/fixtures/not_found | 1 - spec/fixtures/people_list_empty | 1 - spec/fixtures/people_list_success | 1 - spec/nation_builder_spec.rb | 2 +- spec/people_spec.rb | 113 +++++++++++++++++++++--------- spec/spec_helper.rb | 47 +++---------- 19 files changed, 140 insertions(+), 224 deletions(-) delete mode 100644 .document delete mode 100644 .ruby-gemset delete mode 100644 .ruby-version delete mode 100644 VERSION create mode 100644 lib/nation_builder/version.rb delete mode 100644 spec/fixtures/not_found delete mode 100644 spec/fixtures/people_list_empty delete mode 100644 spec/fixtures/people_list_success diff --git a/.document b/.document deleted file mode 100644 index 3d618dd..0000000 --- a/.document +++ /dev/null @@ -1,5 +0,0 @@ -lib/**/*.rb -bin/* -- -features/**/*.feature -LICENSE.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6519e88..6a7abf8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,20 @@ name: CI -on: [push] +on: + push: + branches: [main] + pull_request: jobs: test: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.3', '3.4', '4.0'] steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6 + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle install - - run: bundle exec rspec + - run: bundle exec rake diff --git a/.rspec b/.rspec index 4e1e0d2..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ --color +--require spec_helper diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index cc9435e..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -nation_builder diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index a4dd9db..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.7.4 diff --git a/Gemfile b/Gemfile index 693a763..e2910ab 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,7 @@ -source 'http://rubygems.org' +source 'https://rubygems.org' -gem 'oauth2', '~> 2.0' -gem 'json', '>= 2.1' -gem 'activesupport', '>3.0.0' +gemspec -group :development do - gem 'webmock', '~> 3.0', '>= 3.0.1' - gem 'byebug', '~> 9.0', '>= 9.0.6' - gem 'rspec', '~> 3.6' - gem 'bundler', '>= 0' - gem 'juwelier', '~> 2.4', '>= 2.4.7' -end +gem 'rake' +gem 'rspec', '~> 3.13' +gem 'webmock', '~> 3.23' diff --git a/README.md b/README.md index fe8e3c8..92e0ee4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ http://nationbuilder.com/api_documentation require 'nation_builder' client = NationBuilder.new(hostname: 'whatever.nationbuilder.com', client_id: 'id', client_secret: 'secret', username: 'you@nation.com', password: 'pass') client.people.create('person' => {'first_name' => 'George', 'last_name' => 'Washington', 'email' => 'george@washington.com'}) -client.people.match('email' => 'george@washington.com) # either a person hash or nil. +client.people.match('email' => 'george@washington.com') # either a person hash or nil. client.people.list # returns people in nation client.tags.list # all tags. ``` @@ -23,10 +23,7 @@ The current gem is minimalist -- but we'd welcome pull requests with additional ### Release -``` -rake version:bump:minor -BRANCH=main rake release -``` +Bump `NationBuilder::VERSION` in `lib/nation_builder/version.rb`, merge to main, then run `bundle exec rake release`. ### Copyright diff --git a/Rakefile b/Rakefile index 68b8a1a..4c774a2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,49 +1,6 @@ -# encoding: utf-8 - -require 'rubygems' -require 'bundler' -begin - Bundler.setup(:default, :development) -rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" - exit e.status_code -end -require 'rake' - -require 'juwelier' -Juwelier::Tasks.new do |gem| - # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options - gem.name = "nation_builder" - gem.homepage = "http://github.com/controlshift/nation_builder" - gem.license = "MIT" - gem.summary = "NationBuilder API wrapper" - gem.description = %Q{Ruby wrapper for NationBuilder API} - gem.email = "nathan@controlshiftlabs.com" - gem.authors = ["Nathan Woodhull", "Dan Schneiderman"] - # dependencies defined in Gemfile -end -Juwelier::RubygemsDotOrgTasks.new - -require 'rspec/core' +require 'bundler/gem_tasks' require 'rspec/core/rake_task' -RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = FileList['spec/**/*_spec.rb'] -end - -RSpec::Core::RakeTask.new(:rcov) do |spec| - spec.pattern = 'spec/**/*_spec.rb' - spec.rcov = true -end - -task :default => :spec -require 'rdoc/task' -Rake::RDocTask.new do |rdoc| - version = File.exist?('VERSION') ? File.read('VERSION') : "" +RSpec::Core::RakeTask.new(:spec) - rdoc.rdoc_dir = 'rdoc' - rdoc.title = "nation_builder #{version}" - rdoc.rdoc_files.include('README*') - rdoc.rdoc_files.include('lib/**/*.rb') -end +task default: :spec diff --git a/VERSION b/VERSION deleted file mode 100644 index a618622..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.0.18 \ No newline at end of file diff --git a/lib/nation_builder.rb b/lib/nation_builder.rb index 91fcfeb..7bc874c 100644 --- a/lib/nation_builder.rb +++ b/lib/nation_builder.rb @@ -1,4 +1,5 @@ require 'oauth2' +require 'nation_builder/version' require 'active_support/all' require 'nation_builder/exceptions/validation_error' require 'nation_builder/actions/show' diff --git a/lib/nation_builder/version.rb b/lib/nation_builder/version.rb new file mode 100644 index 0000000..2918b4c --- /dev/null +++ b/lib/nation_builder/version.rb @@ -0,0 +1,3 @@ +module NationBuilder + VERSION = '0.1.0' +end diff --git a/nation_builder.gemspec b/nation_builder.gemspec index 881bdc4..5d4182b 100644 --- a/nation_builder.gemspec +++ b/nation_builder.gemspec @@ -1,80 +1,24 @@ -# Generated by juwelier -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec' -# -*- encoding: utf-8 -*- -# stub: nation_builder 0.0.18 ruby lib +require_relative 'lib/nation_builder/version' -Gem::Specification.new do |s| - s.name = "nation_builder".freeze - s.version = "0.0.18" +Gem::Specification.new do |spec| + spec.name = 'nation_builder' + spec.version = NationBuilder::VERSION + spec.authors = ['Nathan Woodhull', 'Dan Schneiderman'] + spec.email = ['nathan@controlshiftlabs.com'] - s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= - s.require_paths = ["lib".freeze] - s.authors = ["Nathan Woodhull".freeze, "Dan Schneiderman".freeze] - s.date = "2026-11-12" - s.description = "Ruby wrapper for NationBuilder API".freeze - s.email = "nathan@controlshiftlabs.com".freeze - s.extra_rdoc_files = [ - "LICENSE.txt", - "README.md" - ] - s.files = [ - ".document", - ".github/workflows/ci.yml", - ".rspec", - ".ruby-gemset", - ".ruby-version", - "Gemfile", - "LICENSE.txt", - "README.md", - "Rakefile", - "VERSION", - "lib/nation_builder.rb", - "lib/nation_builder/actions/create.rb", - "lib/nation_builder/actions/list.rb", - "lib/nation_builder/actions/show.rb", - "lib/nation_builder/actions/update.rb", - "lib/nation_builder/client.rb", - "lib/nation_builder/exceptions/validation_error.rb", - "lib/nation_builder/people.rb", - "lib/nation_builder/remote_controller.rb", - "lib/nation_builder/tags.rb", - "nation_builder.gemspec", - "spec/client_spec.rb", - "spec/fixtures/not_found", - "spec/fixtures/people_list_empty", - "spec/fixtures/people_list_success", - "spec/nation_builder_spec.rb", - "spec/people_spec.rb", - "spec/spec_helper.rb" - ] - s.homepage = "http://github.com/controlshift/nation_builder".freeze - s.licenses = ["MIT".freeze] - s.rubygems_version = "3.1.6".freeze - s.summary = "NationBuilder API wrapper".freeze + spec.summary = 'NationBuilder API wrapper' + spec.description = 'Ruby wrapper for NationBuilder API' + spec.homepage = 'https://github.com/controlshift/nation_builder' + spec.license = 'MIT' + spec.required_ruby_version = '>= 3.3' - if s.respond_to? :specification_version then - s.specification_version = 4 - end + spec.metadata['source_code_uri'] = spec.homepage + spec.metadata['rubygems_mfa_required'] = 'true' - if s.respond_to? :add_runtime_dependency then - s.add_runtime_dependency(%q.freeze, ["~> 2.0"]) - s.add_runtime_dependency(%q.freeze, [">= 2.1"]) - s.add_runtime_dependency(%q.freeze, ["> 3.0.0"]) - s.add_development_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) - s.add_development_dependency(%q.freeze, ["~> 9.0", ">= 9.0.6"]) - s.add_development_dependency(%q.freeze, ["~> 3.6"]) - s.add_development_dependency(%q.freeze, [">= 0"]) - s.add_development_dependency(%q.freeze, ["~> 2.4", ">= 2.4.7"]) - else - s.add_dependency(%q.freeze, ["~> 2.0"]) - s.add_dependency(%q.freeze, [">= 2.1"]) - s.add_dependency(%q.freeze, ["> 3.0.0"]) - s.add_dependency(%q.freeze, ["~> 3.0", ">= 3.0.1"]) - s.add_dependency(%q.freeze, ["~> 9.0", ">= 9.0.6"]) - s.add_dependency(%q.freeze, ["~> 3.6"]) - s.add_dependency(%q.freeze, [">= 0"]) - s.add_dependency(%q.freeze, ["~> 2.4", ">= 2.4.7"]) - end -end + spec.files = Dir['lib/**/*.rb', 'LICENSE.txt', 'README.md'] + spec.require_paths = ['lib'] + spec.add_dependency 'activesupport', '>= 7.0' + spec.add_dependency 'json', '>= 2.1' + spec.add_dependency 'oauth2', '~> 2.0' +end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 2c81aa6..60953f2 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') +require 'spec_helper' describe NationBuilder::Client do shared_examples 'request' do diff --git a/spec/fixtures/not_found b/spec/fixtures/not_found deleted file mode 100644 index de7b766..0000000 --- a/spec/fixtures/not_found +++ /dev/null @@ -1 +0,0 @@ -{"code"=>"not_found", "message"=>"Record not found"} \ No newline at end of file diff --git a/spec/fixtures/people_list_empty b/spec/fixtures/people_list_empty deleted file mode 100644 index 0e73193..0000000 --- a/spec/fixtures/people_list_empty +++ /dev/null @@ -1 +0,0 @@ -{\"page\":20,\"total_pages\":1,\"per_page\":10,\"total\":4,\"results\":[]} \ No newline at end of file diff --git a/spec/fixtures/people_list_success b/spec/fixtures/people_list_success deleted file mode 100644 index 3592db3..0000000 --- a/spec/fixtures/people_list_success +++ /dev/null @@ -1 +0,0 @@ -{\"page\":1,\"total_pages\":1,\"per_page\":10,\"total\":4,\"results\":[{\"id\":4,\"external_id\":null,\"support_level\":null,\"first_name\":\"John\",\"last_name\":\"Doe\",\"email\":\"johndoe@gmail.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2013-09-17T15:23:44-07:00\",\"updated_at\":\"2013-09-17T15:23:44-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":3,\"external_id\":null,\"support_level\":null,\"first_name\":\"Nathan\",\"last_name\":\"Woodhull\",\"email\":\"woodhull@gmail.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":{\"address1\":null,\"address2\":null,\"city\":\"Brooklyn\",\"state\":\"NY\",\"country_code\":\"US\",\"zip\":null,\"lat\":\"40.6528762\",\"lng\":\"-73.959494\"},\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2013-09-16T07:39:14-07:00\",\"updated_at\":\"2013-09-16T07:40:34-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":true,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":2,\"external_id\":null,\"support_level\":null,\"first_name\":\"Nathan\",\"last_name\":\"Woodhull\",\"email\":\"nathan@controlshiftlabs.com\",\"phone\":\"518-207-6768\",\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[\"customer - signed in\"],\"recruiter_id\":null,\"created_at\":\"2012-09-20T07:03:26-07:00\",\"updated_at\":\"2013-09-16T14:11:28-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":true,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null},{\"id\":1,\"external_id\":null,\"support_level\":null,\"first_name\":\"NationBuilder\",\"last_name\":\"Support\",\"email\":\"help@nationbuilder.com\",\"phone\":null,\"mobile\":null,\"birthdate\":null,\"sex\":null,\"note\":null,\"primary_address\":null,\"tags\":[],\"recruiter_id\":null,\"created_at\":\"2012-09-20T07:03:26-07:00\",\"updated_at\":\"2013-09-16T11:18:53-07:00\",\"mobile_opt_in\":true,\"email_opt_in\":false,\"is_volunteer\":false,\"is_twitter_follower\":false,\"has_facebook\":false,\"state_file_id\":null,\"nbec_guid\":null,\"van_id\":null,\"dw_id\":null,\"ngp_id\":null,\"pf_strat_id\":null,\"county_file_id\":null,\"twitter_name\":null,\"twitter_id\":null,\"salesforce_id\":null,\"civicrm_id\":null,\"linkedin_id\":null,\"employer\":null,\"occupation\":null,\"supranational_district\":null,\"federal_district\":null,\"labour_region\":null,\"state_upper_district\":null,\"state_lower_district\":null,\"city_district\":null,\"county_district\":null,\"judicial_district\":null,\"school_district\":null,\"school_sub_district\":null,\"village_district\":null,\"fire_district\":null,\"precinct_id\":null}]} \ No newline at end of file diff --git a/spec/nation_builder_spec.rb b/spec/nation_builder_spec.rb index b47f930..9498937 100644 --- a/spec/nation_builder_spec.rb +++ b/spec/nation_builder_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') +require 'spec_helper' describe NationBuilder do before(:each) do diff --git a/spec/people_spec.rb b/spec/people_spec.rb index a0be0ca..51ca655 100644 --- a/spec/people_spec.rb +++ b/spec/people_spec.rb @@ -1,36 +1,85 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') - -describe 'People' do - describe 'list' do - - let(:body) { fixture('people_get') } - let(:request_path) { '/api/v1/people' } - let(:status) { 200 } - let(:client) { NationBuilder::Client.new(hostname: 'controlshifttest.nationbuilder.com', client_id: 'be4e96f9c1c664b1903764cc425f522e4adbc3f26f0e6b52603f7e68e1ed025e', client_secret: '3dbafb54fb670fb6b2323a617d3cafbee7a83943cf5340347dcbe40fe13d93f7', username: 'nathan@controlshiftlabs.com', password: '9WRv9pZRwaUJuv') } - before(:each) do - stub_get(request_path).to_return(:body => body, :status => status, - :headers => { content_type: "application/json; charset=utf-8"}) +require 'spec_helper' + +describe NationBuilder::People do + subject(:people) { nb_client.people } + + let(:person) { { 'person' => { 'id' => 17, 'email' => 'george@example.com' } } } + + it 'sends the token as a bearer header' do + stub = stub_nb(:get, 'people', body: { 'results' => [] }) + .with(headers: { 'Authorization' => 'Bearer secret-token' }) + + people.list + + expect(stub).to have_been_requested + end + + describe '#list' do + it 'returns an empty result set if the nation is empty' do + stub_nb(:get, 'people', body: { 'results' => [] }) + + expect(people.list['results']).to be_empty + end + + it 'returns the people in the nation' do + stub_nb(:get, 'people', body: { 'results' => [person['person']] }) + + expect(people.list['results']).to eq([person['person']]) + end + end + + describe '#match' do + it 'returns the matching person' do + stub_request(:get, "#{NationBuilderHelpers::BASE_URL}/people/match?email=george@example.com") + .to_return(status: 200, body: JSON.generate(person), headers: { 'Content-Type' => 'application/json' }) + + expect(people.match('email' => 'george@example.com')).to eq(person) + end + + it 'returns nil when there is no match' do + stub_request(:get, "#{NationBuilderHelpers::BASE_URL}/people/match?email=nobody@example.com") + .to_return(status: 400, body: '{"code":"no_matches","message":"No people matched the given criteria."}', + headers: { 'Content-Type' => 'application/json' }) + + expect(people.match('email' => 'nobody@example.com')).to be_nil + end + + it 'raises OAuth2::Error for other failures' do + stub_request(:get, "#{NationBuilderHelpers::BASE_URL}/people/match?email=x@example.com") + .to_return(status: 500, body: '{"code":"server_error"}', headers: { 'Content-Type' => 'application/json' }) + + expect { people.match('email' => 'x@example.com') }.to raise_error(OAuth2::Error) + end + end + + describe '#add' do + it 'puts the person to people/add' do + stub_nb(:put, 'people/add', body: person).with(body: person) + + expect(people.add(person)).to eq(person) end - describe 'on success' do - describe 'empty list' do - let(:body) { fixture('people_list_empty') } - it 'should return an empty result set if the nation is empty' do - pending "figure out how to stub oauth2" - client.people.list.should be_a(Hash) - client.people.list['results'].should be_empty - end - end - - describe 'succesful response' do - let(:body) { fixture('people_list_success') } - it 'should return a list of people in the nation' do - pending "figure out how to stub oauth2" - - client.people.list.should be_a(Hash) - client.people.list.should_not be_empty - end - end + it 'raises ValidationError when validation fails' do + stub_nb(:put, 'people/add', status: 400, + body: { 'code' => 'validation_failed', 'message' => 'Validation Failed.', + 'validation_errors' => ['email is invalid'] }) + + expect { people.add(person) }.to raise_error(NationBuilder::Exceptions::ValidationError) { |e| + expect(e.errors).to eq(['email is invalid']) + } end end -end \ No newline at end of file + + it '#update puts the person' do + stub_nb(:put, 'people/17', body: person).with(body: { 'person' => { 'email_opt_in' => false } }) + + expect(people.update(17, 'person' => { 'email_opt_in' => false })).to eq(person) + end + + it '#add_tagging puts the tag' do + stub_nb(:put, 'people/17/taggings', body: { 'tagging' => { 'tag' => 'volunteer' } }) + .with(body: { 'tagging' => { 'tag' => 'volunteer' } }) + + expect(people.add_tagging(17, 'volunteer')).to eq('tagging' => { 'tag' => 'volunteer' }) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a743ccb..2a684a7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,46 +1,21 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require 'rspec' require 'nation_builder' require 'webmock/rspec' require 'json' -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +module NationBuilderHelpers + # The client joins base_uri and paths with a double slash; NationBuilder accepts it + BASE_URL = 'https://test.nationbuilder.com//api/v1' - -RSpec.configure do |config| - config.include WebMock::API - - config.before(:each) do - WebMock.reset! - WebMock.allow_net_connect! - end - config.after(:each) do - WebMock.reset! + def nb_client + NationBuilder.new(hostname: 'test.nationbuilder.com', token: 'secret-token') end -end - -# Allow real connections - -def stub_get(path) - stub_nation_builder_request(:get, path) -end - -def stub_post(path) - stub_nation_builder_request(:post, path) -end - -def stub_nation_builder_request(method, path) - stub_request(method, "https://test.com" + path) -end - -def fixture_path - File.expand_path("../fixtures", __FILE__) + def stub_nb(method, path, status: 200, body: {}) + stub_request(method, "#{BASE_URL}/#{path}") + .to_return(status: status, body: JSON.generate(body), headers: { 'Content-Type' => 'application/json' }) + end end -def fixture(file) - File.new(File.join(fixture_path, '/', file)) +RSpec.configure do |config| + config.include NationBuilderHelpers end From 68807371f76e48a41efbf9acf55ebccaf622bcab Mon Sep 17 00:00:00 2001 From: Nathan Woodhull Date: Thu, 12 Nov 2026 18:51:31 -0500 Subject: [PATCH 4/4] Restore spec fixtures as valid JSON The fixtures were escaped strings and a Ruby hash literal, so they never parsed, and the pending specs that referenced them never reached them. Restore them as JSON, load them in the People#list specs, and use not_found for an update 404 spec. Co-Authored-By: Claude Opus 5.5 --- spec/fixtures/not_found.json | 4 + spec/fixtures/people_list_empty.json | 7 + spec/fixtures/people_list_success.json | 219 +++++++++++++++++++++++++ spec/people_spec.rb | 26 ++- spec/spec_helper.rb | 8 +- 5 files changed, 257 insertions(+), 7 deletions(-) create mode 100644 spec/fixtures/not_found.json create mode 100644 spec/fixtures/people_list_empty.json create mode 100644 spec/fixtures/people_list_success.json diff --git a/spec/fixtures/not_found.json b/spec/fixtures/not_found.json new file mode 100644 index 0000000..198e6c0 --- /dev/null +++ b/spec/fixtures/not_found.json @@ -0,0 +1,4 @@ +{ + "code": "not_found", + "message": "Record not found" +} diff --git a/spec/fixtures/people_list_empty.json b/spec/fixtures/people_list_empty.json new file mode 100644 index 0000000..4431277 --- /dev/null +++ b/spec/fixtures/people_list_empty.json @@ -0,0 +1,7 @@ +{ + "page": 20, + "total_pages": 1, + "per_page": 10, + "total": 4, + "results": [] +} diff --git a/spec/fixtures/people_list_success.json b/spec/fixtures/people_list_success.json new file mode 100644 index 0000000..69fb440 --- /dev/null +++ b/spec/fixtures/people_list_success.json @@ -0,0 +1,219 @@ +{ + "page": 1, + "total_pages": 1, + "per_page": 10, + "total": 4, + "results": [ + { + "id": 4, + "external_id": null, + "support_level": null, + "first_name": "John", + "last_name": "Doe", + "email": "johndoe@gmail.com", + "phone": null, + "mobile": null, + "birthdate": null, + "sex": null, + "note": null, + "primary_address": null, + "tags": [], + "recruiter_id": null, + "created_at": "2013-09-17T15:23:44-07:00", + "updated_at": "2013-09-17T15:23:44-07:00", + "mobile_opt_in": true, + "email_opt_in": true, + "is_volunteer": false, + "is_twitter_follower": false, + "has_facebook": false, + "state_file_id": null, + "nbec_guid": null, + "van_id": null, + "dw_id": null, + "ngp_id": null, + "pf_strat_id": null, + "county_file_id": null, + "twitter_name": null, + "twitter_id": null, + "salesforce_id": null, + "civicrm_id": null, + "linkedin_id": null, + "employer": null, + "occupation": null, + "supranational_district": null, + "federal_district": null, + "labour_region": null, + "state_upper_district": null, + "state_lower_district": null, + "city_district": null, + "county_district": null, + "judicial_district": null, + "school_district": null, + "school_sub_district": null, + "village_district": null, + "fire_district": null, + "precinct_id": null + }, + { + "id": 3, + "external_id": null, + "support_level": null, + "first_name": "Nathan", + "last_name": "Woodhull", + "email": "woodhull@gmail.com", + "phone": null, + "mobile": null, + "birthdate": null, + "sex": null, + "note": null, + "primary_address": { + "address1": null, + "address2": null, + "city": "Brooklyn", + "state": "NY", + "country_code": "US", + "zip": null, + "lat": "40.6528762", + "lng": "-73.959494" + }, + "tags": [], + "recruiter_id": null, + "created_at": "2013-09-16T07:39:14-07:00", + "updated_at": "2013-09-16T07:40:34-07:00", + "mobile_opt_in": true, + "email_opt_in": true, + "is_volunteer": false, + "is_twitter_follower": false, + "has_facebook": true, + "state_file_id": null, + "nbec_guid": null, + "van_id": null, + "dw_id": null, + "ngp_id": null, + "pf_strat_id": null, + "county_file_id": null, + "twitter_name": null, + "twitter_id": null, + "salesforce_id": null, + "civicrm_id": null, + "linkedin_id": null, + "employer": null, + "occupation": null, + "supranational_district": null, + "federal_district": null, + "labour_region": null, + "state_upper_district": null, + "state_lower_district": null, + "city_district": null, + "county_district": null, + "judicial_district": null, + "school_district": null, + "school_sub_district": null, + "village_district": null, + "fire_district": null, + "precinct_id": null + }, + { + "id": 2, + "external_id": null, + "support_level": null, + "first_name": "Nathan", + "last_name": "Woodhull", + "email": "nathan@controlshiftlabs.com", + "phone": "518-207-6768", + "mobile": null, + "birthdate": null, + "sex": null, + "note": null, + "primary_address": null, + "tags": [ + "customer - signed in" + ], + "recruiter_id": null, + "created_at": "2012-09-20T07:03:26-07:00", + "updated_at": "2013-09-16T14:11:28-07:00", + "mobile_opt_in": true, + "email_opt_in": true, + "is_volunteer": false, + "is_twitter_follower": false, + "has_facebook": false, + "state_file_id": null, + "nbec_guid": null, + "van_id": null, + "dw_id": null, + "ngp_id": null, + "pf_strat_id": null, + "county_file_id": null, + "twitter_name": null, + "twitter_id": null, + "salesforce_id": null, + "civicrm_id": null, + "linkedin_id": null, + "employer": null, + "occupation": null, + "supranational_district": null, + "federal_district": null, + "labour_region": null, + "state_upper_district": null, + "state_lower_district": null, + "city_district": null, + "county_district": null, + "judicial_district": null, + "school_district": null, + "school_sub_district": null, + "village_district": null, + "fire_district": null, + "precinct_id": null + }, + { + "id": 1, + "external_id": null, + "support_level": null, + "first_name": "NationBuilder", + "last_name": "Support", + "email": "help@nationbuilder.com", + "phone": null, + "mobile": null, + "birthdate": null, + "sex": null, + "note": null, + "primary_address": null, + "tags": [], + "recruiter_id": null, + "created_at": "2012-09-20T07:03:26-07:00", + "updated_at": "2013-09-16T11:18:53-07:00", + "mobile_opt_in": true, + "email_opt_in": false, + "is_volunteer": false, + "is_twitter_follower": false, + "has_facebook": false, + "state_file_id": null, + "nbec_guid": null, + "van_id": null, + "dw_id": null, + "ngp_id": null, + "pf_strat_id": null, + "county_file_id": null, + "twitter_name": null, + "twitter_id": null, + "salesforce_id": null, + "civicrm_id": null, + "linkedin_id": null, + "employer": null, + "occupation": null, + "supranational_district": null, + "federal_district": null, + "labour_region": null, + "state_upper_district": null, + "state_lower_district": null, + "city_district": null, + "county_district": null, + "judicial_district": null, + "school_district": null, + "school_sub_district": null, + "village_district": null, + "fire_district": null, + "precinct_id": null + } + ] +} diff --git a/spec/people_spec.rb b/spec/people_spec.rb index 51ca655..f5c6eef 100644 --- a/spec/people_spec.rb +++ b/spec/people_spec.rb @@ -16,15 +16,18 @@ describe '#list' do it 'returns an empty result set if the nation is empty' do - stub_nb(:get, 'people', body: { 'results' => [] }) + stub_nb(:get, 'people', body: fixture('people_list_empty')) expect(people.list['results']).to be_empty end it 'returns the people in the nation' do - stub_nb(:get, 'people', body: { 'results' => [person['person']] }) + stub_nb(:get, 'people', body: fixture('people_list_success')) - expect(people.list['results']).to eq([person['person']]) + list = people.list + + expect(list['total']).to eq(4) + expect(list['results'].map { |p| p['email'] }).to include('johndoe@gmail.com') end end @@ -70,10 +73,21 @@ end end - it '#update puts the person' do - stub_nb(:put, 'people/17', body: person).with(body: { 'person' => { 'email_opt_in' => false } }) + describe '#update' do + it 'puts the person' do + stub_nb(:put, 'people/17', body: person).with(body: { 'person' => { 'email_opt_in' => false } }) + + expect(people.update(17, 'person' => { 'email_opt_in' => false })).to eq(person) + end + + it 'raises OAuth2::Error with a 404 response when the person does not exist' do + stub_nb(:put, 'people/99', status: 404, body: fixture('not_found')) - expect(people.update(17, 'person' => { 'email_opt_in' => false })).to eq(person) + expect { people.update(99, 'person' => { 'email_opt_in' => false }) }.to raise_error(OAuth2::Error) { |e| + expect(e.response.status).to eq(404) + expect(e.response.parsed['code']).to eq('not_found') + } + end end it '#add_tagging puts the tag' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2a684a7..60fc801 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,9 +10,15 @@ def nb_client NationBuilder.new(hostname: 'test.nationbuilder.com', token: 'secret-token') end + # body may be a Hash, or a String of raw JSON such as a fixture def stub_nb(method, path, status: 200, body: {}) + body = JSON.generate(body) unless body.is_a?(String) stub_request(method, "#{BASE_URL}/#{path}") - .to_return(status: status, body: JSON.generate(body), headers: { 'Content-Type' => 'application/json' }) + .to_return(status: status, body: body, headers: { 'Content-Type' => 'application/json' }) + end + + def fixture(name) + File.read(File.expand_path("fixtures/#{name}.json", __dir__)) end end