solidus_identifiers 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +21 -0
- data/.gitlab/ci.yml +63 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +396 -0
- data/Rakefile +6 -0
- data/app/decorators/solidus_identifiers/spree/api/api_helpers_decorator.rb +20 -0
- data/app/decorators/solidus_identifiers/spree/permission_sets/user_management_decorator.rb +15 -0
- data/app/decorators/solidus_identifiers/spree/permitted_attributes_decorator.rb +16 -0
- data/app/decorators/solidus_identifiers/spree/user_decorator.rb +11 -0
- data/app/models/spree/identifier.rb +19 -0
- data/app/models/spree/identifier_key.rb +17 -0
- data/app/views/spree/api/identifier_keys/_identifier_key.json.jbuilder +5 -0
- data/app/views/spree/api/identifier_keys/index.json.jbuilder +6 -0
- data/app/views/spree/api/identifier_keys/show.json.jbuilder +3 -0
- data/app/views/spree/api/identifiers/_identifier.json.jbuilder +14 -0
- data/app/views/spree/api/identifiers/index.json.jbuilder +6 -0
- data/app/views/spree/api/identifiers/show.json.jbuilder +3 -0
- data/app/views/spree/api/users/_user.json.jbuilder +31 -0
- data/bin/console +17 -0
- data/bin/r +15 -0
- data/bin/rake +7 -0
- data/bin/sandbox +84 -0
- data/bin/sandbox_rails +18 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20200603191551_create_spree_identifier_keys.rb +10 -0
- data/db/migrate/20200603191555_create_spree_identifiers.rb +18 -0
- data/db/migrate/20200603203105_add_unique_index_to_spree_identifier_keys.rb +7 -0
- data/lib/controllers/api/spree/api/identifier_keys_controller.rb +15 -0
- data/lib/controllers/api/spree/api/identifiers_controller.rb +15 -0
- data/lib/generators/solidus_identifiers/install/install_generator.rb +26 -0
- data/lib/solidus_identifiers.rb +7 -0
- data/lib/solidus_identifiers/engine.rb +19 -0
- data/lib/solidus_identifiers/factories.rb +14 -0
- data/lib/solidus_identifiers/version.rb +5 -0
- data/solidus_identifiers.gemspec +38 -0
- data/spec/controllers/spree/api/identifier_keys_controller_spec.rb +151 -0
- data/spec/controllers/spree/api/identifiers_controller_spec.rb +161 -0
- data/spec/models/spree/identifier_key_spec.rb +21 -0
- data/spec/models/spree/identifier_spec.rb +33 -0
- data/spec/spec_helper.rb +32 -0
- metadata +174 -0
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module SolidusIdentifiers
         | 
| 4 | 
            +
              module Generators
         | 
| 5 | 
            +
                class InstallGenerator < Rails::Generators::Base
         | 
| 6 | 
            +
                  class_option :auto_run_migrations, type: :boolean, default: false
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def add_javascripts; end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def add_stylesheets; end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def add_migrations
         | 
| 13 | 
            +
                    run 'bin/rails railties:install:migrations FROM=solidus_identifiers'
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def run_migrations
         | 
| 17 | 
            +
                    run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength
         | 
| 18 | 
            +
                    if run_migrations
         | 
| 19 | 
            +
                      run 'bin/rails db:migrate'
         | 
| 20 | 
            +
                    else
         | 
| 21 | 
            +
                      puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spree/core'
         | 
| 4 | 
            +
            require 'solidus_identifiers'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module SolidusIdentifiers
         | 
| 7 | 
            +
              class Engine < Rails::Engine
         | 
| 8 | 
            +
                include SolidusSupport::EngineExtensions
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                isolate_namespace ::Spree
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                engine_name 'solidus_identifiers'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                # use rspec for tests
         | 
| 15 | 
            +
                config.generators do |g|
         | 
| 16 | 
            +
                  g.test_framework :rspec
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            FactoryBot.define do
         | 
| 4 | 
            +
              factory :identifier_key, class: 'Spree::IdentifierKey' do
         | 
| 5 | 
            +
                sequence(:name) { |n| "key_#{n}" }
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              factory :identifier, class: 'Spree::Identifier' do
         | 
| 9 | 
            +
                sequence(:value) { |n| "extension-id-#{n}" }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                association :key, factory: :identifier_key
         | 
| 12 | 
            +
                association :attachable, factory: :user
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative 'lib/solidus_identifiers/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name = 'solidus_identifiers'
         | 
