acfs 1.6.0 → 1.7.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 +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +16 -19
- data/acfs.gemspec +2 -0
- data/lib/acfs/adapter/typhoeus.rb +6 -4
- data/lib/acfs/configuration.rb +13 -3
- data/lib/acfs/errors.rb +1 -1
- data/lib/acfs/global.rb +2 -2
- data/lib/acfs/location.rb +1 -1
- data/lib/acfs/operation.rb +1 -1
- data/lib/acfs/request/callbacks.rb +1 -1
- data/lib/acfs/request.rb +1 -1
- data/lib/acfs/resource/attributes/uuid.rb +1 -1
- data/lib/acfs/resource/locatable.rb +2 -2
- data/lib/acfs/resource/query_methods.rb +2 -2
- data/lib/acfs/runner.rb +15 -15
- data/lib/acfs/stub.rb +34 -29
- data/lib/acfs/version.rb +2 -2
- data/spec/acfs/adapter/typhoeus_spec.rb +1 -1
- data/spec/acfs/collection_spec.rb +66 -41
- data/spec/acfs/configuration_spec.rb +22 -12
- data/spec/acfs/global_spec.rb +9 -7
- data/spec/acfs/middleware/json_spec.rb +8 -8
- data/spec/acfs/middleware/{msgpack_spec.rb → message_pack_spec.rb} +6 -6
- data/spec/acfs/operation_spec.rb +3 -2
- data/spec/acfs/request/callbacks_spec.rb +19 -10
- data/spec/acfs/request_spec.rb +15 -19
- data/spec/acfs/resource/attributes/boolean_spec.rb +32 -32
- data/spec/acfs/resource/attributes/date_time_spec.rb +16 -8
- data/spec/acfs/resource/attributes/dict_spec.rb +15 -9
- data/spec/acfs/resource/attributes/float_spec.rb +20 -10
- data/spec/acfs/resource/attributes/integer_spec.rb +10 -5
- data/spec/acfs/resource/attributes/list_spec.rb +13 -8
- data/spec/acfs/resource/attributes/uuid_spec.rb +12 -6
- data/spec/acfs/resource/attributes_spec.rb +33 -32
- data/spec/acfs/resource/dirty_spec.rb +6 -3
- data/spec/acfs/resource/initialization_spec.rb +4 -5
- data/spec/acfs/resource/loadable_spec.rb +3 -1
- data/spec/acfs/resource/locatable_spec.rb +24 -18
- data/spec/acfs/resource/{persistance_spec.rb → persistence_spec.rb} +114 -82
- data/spec/acfs/resource/query_methods_spec.rb +143 -110
- data/spec/acfs/resource/validation_spec.rb +34 -27
- data/spec/acfs/response/formats_spec.rb +8 -8
- data/spec/acfs/response/status_spec.rb +16 -9
- data/spec/acfs/runner_spec.rb +10 -8
- data/spec/acfs/service/middleware_spec.rb +3 -3
- data/spec/acfs/service_spec.rb +5 -4
- data/spec/acfs/singleton_resource_spec.rb +2 -1
- data/spec/acfs/stub_spec.rb +57 -53
- data/spec/acfs_spec.rb +111 -93
- data/spec/spec_helper.rb +1 -1
- data/spec/support/response.rb +2 -2
- data/spec/support/service.rb +1 -1
- data/spec/support/shared/find_callbacks.rb +14 -10
- metadata +9 -8
| @@ -13,32 +13,33 @@ describe Acfs::Resource::QueryMethods do | |
| 13 13 | 
             
                        .to_return response id: 1, name: 'Anon', age: 12, born_at: 'Berlin'
         | 
| 14 14 | 
             
                      stub_request(:get, 'http://users.example.org/users/2')
         | 
| 15 15 | 
             
                        .to_return response id: 2, type: 'Customer',
         | 
| 16 | 
            -
             | 
| 16 | 
            +
                          name: 'Clare Customer', age: 24
         | 
| 17 17 | 
             
                    end
         | 
| 18 18 |  | 
| 19 19 | 
             
                    let(:action) { ->(cb = nil) { model.find(1, &cb) } }
         | 
| 20 | 
            +
             | 
| 20 21 | 
             
                    it_behaves_like 'a query method with multi-callback support'
         | 
| 21 22 |  | 
| 22 | 
            -
                    it ' | 
| 23 | 
            +
                    it 'loads a single remote resource' do
         | 
| 23 24 | 
             
                      user = action.call
         | 
| 24 25 | 
             
                      Acfs.run
         | 
| 25 26 |  | 
| 26 27 | 
             
                      expect(user.attributes).to eq id: 1, name: 'Anon',
         | 
| 27 | 
            -
             | 
| 28 | 
            +
                        age: 12, born_at: 'Berlin'
         | 
| 28 29 | 
             
                    end
         | 
| 29 30 |  | 
| 30 31 | 
             
                    context 'with resource type inheritance' do
         | 
