Skip to content

Commit

Permalink
add data to sync errors
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 7, 2018
1 parent f25d2b1 commit c4ea95c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/serializers/api/sync_error_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Api::SyncErrorSerializer < ActiveModel::Serializer
attributes :params, :code, :message, :created_at, :updated_at
attributes :params, :code, :message, :created_at, :updated_at, :data
attribute :method

def method
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180807073702_add_data_to_sync_errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDataToSyncErrors < ActiveRecord::Migration[5.2]
def change
add_column :sync_errors, :data, :json
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_08_07_030924) do
ActiveRecord::Schema.define(version: 2018_08_07_073702) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -69,6 +69,7 @@
t.string "message"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.json "data"
end

create_table "transactions", force: :cascade do |t|
Expand Down
9 changes: 5 additions & 4 deletions spec/controllers/api/sync_errors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
expect(result["syncErrors"]).to be_a(Array)
sync_error = SyncError.last
sync_error_resp = result["syncErrors"].first
expect(sync_error_resp["params"]).to eq sync_error.params
expect(sync_error_resp["method"]).to eq sync_error.method
expect(sync_error_resp["code"]).to eq sync_error.code
expect(sync_error_resp["message"]).to eq sync_error.message

%w(method params code message data).each do |attr|
expect(sync_error_resp).to have_key(attr)
expect(sync_error_resp[attr]).to eq sync_error.public_send(attr)
end
end

it "with page and perPage" do
Expand Down
1 change: 1 addition & 0 deletions spec/factories/sync_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
code -32700
params ["0x0"]
message "invalid format: [0x0]"
data nil
end
end
6 changes: 6 additions & 0 deletions spec/models/cita_sync/persist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
expect(sync_error.params).to eq ["a", true]
expect(sync_error.code).to eq block_zero_params_error_code
expect(sync_error.message).to eq block_zero_params_error_message
expect(sync_error.data).to be nil
end
end

Expand Down Expand Up @@ -52,6 +53,7 @@
expect(sync_error.params).to eq params
expect(sync_error.code).to eq transaction_params_error_code
expect(sync_error.message).to eq transaction_params_error_message
expect(sync_error.data).to be nil
end
end

Expand All @@ -69,6 +71,7 @@
expect(sync_error.params).to eq params
expect(sync_error.code).to eq meta_data_params_error_code
expect(sync_error.message).to eq meta_data_params_error_message
expect(sync_error.data).to be nil
end
end

Expand All @@ -85,6 +88,7 @@
expect(sync_error.params).to eq params
expect(sync_error.code).to eq balance_params_error_code
expect(sync_error.message).to eq balance_params_error_message
expect(sync_error.data).to be nil
end
end

Expand All @@ -101,6 +105,7 @@
expect(sync_error.params).to eq params
expect(sync_error.code).to eq abi_params_error_code
expect(sync_error.message).to eq abi_params_error_message
expect(sync_error.data).to be nil
end
end

Expand Down Expand Up @@ -153,6 +158,7 @@
expect(sync_error.params).to match_array(params)
expect(sync_error.code).to eq code
expect(sync_error.message).to eq message
expect(sync_error.data).to be nil
end

it "with no error info" do
Expand Down

0 comments on commit c4ea95c

Please sign in to comment.