| 7 | 
            +
              spec.version = SolidusIdentifiers::VERSION
         | 
| 8 | 
            +
              spec.authors = ['Taylor Scott']
         | 
| 9 | 
            +
              spec.email = 't.skukx@gmail.com'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              spec.summary = 'Map 3rd party services to a spree user'
         | 
| 12 | 
            +
              spec.description = 'Map 3rd party services to a spree user.' \
         | 
| 13 | 
            +
                                 'These can include facebook, twitch, google, etc;'
         | 
| 14 | 
            +
              spec.homepage = 'https://gitlab.com/deseretbook/packages/solidus_identifiers'
         | 
| 15 | 
            +
              spec.license = 'BSD-3-Clause'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              spec.metadata['homepage_uri'] = spec.homepage
         | 
| 18 | 
            +
              spec.metadata['source_code_uri'] = 'https://gitlab.com/deseretbook/packages/solidus_identifiers'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              # Specify which files should be added to the gem when it is released.
         | 
| 23 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 24 | 
            +
              files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              spec.files = files.grep_v(%r{^(test|spec|features)/})
         | 
| 27 | 
            +
              spec.test_files = files.grep(%r{^(test|spec|features)/})
         | 
| 28 | 
            +
              spec.bindir = "exe"
         | 
| 29 | 
            +
              spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 30 | 
            +
              spec.require_paths = ["lib"]
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
         | 
| 33 | 
            +
              spec.add_dependency 'solidus_support', '> 0.4'
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              spec.add_development_dependency 'byebug'
         | 
| 36 | 
            +
              spec.add_development_dependency 'rails-controller-testing'
         | 
| 37 | 
            +
              spec.add_development_dependency 'solidus_dev_support'
         | 
| 38 | 
            +
            end
         | 
| @@ -0,0 +1,151 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec.describe Spree::Api::IdentifierKeysController, type: :request do
         | 
| 6 | 
            +
              subject { response }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              # Setup
         | 
| 9 | 
            +
              let(:user) { create(:user) }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              let(:headers) do
         | 
| 12 | 
            +
                { 'ACCEPT': 'application/json' }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              custom_authorization! do |_|
         | 
| 16 | 
            +
                can [:manage], ::Spree::IdentifierKey
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              before do
         | 
| 20 | 
            +
                allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { user }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              # End Setup
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              # Spree::Api::IdentifierKeysController#index
         | 
| 25 | 
            +
              describe 'GET /api/identifier_keys' do
         | 
| 26 | 
            +
                let(:path) { '/api/identifier_keys' }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                before do
         | 
| 29 | 
            +
                  FactoryBot.create_list(:identifier_key, 5)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  get path, headers: headers
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                it 'must render correct templates' do
         | 
| 37 | 
            +
                  expect(response).to render_template(:index)
         | 
| 38 | 
            +
                  expect(response).to render_template('identifier_keys/_identifier_key')
         | 
| 39 | 
            +
                  expect(response).to render_template('spree/api/shared/_pagination')
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                it 'must respond with correct content type' do
         | 
| 43 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              # Spree::Api::IdentifierKeysController#show
         | 
| 48 | 
            +
              describe 'GET /api/identifier_keys/:id' do
         | 
| 49 | 
            +
                let(:identifier_key) { create(:identifier_key) }
         | 
| 50 | 
            +
                let(:path) { "/api/identifier_keys/#{identifier_key.to_param}" }
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                before do
         | 
| 53 | 
            +
                  get path, headers: headers
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it 'must render correct templates' do
         | 
| 59 | 
            +
                  expect(response).to render_template(:show)
         | 
| 60 | 
            +
                  expect(response).to render_template('identifier_keys/_identifier_key')
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                it 'must respond with correct content type' do
         | 
| 64 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              # Spree::Api::IdentifierKeysController#new
         | 
| 69 | 
            +
              describe 'GET /api/identifier_keys/new' do
         | 
| 70 | 
            +
                let(:path) { '/api/identifier_keys/new' }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                before do
         | 
| 73 | 
            +
                  get path, headers: headers
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                it 'must render correct templates' do
         | 
| 79 | 
            +
                  expect(response).to render_template(nil)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                it 'must respond with correct content type' do
         | 
| 83 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              # Spree::Api::IdentifierKeysController#create
         | 
| 88 | 
            +
              describe 'POST /api/identifier_keys' do
         | 
