Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeClimate and MetricFu issues #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions app/controllers/metric_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ def create
metric_snapshot = build_metric_snapshot
@metric_configuration = MetricConfiguration.new(all_params.reject { |key, _| key == 'metric' })
if valid_metric_snapshot_for_configuration(metric_snapshot, @metric_configuration)
if save_metric_configuration_with_snapshot(@metric_configuration, metric_snapshot)
data = { metric_configuration: @metric_configuration }
status = :created
else
data = { errors: @metric_configuration.errors.full_messages + metric_snapshot.errors.full_messages }
status = :unprocessable_entity
end
result = try_to_save_metric_configuration(metric_snapshot)
else
result = get_result_from_invalid_metric_configuration(metric_snapshot)
end
respond_with_json result[:data], result[:status]
end

def try_to_save_metric_configuration(metric_snapshot)
result = {}
if save_metric_configuration_with_snapshot(@metric_configuration, metric_snapshot)
result[:data] = { metric_configuration: @metric_configuration }
result[:status] = :created
else
data = { errors: @metric_configuration.errors.full_messages + metric_snapshot.errors.full_messages }
status = :unprocessable_entity
result = get_result_from_invalid_metric_configuration(metric_snapshot)
end
respond_with_json data, status
result
end

def get_result_from_invalid_metric_configuration(metric_snapshot)
result = {}
result[:data] = { errors: @metric_configuration.errors.full_messages + metric_snapshot.errors.full_messages }
result[:status] = :unprocessable_entity
result
end

def update
Expand Down