| 31 | 
            -
                       | 
| 32 | 
            -
             | 
| 32 | 
            +
                      subject!(:user) { MyUser.find 2 }
         | 
| 33 | 
            +
             | 
| 33 34 | 
             
                      before { Acfs.run }
         | 
| 34 35 |  | 
| 35 | 
            -
                      it ' | 
| 36 | 
            -
                        expect( | 
| 36 | 
            +
                      it 'respects resource type inheritance' do
         | 
| 37 | 
            +
                        expect(user).to be_a Customer
         | 
| 37 38 | 
             
                      end
         | 
| 38 39 |  | 
| 39 | 
            -
                      it ' | 
| 40 | 
            -
                        expect( | 
| 41 | 
            -
                        expect( | 
| 40 | 
            +
                      it 'implements ActiveModel class interface' do
         | 
| 41 | 
            +
                        expect(user.class).to be_a ActiveModel::Naming
         | 
| 42 | 
            +
                        expect(user.class).to be_a ActiveModel::Translation
         | 
| 42 43 | 
             
                      end
         | 
| 43 44 | 
             
                    end
         | 
| 44 45 | 
             
                  end
         | 
| @@ -49,12 +50,12 @@ describe Acfs::Resource::QueryMethods do | |
| 49 50 | 
             
                        .to_return response({error: 'not found'}, {status: 404})
         | 
| 50 51 | 
             
                    end
         | 
| 51 52 |  | 
| 52 | 
            -
                    it ' | 
| 53 | 
            -
                       | 
| 53 | 
            +
                    it 'raises a NotFound error' do
         | 
| 54 | 
            +
                      user = model.find 1
         | 
| 54 55 |  | 
| 55 56 | 
             
                      expect { Acfs.run }.to raise_error(Acfs::ResourceNotFound)
         | 
| 56 57 |  | 
| 57 | 
            -
                      expect( | 
| 58 | 
            +
                      expect(user).not_to be_loaded
         | 
| 58 59 | 
             
                    end
         | 
| 59 60 | 
             
                  end
         | 
| 60 61 |  | 
| @@ -64,12 +65,12 @@ describe Acfs::Resource::QueryMethods do | |
| 64 65 | 
             
                        .to_return response(nil, status: 500)
         | 
| 65 66 | 
             
                    end
         | 
| 66 67 |  | 
| 67 | 
            -
                    it ' | 
| 68 | 
            -
                       | 
| 68 | 
            +
                    it 'raises a response error' do
         | 
| 69 | 
            +
                      user = model.find 1
         | 
| 69 70 |  | 
| 70 71 | 
             
                      expect { Acfs.run }.to raise_error(Acfs::ErroneousResponse)
         | 
| 71 72 |  | 
| 72 | 
            -
                      expect( | 
| 73 | 
            +
                      expect(user).not_to be_loaded
         | 
| 73 74 | 
             
                    end
         | 
| 74 75 | 
             
                  end
         | 
| 75 76 | 
             
                end
         | 
| @@ -87,47 +88,49 @@ describe Acfs::Resource::QueryMethods do | |
| 87 88 | 
             
                  end
         | 
| 88 89 |  | 
| 89 90 | 
             
                  context 'with successful response' do
         | 
| 90 | 
            -
                    it ' | 
| 91 | 
            +
                    it 'loads a multiple remote resources' do
         | 
| 91 92 | 
             
                      users = model.find([1, 2])
         | 
| 92 93 | 
             
                      Acfs.run
         | 
| 93 94 |  | 
| 94 | 
            -
                      expect(users.size).to  | 
| 95 | 
            +
                      expect(users.size).to eq 2
         | 
| 95 96 | 
             
                      expect(users[0].attributes).to eq id: 1, name: 'Anon', age: 12
         | 
| 96 97 | 
             
                      expect(users[1].attributes).to eq id: 2, name: 'Johnny', age: 42
         | 
| 97 98 | 
             
                    end
         | 
| 98 99 |  | 
| 99 | 
            -
                    it ' | 
| 100 | 
            +
                    it 'invokes callback after all models are loaded' do
         | 
| 100 101 | 
             
                      block = proc {}
         | 
| 102 | 
            +
             | 
| 101 103 | 
             
                      expect(block).to receive(:call) do |users|
         | 
| 102 | 
            -
                        expect(users).to equal  | 
| 103 | 
            -
                        expect(users.size).to  | 
| 104 | 
            +
                        expect(users).to equal users
         | 
| 105 | 
            +
                        expect(users.size).to eq 2
         | 
| 104 106 | 
             
                        expect(users).to be_loaded
         | 
| 105 107 | 
             
                      end
         | 
| 106 108 |  | 
| 107 | 
            -
                       | 
| 109 | 
            +
                      users = model.find([1, 2], &block) # rubocop:disable Lint/UselessAssignment
         | 
| 108 110 | 
             
                      Acfs.run
         | 
| 109 111 | 
             
                    end
         | 
| 110 112 |  | 
| 111 | 
            -
                    it ' | 
| 113 | 
            +
                    it 'invokes multiple callback after all models are loaded' do
         | 
| 112 114 | 
             
                      proc1 = proc {}
         | 
| 113 115 | 
             
                      proc2 = proc {}
         | 
| 116 | 
            +
             | 
| 114 117 | 
             
                      expect(proc1).to receive(:call) do |users|
         | 
| 115 | 
            -
                        expect(users).to equal  | 
| 116 | 
            -
                        expect(users.size).to  | 
| 118 | 
            +
                        expect(users).to equal users
         | 
| 119 | 
            +
                        expect(users.size).to eq 2
         | 
| 117 120 | 
             
                        expect(users).to be_loaded
         | 
| 118 121 | 
             
                      end
         | 
| 119 122 | 
             
                      expect(proc2).to receive(:call) do |users|
         | 
| 120 | 
            -
                        expect(users).to equal  | 
| 121 | 
            -
                        expect(users.size).to  | 
| 123 | 
            +
                        expect(users).to equal users
         | 
| 124 | 
            +
                        expect(users.size).to eq 2
         | 
| 122 125 | 
             
                        expect(users).to be_loaded
         | 
| 123 126 | 
             
                      end
         | 
| 124 127 |  | 
| 125 | 
            -
                       | 
| 126 | 
            -
                      Acfs.add_callback( | 
| 128 | 
            +
                      users = model.find([1, 2], &proc1)
         | 
| 129 | 
            +
                      Acfs.add_callback(users, &proc2)
         | 
| 127 130 | 
             
                      Acfs.run
         | 
| 128 131 | 
             
                    end
         | 
| 129 132 |  | 
| 130 | 
            -
                    it ' | 
| 133 | 
            +
                    it 'respects resource type inheritance' do
         | 
| 131 134 | 
             
                      customers = MyUser.find [3, 4]
         | 
| 132 135 | 
             
                      Acfs.run
         | 
| 133 136 |  | 
| @@ -142,7 +145,7 @@ describe Acfs::Resource::QueryMethods do | |
| 142 145 | 
             
                        .to_return response({error: 'not found'}, {status: 404})
         | 
| 143 146 | 
             
                    end
         | 
| 144 147 |  | 
| 145 | 
            -
                    it ' | 
| 148 | 
            +
                    it 'raises resource not found error' do
         | 
| 146 149 | 
             
                      model.find [1, 2]
         | 
| 147 150 |  | 
| 148 151 | 
             
                      expect { Acfs.run }.to raise_error(Acfs::ResourceNotFound)
         | 
| @@ -155,52 +158,54 @@ describe Acfs::Resource::QueryMethods do | |
| 155 158 | 
             
                let(:computer) { Computer }
         | 
| 156 159 | 
             
                let(:pc) { PC }
         | 
| 157 160 | 
             
                let(:mac) { Mac }
         | 
| 161 | 
            +
             | 
| 158 162 | 
             
                before do
         | 
| 159 163 | 
             
                  stub_request(:get, 'http://computers.example.org/computers')
         | 
| 160 164 | 
             
                    .to_return response [
         | 
| 161 165 | 
             
                      {id: 1, type: 'PC'},
         | 
| 162 166 | 
             
                      {id: 2, type: 'Computer'},
         | 
| 163 | 
            -
                      {id: 3, type: 'Mac'}
         | 
| 167 | 
            +
                      {id: 3, type: 'Mac'},
         | 
| 164 168 | 
             
                    ]
         | 
| 165 169 | 
             
                end
         | 
| 166 170 |  | 
| 167 | 
            -
                it ' | 
| 171 | 
            +
                it 'invokes multiple callback after all models are loaded' do
         | 
| 168 172 | 
             
                  proc1 = proc {}
         | 
| 169 173 | 
             
                  proc2 = proc {}
         | 
| 174 | 
            +
             | 
| 170 175 | 
             
                  expect(proc1).to receive(:call) do |computers|
         | 
| 171 | 
            -
                    expect(computers).to equal  | 
| 172 | 
            -
                    expect(computers.size).to  | 
| 176 | 
            +
                    expect(computers).to equal computers
         | 
| 177 | 
            +
                    expect(computers.size).to eq 3
         | 
| 173 178 | 
             
                    expect(computers).to be_loaded
         | 
| 174 179 | 
             
                  end
         | 
| 175 180 | 
             
                  expect(proc2).to receive(:call) do |computers|
         | 
| 176 | 
            -
                    expect(computers).to equal  | 
| 177 | 
            -
                    expect(computers.size).to  | 
| 181 | 
            +
                    expect(computers).to equal computers
         | 
| 182 | 
            +
                    expect(computers.size).to eq 3
         | 
| 178 183 | 
             
                    expect(computers).to be_loaded
         | 
| 179 184 | 
             
                  end
         | 
| 180 185 |  | 
| 181 | 
            -
                   | 
| 182 | 
            -
                  Acfs.add_callback( | 
| 186 | 
            +
                  computers = computer.all(&proc1)
         | 
| 187 | 
            +
                  Acfs.add_callback(computers, &proc2)
         | 
| 183 188 | 
             
                  Acfs.run
         | 
| 184 189 | 
             
                end
         | 
| 185 190 |  | 
| 186 191 | 
             
                context 'with resource type inheritance' do
         | 
| 187 | 
            -
                  it ' | 
| 188 | 
            -
                     | 
| 192 | 
            +
                  it 'creates appropriate subclass resources' do
         | 
| 193 | 
            +
                    computers = Computer.all
         | 
| 189 194 |  | 
| 190 | 
            -
                    expect( | 
| 195 | 
            +
                    expect(computers).not_to be_loaded
         | 
| 191 196 |  | 
| 192 197 | 
             
                    Acfs.run
         | 
| 193 198 |  | 
| 194 | 
            -
                    expect( | 
| 195 | 
            -
                    expect( | 
| 196 | 
            -
                    expect( | 
| 197 | 
            -
                    expect( | 
| 198 | 
            -
                    expect( | 
| 199 | 
            +
                    expect(computers).to be_loaded
         | 
| 200 | 
            +
                    expect(computers).to have(3).items
         | 
| 201 | 
            +
                    expect(computers[0]).to be_a PC
         | 
| 202 | 
            +
                    expect(computers[1]).to be_a Computer
         | 
| 203 | 
            +
                    expect(computers[2]).to be_a Mac
         | 
| 199 204 | 
             
                  end
         | 
| 200 205 |  | 
| 201 206 | 
             
                  context 'with invalid type set' do
         | 
| 202 207 | 
             
                    shared_examples 'with invalid type' do
         | 
| 203 | 
            -
                      it ' | 
| 208 | 
            +
                      it 'raises error if type is no subclass' do
         | 
| 204 209 | 
             
                        Computer.all
         | 
| 205 210 | 
             
                        expect { Acfs.run }.to raise_error(Acfs::ResourceTypeError)
         | 
| 206 211 | 
             
                      end
         | 
| @@ -212,9 +217,10 @@ describe Acfs::Resource::QueryMethods do | |
| 212 217 | 
             
                          .to_return response [
         | 
| 213 218 | 
             
                            {id: 1, type: 'MyUser'},
         | 
| 214 219 | 
             
                            {id: 2, type: 'Computer'},
         | 
| 215 | 
            -
                            {id: 3, type: 'Mac'}
         | 
| 220 | 
            +
                            {id: 3, type: 'Mac'},
         | 
| 216 221 | 
             
                          ]
         | 
| 217 222 | 
             
                      end
         | 
| 223 | 
            +
             | 
| 218 224 | 
             
                      it_behaves_like 'with invalid type'
         | 
| 219 225 | 
             
                    end
         | 
| 220 226 |  | 
| @@ -224,9 +230,10 @@ describe Acfs::Resource::QueryMethods do | |
| 224 230 | 
             
                          .to_return response [
         | 
| 225 231 | 
             
                            {id: 1, type: 'PC'},
         | 
| 226 232 | 
             
                            {id: 2, type: 'noValidType'},
         | 
| 227 | 
            -
                            {id: 3, type: 'Mac'}
         | 
| 233 | 
            +
                            {id: 3, type: 'Mac'},
         | 
| 228 234 | 
             
                          ]
         | 
| 229 235 | 
             
                      end
         | 
| 236 | 
            +
             | 
| 230 237 | 
             
                      it_behaves_like 'with invalid type'
         | 
| 231 238 | 
             
                    end
         | 
| 232 239 |  | 
| @@ -236,9 +243,10 @@ describe Acfs::Resource::QueryMethods do | |
| 236 243 | 
             
                          .to_return response [
         | 
| 237 244 | 
             
                            {id: 1, type: 'PC'},
         | 
| 238 245 | 
             
                            {id: 2, type: 'Computer'},
         | 
| 239 | 
            -
                            {id: 3, type: 42}
         | 
| 246 | 
            +
                            {id: 3, type: 42},
         | 
| 240 247 | 
             
                          ]
         | 
| 241 248 | 
             
                      end
         | 
| 249 | 
            +
             | 
| 242 250 | 
             
                      it_behaves_like 'with invalid type'
         | 
| 243 251 | 
             
                    end
         | 
| 244 252 | 
             
                  end
         | 
| @@ -247,15 +255,16 @@ describe Acfs::Resource::QueryMethods do | |
| 247 255 |  | 
| 248 256 | 
             
              shared_examples 'find_by' do
         | 
| 249 257 | 
             
                context 'standard resource' do
         | 
| 258 | 
            +
                  subject { Acfs.run && user }
         | 
| 259 | 
            +
             | 
| 250 260 | 
             
                  let(:model) { MyUser }
         | 
| 251 261 | 
             
                  let!(:user) { model.send described_method, age: 24 }
         | 
| 252 | 
            -
                  subject { Acfs.run && user }
         | 
| 253 262 |  | 
| 254 263 | 
             
                  context 'return value' do
         | 
| 255 264 | 
             
                    subject { user }
         | 
| 256 265 |  | 
| 257 | 
            -
                    it {  | 
| 258 | 
            -
                    it {  | 
| 266 | 
            +
                    it { is_expected.to be_a MyUser }
         | 
| 267 | 
            +
                    it { is_expected.not_to be_loaded }
         | 
| 259 268 | 
             
                  end
         | 
| 260 269 |  | 
| 261 270 | 
             
                  context 'with params' do
         | 
| @@ -264,7 +273,7 @@ describe Acfs::Resource::QueryMethods do | |
| 264 273 | 
             
                        .to_return response([{id: 1, name: 'Mike', age: 24}])
         | 
| 265 274 | 
             
                    end
         | 
| 266 275 |  | 
| 267 | 
            -
                    it ' | 
| 276 | 
            +
                    it 'includes params in URI to index action' do
         | 
| 268 277 | 
             
                      subject
         | 
| 269 278 | 
             
                      expect(request).to have_been_requested
         | 
| 270 279 | 
             
                    end
         | 
| @@ -276,45 +285,45 @@ describe Acfs::Resource::QueryMethods do | |
| 276 285 | 
             
                        .to_return response [
         | 
| 277 286 | 
             
                          {id: 1, name: 'Mike', age: 24},
         | 
| 278 287 | 
             
                          {id: 4, type: 'Maria', age: 24},
         | 
| 279 | 
            -
                          {id: 7, type: 'James', age: 24}
         | 
| 288 | 
            +
                          {id: 7, type: 'James', age: 24},
         | 
| 280 289 | 
             
                        ]
         | 
| 281 290 | 
             
                    end
         | 
| 282 291 |  | 
| 283 | 
            -
                    it ' | 
| 292 | 
            +
                    it 'invokes callback after model is loaded' do
         | 
| 284 293 | 
             
                      block = proc {}
         | 
| 285 294 |  | 
| 286 295 | 
             
                      expect(block).to receive(:call) do |user|
         | 
| 287 | 
            -
                        expect(user).to eql  | 
| 296 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 288 297 | 
             
                        expect(user).to be_a MyUser
         | 
| 289 298 | 
             
                        expect(user).to be_loaded
         | 
| 290 299 | 
             
                      end
         | 
| 291 300 |  | 
| 292 | 
            -
                       | 
| 301 | 
            +
                      user = model.send described_method, age: 24, &block # rubocop:disable Lint/UselessAssignment
         | 
| 293 302 | 
             
                      Acfs.run
         | 
| 294 303 | 
             
                    end
         | 
| 295 304 |  | 
| 296 | 
            -
                    it ' | 
| 305 | 
            +
                    it 'invokes multiple callbacks after model is loaded' do
         | 
| 297 306 | 
             
                      proc1 = proc {}
         | 
| 298 307 | 
             
                      proc2 = proc {}
         | 
| 299 308 |  | 
| 300 309 | 
             
                      expect(proc1).to receive(:call) do |user|
         | 
| 301 | 
            -
                        expect(user).to eql  | 
| 310 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 302 311 | 
             
                        expect(user).to be_a MyUser
         | 
| 303 312 | 
             
                        expect(user).to be_loaded
         | 
| 304 313 | 
             
                      end
         | 
| 305 314 |  | 
| 306 315 | 
             
                      expect(proc2).to receive(:call) do |user|
         | 
| 307 | 
            -
                        expect(user).to eql  | 
| 316 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 308 317 | 
             
                        expect(user).to be_a MyUser
         | 
| 309 318 | 
             
                        expect(user).to be_loaded
         | 
| 310 319 | 
             
                      end
         | 
| 311 320 |  | 
| 312 | 
            -
                       | 
| 313 | 
            -
                      Acfs.add_callback  | 
| 321 | 
            +
                      user = model.send described_method, age: 24, &proc1
         | 
| 322 | 
            +
                      Acfs.add_callback user, &proc2
         | 
| 314 323 | 
             
                      Acfs.run
         | 
| 315 324 | 
             
                    end
         | 
| 316 325 |  | 
| 317 | 
            -
                    it ' | 
| 326 | 
            +
                    it 'loads a single MyUser object' do
         | 
| 318 327 | 
             
                      expect(subject).to be_a MyUser
         | 
| 319 328 | 
             
                    end
         | 
| 320 329 | 
             
                  end
         | 
| @@ -331,12 +340,14 @@ describe Acfs::Resource::QueryMethods do | |
| 331 340 |  | 
| 332 341 | 
             
              describe '.find_by' do
         | 
| 333 342 | 
             
                let(:described_method) { :find_by }
         | 
| 343 | 
            +
             | 
| 334 344 | 
             
                it_behaves_like 'find_by'
         | 
| 335 345 |  | 
| 336 346 | 
             
                context 'standard resource' do
         | 
| 347 | 
            +
                  subject { Acfs.run && user }
         | 
| 348 | 
            +
             | 
| 337 349 | 
             
                  let(:model) { MyUser }
         | 
| 338 350 | 
             
                  let!(:user) { model.send described_method, age: 24 }
         | 
| 339 | 
            -
                  subject { Acfs.run && user }
         | 
| 340 351 |  | 
| 341 352 | 
             
                  context 'with empty response' do
         | 
| 342 353 | 
             
                    before do
         | 
| @@ -344,35 +355,35 @@ describe Acfs::Resource::QueryMethods do | |
| 344 355 | 
             
                        .to_return response []
         | 
| 345 356 | 
             
                    end
         | 
| 346 357 |  | 
| 347 | 
            -
                    it {  | 
| 358 | 
            +
                    it { is_expected.to be_nil }
         | 
| 348 359 |  | 
| 349 | 
            -
                    it ' | 
| 360 | 
            +
                    it 'invokes callback after model is loaded' do
         | 
| 350 361 | 
             
                      block = proc {}
         | 
| 351 362 |  | 
| 352 363 | 
             
                      expect(block).to receive(:call) do |user|
         | 
| 353 | 
            -
                        expect(user).to eql  | 
| 364 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 354 365 | 
             
                        expect(user).to be_a NilClass
         | 
| 355 366 | 
             
                      end
         | 
| 356 367 |  | 
| 357 | 
            -
                       | 
| 368 | 
            +
                      user = model.find_by age: 24, &block # rubocop:disable Lint/UselessAssignment
         | 
| 358 369 | 
             
                      Acfs.run
         | 
| 359 370 | 
             
                    end
         | 
| 360 371 |  | 
| 361 | 
            -
                    it ' | 
| 372 | 
            +
                    it 'invokes multiple callbacks after model is loaded' do
         | 
| 362 373 | 
             
                      proc1 = proc {}
         | 
| 363 374 | 
             
                      proc2 = proc {}
         | 
| 364 375 |  | 
| 365 376 | 
             
                      expect(proc1).to receive(:call) do |user|
         | 
| 366 | 
            -
                        expect(user).to eql  | 
| 377 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 367 378 | 
             
                        expect(user).to be_a NilClass
         | 
| 368 379 | 
             
                      end
         | 
| 369 380 | 
             
                      expect(proc2).to receive(:call) do |user|
         | 
| 370 | 
            -
                        expect(user).to eql  | 
| 381 | 
            +
                        expect(user).to eql user.__getobj__
         | 
| 371 382 | 
             
                        expect(user).to be_a NilClass
         | 
| 372 383 | 
             
                      end
         | 
| 373 384 |  | 
| 374 | 
            -
                       | 
| 375 | 
            -
                      Acfs.add_callback  | 
| 385 | 
            +
                      user = model.find_by age: 24, &proc1
         | 
| 386 | 
            +
                      Acfs.add_callback user, &proc2
         | 
| 376 387 | 
             
                      Acfs.run
         | 
| 377 388 | 
             
                    end
         | 
| 378 389 | 
             
                  end
         | 
| @@ -381,12 +392,14 @@ describe Acfs::Resource::QueryMethods do | |
| 381 392 |  | 
| 382 393 | 
             
              describe '.find_by!' do
         | 
| 383 394 | 
             
                let(:described_method) { :find_by! }
         | 
| 395 | 
            +
             | 
| 384 396 | 
             
                it_behaves_like 'find_by'
         | 
| 385 397 |  | 
| 386 398 | 
             
                context 'standard resource' do
         | 
| 399 | 
            +
                  subject { Acfs.run && user }
         | 
| 400 | 
            +
             | 
| 387 401 | 
             
                  let(:model) { MyUser }
         | 
| 388 402 | 
             
                  let!(:user) { model.send described_method, age: 24 }
         | 
| 389 | 
            -
                  subject { Acfs.run && user }
         | 
| 390 403 |  | 
| 391 404 | 
             
                  context 'with empty response' do
         | 
| 392 405 | 
             
                    before do
         | 
| @@ -394,12 +407,12 @@ describe Acfs::Resource::QueryMethods do | |
| 394 407 | 
             
                        .to_return response []
         | 
| 395 408 | 
             
                    end
         | 
| 396 409 |  | 
| 397 | 
            -
                    it ' | 
| 410 | 
            +
                    it 'raises an ResourceNotFound error' do
         | 
| 398 411 | 
             
                      model.find_by! age: 24
         | 
| 399 412 | 
             
                      expect { Acfs.run }.to raise_error Acfs::ResourceNotFound
         | 
| 400 413 | 
             
                    end
         | 
| 401 414 |  | 
| 402 | 
            -
                    it ' | 
| 415 | 
            +
                    it 'does not invoke callback after model could not be loaded' do
         | 
| 403 416 | 
             
                      block = proc {}
         | 
| 404 417 |  | 
| 405 418 | 
             
                      expect(block).not_to receive(:call)
         | 
| @@ -417,29 +430,29 @@ describe Acfs::Resource::QueryMethods do | |
| 417 430 | 
             
                        .to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 418 431 | 
             
                          headers: {
         | 
| 419 432 | 
             
                            'X-Total-Pages' => '4',
         | 
| 420 | 
            -
                            'Link' => '<http://users.example.org/users?page=2>; rel="next"'
         | 
| 421 | 
            -
                          })
         | 
| 433 | 
            +
                            'Link' => '<http://users.example.org/users?page=2>; rel="next"',
         | 
| 434 | 
            +
                          },)
         | 
| 422 435 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=2')
         | 
| 423 436 | 
             
                        .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 424 437 | 
             
                          headers: {
         | 
| 425 438 | 
             
                            'X-Total-Pages' => '4',
         | 
| 426 | 
            -
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"'
         | 
| 427 | 
            -
                          })
         | 
| 439 | 
            +
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"',
         | 
| 440 | 
            +
                          },)
         | 
| 428 441 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=3')
         | 
| 429 442 | 
             
                        .to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 430 443 | 
             
                          headers: {
         | 
| 431 444 | 
             
                            'X-Total-Pages' => '4',
         | 
| 432 | 
            -
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"'
         | 
| 433 | 
            -
                          })
         | 
| 445 | 
            +
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"',
         | 
| 446 | 
            +
                          },)
         | 
| 434 447 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=4')
         | 
| 435 448 | 
             
                        .to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 436 449 | 
             
                          headers: {
         | 
| 437 450 | 
             
                            'X-Total-Pages' => '4',
         | 
| 438 | 
            -
                            'Link' => ''
         | 
| 439 | 
            -
                          })
         | 
| 451 | 
            +
                            'Link' => '',
         | 
| 452 | 
            +
                          },)
         | 
| 440 453 | 
             
                    end
         | 
| 441 454 |  | 
| 442 | 
            -
                    it ' | 
| 455 | 
            +
                    it 'iterates all pages' do
         | 
| 443 456 | 
             
                      index = 0
         | 
| 444 457 | 
             
                      model.each_page do |page|
         | 
| 445 458 | 
             
                        expect(page).to be_a Acfs::Collection
         | 
| @@ -459,29 +472,29 @@ describe Acfs::Resource::QueryMethods do | |
| 459 472 | 
             
                        .to_return response([{id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 460 473 | 
             
                          headers: {
         | 
| 461 474 | 
             
                            'X-Total-Pages' => '4',
         | 
| 462 | 
            -
                            'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"'
         | 
| 463 | 
            -
                          })
         | 
| 475 | 
            +
                            'Link' => '<http://users.example.org/users?where=fuu&page=2>; rel="next"',
         | 
| 476 | 
            +
                          },)
         | 
| 464 477 | 
             
                      stub_request(:get, 'http://users.example.org/users?where=fuu&page=2')
         | 
| 465 478 | 
             
                        .to_return response([{id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 466 479 | 
             
                          headers: {
         | 
| 467 480 | 
             
                            'X-Total-Pages' => '4',
         | 
| 468 | 
            -
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"'
         | 
| 469 | 
            -
                          })
         | 
| 481 | 
            +
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"',
         | 
| 482 | 
            +
                          },)
         | 
| 470 483 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=3')
         | 
| 471 484 | 
             
                        .to_return response([{id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 472 485 | 
             
                          headers: {
         | 
| 473 486 | 
             
                            'X-Total-Pages' => '4',
         | 
| 474 | 
            -
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"'
         | 
| 475 | 
            -
                          })
         | 
| 487 | 
            +
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"',
         | 
| 488 | 
            +
                          },)
         | 
| 476 489 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=4')
         | 
| 477 490 | 
             
                        .to_return response([{id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'}],
         | 
| 478 491 | 
             
                          headers: {
         | 
| 479 492 | 
             
                            'X-Total-Pages' => '4',
         | 
| 480 | 
            -
                            'Link' => ''
         | 
| 481 | 
            -
                          })
         | 
| 493 | 
            +
                            'Link' => '',
         | 
| 494 | 
            +
                          },)
         | 
| 482 495 | 
             
                    end
         | 
| 483 496 |  | 
| 484 | 
            -
                    it ' | 
| 497 | 
            +
                    it 'calls first page with params and follow relations' do
         | 
| 485 498 | 
             
                      index = 0
         | 
| 486 499 | 
             
                      model.each_page(param: 'bla') do |page|
         | 
| 487 500 | 
             
                        expect(page).to be_a Acfs::Collection
         | 
| @@ -500,32 +513,52 @@ describe Acfs::Resource::QueryMethods do | |
| 500 513 | 
             
                  context 'without parameters' do
         | 
| 501 514 | 
             
                    before do
         | 
| 502 515 | 
             
                      stub_request(:get, 'http://users.example.org/users')
         | 
| 503 | 
            -
                        .to_return response( | 
| 516 | 
            +
                        .to_return response(
         | 
| 517 | 
            +
                          [
         | 
| 518 | 
            +
                            {id: 1, name: 'Anno', age: 1604, born_at: 'Santa Maria'},
         | 
| 519 | 
            +
                          ],
         | 
| 504 520 | 
             
                          headers: {
         | 
| 505 521 | 
             
                            'X-Total-Pages' => '4',
         | 
| 506 | 
            -
                            'Link' => '<http://users.example.org/users?page=2>; rel="next"'
         | 
| 507 | 
            -
                          } | 
| 522 | 
            +
                            'Link' => '<http://users.example.org/users?page=2>; rel="next"',
         | 
| 523 | 
            +
                          },
         | 
| 524 | 
            +
                        )
         | 
| 525 | 
            +
             | 
| 508 526 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=2')
         | 
| 509 | 
            -
                        .to_return response( | 
| 527 | 
            +
                        .to_return response(
         | 
| 528 | 
            +
                          [
         | 
| 529 | 
            +
                            {id: 2, name: 'Anno', age: 1604, born_at: 'Santa Maria'},
         | 
| 530 | 
            +
                          ],
         | 
| 510 531 | 
             
                          headers: {
         | 
| 511 532 | 
             
                            'X-Total-Pages' => '4',
         | 
| 512 | 
            -
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"'
         | 
| 513 | 
            -
                          } | 
| 533 | 
            +
                            'Link' => '<http://users.example.org/users?page=3>; rel="next"',
         | 
| 534 | 
            +
                          },
         | 
| 535 | 
            +
                        )
         | 
| 536 | 
            +
             | 
| 514 537 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=3')
         | 
| 515 | 
            -
                        .to_return response( | 
| 538 | 
            +
                        .to_return response(
         | 
| 539 | 
            +
                          [
         | 
| 540 | 
            +
                            {id: 3, name: 'Anno', age: 1604, born_at: 'Santa Maria'},
         | 
| 541 | 
            +
                            {id: 4, name: 'Anno', age: 1604, born_at: 'Santa Maria'},
         | 
| 542 | 
            +
                          ],
         | 
| 516 543 | 
             
                          headers: {
         | 
| 517 544 | 
             
                            'X-Total-Pages' => '4',
         | 
| 518 | 
            -
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"'
         | 
| 519 | 
            -
                          } | 
| 545 | 
            +
                            'Link' => '<http://users.example.org/users?page=4>; rel="next"',
         | 
| 546 | 
            +
                          },
         | 
| 547 | 
            +
                        )
         | 
| 548 | 
            +
             | 
| 520 549 | 
             
                      stub_request(:get, 'http://users.example.org/users?page=4')
         | 
| 521 | 
            -
                        .to_return response( | 
| 550 | 
            +
                        .to_return response(
         | 
| 551 | 
            +
                          [
         | 
| 552 | 
            +
                            {id: 5, name: 'Anno', age: 1604, born_at: 'Santa Maria'},
         | 
| 553 | 
            +
                          ],
         | 
| 522 554 | 
             
                          headers: {
         | 
| 523 555 | 
             
                            'X-Total-Pages' => '4',
         | 
| 524 | 
            -
                            'Link' => ''
         | 
| 525 | 
            -
                          } | 
| 556 | 
            +
                            'Link' => '',
         | 
| 557 | 
            +
                          },
         | 
| 558 | 
            +
                        )
         | 
| 526 559 | 
             
                    end
         | 
| 527 560 |  | 
| 528 | 
            -
                    it ' | 
| 561 | 
            +
                    it 'iterates all pages' do
         | 
| 529 562 | 
             
                      indices = []
         | 
| 530 563 | 
             
                      model.each_item do |item|
         | 
| 531 564 | 
             
                        expect(item).to be_a MyUser
         | 
| @@ -536,7 +569,7 @@ describe Acfs::Resource::QueryMethods do | |
| 536 569 | 
             
                      expect(indices).to eq [1, 2, 3, 4, 5]
         | 
| 537 570 | 
             
                    end
         | 
| 538 571 |  | 
| 539 | 
            -
                    it ' | 
| 572 | 
            +
                    it 'passes the collection to the provided block' do
         | 
| 540 573 | 
             
                      model.each_item do |_item, collection|
         | 
| 541 574 | 
             
                        expect(collection).to be_a Acfs::Collection
         | 
| 542 575 | 
             
                      end
         |