| 89 | 
            +
                let(:path) { '/api/identifier_keys' }
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                before do
         | 
| 92 | 
            +
                  post path, headers: headers, params: {
         | 
| 93 | 
            +
                    identifier_key: {
         | 
| 94 | 
            +
                      name: 'test'
         | 
| 95 | 
            +
                    }
         | 
| 96 | 
            +
                  }
         | 
| 97 | 
            +
                end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                it { is_expected.to have_http_status(:created) }
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                it 'must render correct templates' do
         | 
| 102 | 
            +
                  expect(response).to render_template(:show)
         | 
| 103 | 
            +
                  expect(response).to render_template('identifier_keys/_identifier_key')
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                it 'must respond with correct content type' do
         | 
| 107 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 108 | 
            +
                end
         | 
| 109 | 
            +
              end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
              # Spree::Api::IdentifierKeysController#update
         | 
| 112 | 
            +
              describe 'PUT /api/identifier_keys/:id' do
         | 
| 113 | 
            +
                let(:identifier_key) { create(:identifier_key) }
         | 
| 114 | 
            +
                let(:path) { "/api/identifier_keys/#{identifier_key.to_param}" }
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                before do
         | 
| 117 | 
            +
                  put path, headers: headers, params: {
         | 
| 118 | 
            +
                    identifier_key: {
         | 
| 119 | 
            +
                      name: 'test'
         | 
| 120 | 
            +
                    }
         | 
| 121 | 
            +
                  }
         | 
| 122 | 
            +
                end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                it 'must render correct templates' do
         | 
| 127 | 
            +
                  expect(response).to render_template(:show)
         | 
| 128 | 
            +
                  expect(response).to render_template('identifier_keys/_identifier_key')
         | 
| 129 | 
            +
                end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                it 'must respond with correct content type' do
         | 
| 132 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
              # Spree::Api::IdentifierKeysController#delete
         | 
| 137 | 
            +
              describe 'DELETE /api/identifier_keys' do
         | 
| 138 | 
            +
                let(:identifier_key) { create(:identifier_key) }
         | 
| 139 | 
            +
                let(:path) { "/api/identifier_keys/#{identifier_key.to_param}" }
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                before do
         | 
| 142 | 
            +
                  delete path, headers: headers
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                it { is_expected.to have_http_status(:no_content) }
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                it 'renders correct templates' do
         | 
| 148 | 
            +
                  expect(response).to render_template(nil)
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
              end
         | 
| 151 | 
            +
            end
         | 
| @@ -0,0 +1,161 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec.describe Spree::Api::IdentifiersController, type: :request do
         | 
| 6 | 
            +
              subject { response }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              # Setup
         | 
| 9 | 
            +
              let(:user) { create(:user) }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              let(:headers) do
         | 
| 12 | 
            +
                { 'ACCEPT': 'application/json' }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              custom_authorization! do |_|
         | 
| 16 | 
            +
                can [:manage], ::Spree::Identifier
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              before do
         | 
| 20 | 
            +
                allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { user }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              # End Setup
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              # Spree::Api::IdentifiersController#index
         | 
| 25 | 
            +
              describe 'GET /api/identifiers' do
         | 
| 26 | 
            +
                let(:path) { '/api/identifiers' }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                before do
         | 
| 29 | 
            +
                  FactoryBot.create_list(:identifier, 5)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  get path, headers: headers
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                it 'must render correct templates' do
         | 
| 37 | 
            +
                  expect(response).to render_template(:index)
         | 
| 38 | 
            +
                  expect(response).to render_template('identifiers/_identifier')
         | 
| 39 | 
            +
                  expect(response).to render_template('spree/api/shared/_pagination')
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                it 'must respond with correct content type' do
         | 
| 43 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              # Spree::Api::IdentifiersController#show
         | 
| 48 | 
            +
              describe 'GET /api/identifiers/:id' do
         | 
| 49 | 
            +
                let(:identifier) { create(:identifier) }
         | 
| 50 | 
            +
                let(:path) { "/api/identifiers/#{identifier.to_param}" }
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                before do
         | 
| 53 | 
            +
                  get path, headers: headers
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it 'must render correct templates' do
         | 
| 59 | 
            +
                  expect(response).to render_template(:show)
         | 
| 60 | 
            +
                  expect(response).to render_template('identifiers/_identifier')
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                it 'must respond with correct content type' do
         | 
| 64 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              # Spree::Api::IdentifiersController#new
         | 
| 69 | 
            +
              describe 'GET /api/identifiers/new' do
         | 
| 70 | 
            +
                let(:path) { '/api/identifiers/new' }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                before do
         | 
| 73 | 
            +
                  get path, headers: headers
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                it 'must render correct templates' do
         | 
| 79 | 
            +
                  expect(response).to render_template(nil)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                it 'must respond with correct content type' do
         | 
| 83 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              # Spree::Api::IdentifiersController#create
         | 
| 88 | 
            +
              describe 'POST /api/identifiers' do
         | 
| 89 | 
            +
                let(:path) { '/api/identifiers' }
         | 
| 90 | 
            +
                let(:identifier_key) { FactoryBot.create(:identifier_key) }
         | 
| 91 | 
            +
                let(:attachable) { FactoryBot.create(:user) }
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                before do
         | 
| 94 | 
            +
                  post path, headers: headers, params: {
         | 
| 95 | 
            +
                    identifier: {
         | 
| 96 | 
            +
                      value: 'test',
         | 
| 97 | 
            +
                      key_id: identifier_key.id,
         | 
| 98 | 
            +
                      attachable_id: attachable.id,
         | 
| 99 | 
            +
                      attachable_type: attachable.class.to_s
         | 
| 100 | 
            +
                    }
         | 
| 101 | 
            +
                  }
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                it { is_expected.to have_http_status(:created) }
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                it 'must render correct templates' do
         | 
| 107 | 
            +
                  expect(response).to render_template(:show)
         | 
| 108 | 
            +
                  expect(response).to render_template('identifiers/_identifier')
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                it 'must respond with correct content type' do
         | 
| 112 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
              end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              # Spree::Api::IdentifiersController#update
         | 
| 117 | 
            +
              describe 'PUT /api/identifiers/:id' do
         | 
| 118 | 
            +
                let(:identifier) { create(:identifier) }
         | 
| 119 | 
            +
                let(:path) { "/api/identifiers/#{identifier.to_param}" }
         | 
| 120 | 
            +
                let(:identifier_key) { FactoryBot.create(:identifier_key) }
         | 
| 121 | 
            +
                let(:attachable) { FactoryBot.create(:user) }
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                before do
         | 
| 124 | 
            +
                  put path, headers: headers, params: {
         | 
| 125 | 
            +
                    identifier: {
         | 
| 126 | 
            +
                      value: 'test',
         | 
| 127 | 
            +
                      key_id: identifier_key.id,
         | 
| 128 | 
            +
                      attachable_id: attachable.id,
         | 
| 129 | 
            +
                      attachable_type: attachable.class.to_s
         | 
| 130 | 
            +
                    }
         | 
| 131 | 
            +
                  }
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                it { is_expected.to have_http_status(:ok) }
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                it 'must render correct templates' do
         | 
| 137 | 
            +
                  expect(response).to render_template(:show)
         | 
| 138 | 
            +
                  expect(response).to render_template('identifiers/_identifier')
         | 
| 139 | 
            +
                end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                it 'must respond with correct content type' do
         | 
| 142 | 
            +
                  expect(response.content_type).to include 'application/json'
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
              end
         | 
| 145 | 
            +
             | 
| 146 | 
            +
              # Spree::Api::IdentifiersController#delete
         | 
| 147 | 
            +
              describe 'DELETE /api/identifiers' do
         | 
| 148 | 
            +
                let(:identifier) { create(:identifier ) }
         | 
| 149 | 
            +
                let(:path) { "/api/identifiers/#{identifier.to_param}" }
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                before do
         | 
| 152 | 
            +
                  delete path, headers: headers
         | 
| 153 | 
            +
                end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                it { is_expected.to have_http_status(:no_content) }
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                it 'renders correct templates' do
         | 
| 158 | 
            +
                  expect(response).to render_template(nil)
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RSpec.describe Spree::IdentifierKey, type: :model do
         | 
| 6 | 
            +
              subject(:key) { instance }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              let(:instance) { FactoryBot.build(:identifier_key) }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              describe 'validations' do
         | 
| 11 | 
            +
                it { is_expected.to be_valid }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                it 'must be unique' do
         | 
| 14 | 
            +
                  name = 'my-key'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  described_class.create!(name: name)
         | 
| 17 | 
            +
                  expect { described_class.create!(name: name) }.
         | 
| 18 | 
            +
                    to raise_error ActiveRecord::RecordInvalid
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         |