diff --git a/features/step_definitions/metric_collector_details_steps.rb b/features/step_definitions/metric_collector_details_steps.rb
index 1c5f52b..7dfd028 100644
--- a/features/step_definitions/metric_collector_details_steps.rb
+++ b/features/step_definitions/metric_collector_details_steps.rb
@@ -10,7 +10,7 @@
@is_error = false
begin
KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name!("Avalio")
- rescue KalibroClient::Errors::RecordNotFound
+ rescue Likeno::Errors::RecordNotFound
@is_error = true
end
end
diff --git a/features/step_definitions/metric_configuration_steps.rb b/features/step_definitions/metric_configuration_steps.rb
index cfc9e33..dfe191e 100644
--- a/features/step_definitions/metric_configuration_steps.rb
+++ b/features/step_definitions/metric_configuration_steps.rb
@@ -38,7 +38,7 @@
inexistent_id = rand(Time.now.to_i)
begin
KalibroClient::Entities::Configurations::MetricConfiguration.find(inexistent_id)
- rescue KalibroClient::Errors::RecordNotFound
+ rescue Likeno::Errors::RecordNotFound
@is_error = true
end
end
@@ -81,7 +81,7 @@
end
Then(/^the metric configuration should no longer exist$/) do
- expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(KalibroClient::Errors::RecordNotFound)
+ expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(Likeno::Errors::RecordNotFound)
end
Then(/^the metric configuration should exist$/) do
diff --git a/features/step_definitions/module_result_steps.rb b/features/step_definitions/module_result_steps.rb
index 3c44427..83bf598 100644
--- a/features/step_definitions/module_result_steps.rb
+++ b/features/step_definitions/module_result_steps.rb
@@ -6,7 +6,7 @@
@is_error = false
begin
KalibroClient::Entities::Processor::ModuleResult.find(-1)
- rescue KalibroClient::Errors::RecordNotFound
+ rescue Likeno::Errors::RecordNotFound
@is_error = true
end
end
diff --git a/features/support/env.rb b/features/support/env.rb
index d9a2e7f..3bfe490 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -15,9 +15,6 @@
# Kalibro hooks
require 'kalibro_client/kalibro_cucumber_helpers/hooks'
-# Configuring the right hooks
-KalibroClient::KalibroCucumberHelpers.configure_from_yml("#{__dir__}/kalibro_cucumber_helpers.yml")
-
# The gem itself
require 'kalibro_client'
diff --git a/kalibro_client.gemspec b/kalibro_client.gemspec
index 78327ae..3f0d29d 100644
--- a/kalibro_client.gemspec
+++ b/kalibro_client.gemspec
@@ -47,4 +47,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "activesupport", ">= 2.2.1" #version in which underscore was introduced
spec.add_dependency "faraday_middleware", "~> 0.9"
+ spec.add_dependency "likeno", "~> 1.1"
end
diff --git a/lib/kalibro_client.rb b/lib/kalibro_client.rb
index 3a384f2..a40bee1 100644
--- a/lib/kalibro_client.rb
+++ b/lib/kalibro_client.rb
@@ -14,49 +14,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-require 'yaml'
-require 'logger'
+require 'likeno'
require "kalibro_client/version"
require "kalibro_client/errors"
require "kalibro_client/entities"
module KalibroClient
- @config = {
- processor_address: "http://localhost:8082",
- configurations_address: "http://localhost:8083"
- }
+ # Apply default configuration to Likeno
+ Likeno.configure(processor_address: "http://localhost:8082",
+ configurations_address: "http://localhost:8083")
- @valid_config_keys = @config.keys
-
- @logger = Logger.new(STDOUT)
-
- # Configure through hash
- def KalibroClient.configure(opts = {})
- opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
- end
-
- # Configure through yaml file
- def KalibroClient.configure_with(path_to_yaml_file)
- begin
- config = YAML::load(IO.read(path_to_yaml_file))
- rescue Errno::ENOENT
- logger.warn("YAML configuration file couldn't be found. Using defaults."); return
- rescue Psych::SyntaxError
- logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return
- end
-
- configure(config)
- end
-
- def KalibroClient.config
- @config
- end
-
- def KalibroClient.logger
- @logger
- end
-
- def KalibroClient.logger=(logger)
- @logger = logger
- end
end
diff --git a/lib/kalibro_client/entities/base.rb b/lib/kalibro_client/entities/base.rb
index 75b786d..3923ecb 100644
--- a/lib/kalibro_client/entities/base.rb
+++ b/lib/kalibro_client/entities/base.rb
@@ -14,218 +14,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-require 'faraday_middleware'
-require 'kalibro_client/helpers/hash_converters'
-require 'kalibro_client/helpers/request_methods'
+require 'likeno'
+require 'kalibro_client/errors'
module KalibroClient
module Entities
- class Base
- attr_accessor :kalibro_errors, :persisted
-
- def initialize(attributes={}, persisted=false)
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
- @kalibro_errors = []
- @persisted = persisted
- end
-
- def to_hash(options={})
- hash = Hash.new
- excepts = options[:except].nil? ? [] : options[:except]
- excepts << "kalibro_errors"
- excepts << "persisted"
- fields.each do |field|
- hash = field_to_hash(field).merge(hash) if !excepts.include?(field)
- end
- hash
- end
-
- def self.request(action, params = {}, method = :post, prefix="")
- response = client.send(method) do |request|
- url = "/#{endpoint}/#{action}".gsub(":id", params[:id].to_s)
- url = "/#{prefix}#{url}" unless prefix.empty?
- request.url url
- request.body = params unless method == :get || params.empty?
- request.options.timeout = 300
- request.options.open_timeout = 300
- end
-
- if response.success?
- response.body
- # FIXME This condition was added to preserve the deprecated error codes that are returned by kalibro processor
- elsif response.status == 404 || (response.body.key?('errors') && /NotFound/ === response.body['errors'])
- raise KalibroClient::Errors::RecordNotFound.new(response: response)
- else
- raise KalibroClient::Errors::RequestError.new(response: response)
- end
- end
-
-
- def self.to_object value
- value.kind_of?(Hash) ? new(value, true) : value
- end
-
- def self.to_objects_array value
- array = value.kind_of?(Array) ? value : [value]
- array.each.map { |element| to_object(element) }
- end
-
- def save
- if persisted?
- self.update
- else
- without_request_error? do
- response = self.class.request(save_action, save_params, :post, save_prefix)
-
- self.id = response[instance_class_name]["id"]
- self.created_at = response[instance_class_name]["created_at"] unless response[instance_class_name]["created_at"].nil?
- self.updated_at = response[instance_class_name]["updated_at"] unless response[instance_class_name]["updated_at"].nil?
- @persisted = true
- end
- end
- end
-
- def save!
- return true if save
- raise KalibroClient::Errors::RecordInvalid.new(self)
+ class Base < Likeno::Entity
+ # We do not track coverage here as it is deprecated and will be removed soon
+ # :nocov:
+ def kalibro_errors
+ STDERR.puts "DEPRECATED: use 'likeno_errors' instead of 'kalibro_errors'."
+ self.likeno_errors
end
+ # :nocov:
- def self.create(attributes={})
- new_model = new attributes
- new_model.save
- new_model
+ def self.module_name
+ 'KalibroClient'
end
-
- def update(attributes={})
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
- without_request_error? do
- self.class.request(update_action, update_params, :put, update_prefix)
- end
- end
-
- def ==(another)
- unless self.class == another.class
- return false
- end
-
- self.variable_names.each do |name|
- next if name == "created_at" or name == "updated_at" or name == "persisted"
- unless self.send("#{name}") == another.send("#{name}") then
- return false
- end
- end
-
- return true
- end
-
- def self.exists?(id)
- request(exists_action, id_params(id), :get)['exists']
- end
-
- def self.find(id)
- response = request(find_action, id_params(id), :get)
- new(response[entity_name], true)
- end
-
- def destroy
- without_request_error? do
- response = self.class.request(destroy_action, destroy_params, :delete, destroy_prefix)
- @persisted = false
- end
- end
-
- def self.create_objects_array_from_hash (response)
- create_array_from_hash(response[entity_name.pluralize]).map { |hash| new(hash, true) }
- end
-
- def self.create_array_from_hash (response)
- response = [] if response.nil?
- response = [response] if response.is_a?(Hash)
- response
- end
-
- alias_method :persisted?, :persisted
-
- protected
-
- def instance_variable_names
- instance_variables.map { |var| var.to_s }
- end
-
- def fields
- instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
- end
-
- def variable_names
- instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
- end
-
- def self.address
- raise NotImplementedError
- end
-
- # TODO: probably the connection could be a class static variable.
- def self.client
- Faraday.new(:url => KalibroClient.config[address]) do |conn|
- conn.request :json
- conn.response :json, :content_type => /\bjson$/
- conn.adapter Faraday.default_adapter # make requests with Net::HTTP
- end
- end
-
- def self.is_valid?(field)
- field.to_s[0] != '@' and field != :attributes! and (field =~ /attributes!/).nil? and (field.to_s =~ /xsi/).nil? and (field.to_s =~ /errors/).nil?
- end
-
- # TODO rename to instance_entity_name
- def instance_class_name
- self.class.entity_name
- end
-
- include RequestMethods
- extend RequestMethods::ClassMethods
-
- def add_error(exception)
- @kalibro_errors << exception
- end
-
- def self.endpoint
- entity_name.pluralize
- end
-
- def self.entity_name
- # This loop is a generic way to make this work even when the children class has a different name
- entity_class = self
- until entity_class.name.include?("KalibroClient::Entities::") do
- entity_class = entity_class.superclass
- end
-
- return entity_class.name.split("::").last.underscore.downcase
- end
-
- def without_request_error?(&block)
- begin
- block.call
- true
- rescue KalibroClient::Errors::RecordNotFound => error
- raise error
- rescue KalibroClient::Errors::RequestError => error
- raise error if error.response.status.between?(500, 599)
-
- response_errors = error.response.body['errors']
- if response_errors.is_a?(Array)
- response_errors.each { |error_msg| add_error(error_msg) }
- elsif !response_errors.nil?
- add_error response_errors
- else
- add_error error
- end
-
- false
- end
- end
-
- include HashConverters
end
end
end
diff --git a/lib/kalibro_client/entities/configurations/base.rb b/lib/kalibro_client/entities/configurations/base.rb
index fcb40ae..ee1fc40 100644
--- a/lib/kalibro_client/entities/configurations/base.rb
+++ b/lib/kalibro_client/entities/configurations/base.rb
@@ -1,13 +1,13 @@
-require 'kalibro_client/helpers/date_attributes'
+require 'likeno/helpers/date_attributes'
module KalibroClient
module Entities
module Configurations
class Base < KalibroClient::Entities::Base
- include DateAttributes
+ include Likeno::DateAttributes
def self.address
- :configurations_address
+ Likeno.config[:configurations_address]
end
end
end
diff --git a/lib/kalibro_client/entities/configurations/kalibro_configuration.rb b/lib/kalibro_client/entities/configurations/kalibro_configuration.rb
index dac73fd..4e7c42c 100644
--- a/lib/kalibro_client/entities/configurations/kalibro_configuration.rb
+++ b/lib/kalibro_client/entities/configurations/kalibro_configuration.rb
@@ -24,10 +24,6 @@ def id=(value)
@id = value.to_i
end
- def self.all
- create_objects_array_from_hash(request('', {}, :get))
- end
-
def metric_configurations
KalibroClient::Entities::Configurations::MetricConfiguration.create_objects_array_from_hash(self.class.request(':id/metric_configurations', {id: id}, :get))
end
diff --git a/lib/kalibro_client/entities/configurations/metric_configuration.rb b/lib/kalibro_client/entities/configurations/metric_configuration.rb
index 2c59fd2..686af4a 100644
--- a/lib/kalibro_client/entities/configurations/metric_configuration.rb
+++ b/lib/kalibro_client/entities/configurations/metric_configuration.rb
@@ -56,7 +56,7 @@ def weight=(value)
end
def update_attributes(attributes={})
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
+ attributes.each { |field, value| send("#{field}=", value) if self.class.valid?(field) }
save
end
@@ -68,24 +68,6 @@ def self.metric_configurations_of(configuration_id)
create_objects_array_from_hash(request('', {}, :get, "kalibro_configurations/#{configuration_id}"))
end
- def self.find(id)
- begin
- metric_configuration = request(':id', {id: id}, :get)
- return new(metric_configuration['metric_configuration'], true)
- #FIXME Temporary until KalibroProcessor returns proper http statuses
- rescue KalibroClient::Errors::RequestError
- raise KalibroClient::Errors::RecordNotFound
- end
- end
-
- def self.exists?(id)
- begin
- return true unless find(id).nil?
- rescue KalibroClient::Errors::RecordNotFound
- return false
- end
- end
-
def kalibro_ranges
KalibroClient::Entities::Configurations::KalibroRange.create_objects_array_from_hash(self.class.request(':id/kalibro_ranges', {id: id}, :get))
end
diff --git a/lib/kalibro_client/entities/configurations/reading_group.rb b/lib/kalibro_client/entities/configurations/reading_group.rb
index 5e57fb8..f38be7c 100644
--- a/lib/kalibro_client/entities/configurations/reading_group.rb
+++ b/lib/kalibro_client/entities/configurations/reading_group.rb
@@ -5,7 +5,7 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -25,10 +25,6 @@ def id=(value)
@id = value.to_i
end
- def self.all
- create_objects_array_from_hash(request('', {}, :get))
- end
-
def readings
KalibroClient::Entities::Configurations::Reading.create_objects_array_from_hash(self.class.request(':id/readings', {id: @id}, :get))
end
diff --git a/lib/kalibro_client/entities/miscellaneous/base.rb b/lib/kalibro_client/entities/miscellaneous/base.rb
index d9dcfb4..21c7156 100644
--- a/lib/kalibro_client/entities/miscellaneous/base.rb
+++ b/lib/kalibro_client/entities/miscellaneous/base.rb
@@ -1,12 +1,14 @@
+require 'likeno/helpers/hash_converters'
+
module KalibroClient
module Entities
module Miscellaneous
class Base
def initialize(attributes={})
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
+ attributes.each { |field, value| send("#{field}=", value) if self.class.valid?(field) }
end
- include HashConverters
+ include Likeno::HashConverters
def to_hash(options={})
hash = Hash.new
excepts = options[:except].nil? ? [] : options[:except]
diff --git a/lib/kalibro_client/entities/miscellaneous/metric.rb b/lib/kalibro_client/entities/miscellaneous/metric.rb
index 310568e..b8fa2da 100644
--- a/lib/kalibro_client/entities/miscellaneous/metric.rb
+++ b/lib/kalibro_client/entities/miscellaneous/metric.rb
@@ -1,5 +1,3 @@
-require 'kalibro_client/helpers/hash_converters'
-
module KalibroClient
module Entities
module Miscellaneous
diff --git a/lib/kalibro_client/entities/processor/base.rb b/lib/kalibro_client/entities/processor/base.rb
index 6ef3fa2..8da6756 100644
--- a/lib/kalibro_client/entities/processor/base.rb
+++ b/lib/kalibro_client/entities/processor/base.rb
@@ -1,14 +1,14 @@
require 'json'
-require 'kalibro_client/helpers/date_attributes'
+require 'likeno/helpers/date_attributes'
module KalibroClient
module Entities
module Processor
class Base < KalibroClient::Entities::Base
- include DateAttributes
+ include Likeno::DateAttributes
def self.address
- :processor_address
+ Likeno.config[:processor_address]
end
end
end
diff --git a/lib/kalibro_client/entities/processor/hotspot_metric_result.rb b/lib/kalibro_client/entities/processor/hotspot_metric_result.rb
index d9cff33..0db74ff 100644
--- a/lib/kalibro_client/entities/processor/hotspot_metric_result.rb
+++ b/lib/kalibro_client/entities/processor/hotspot_metric_result.rb
@@ -24,7 +24,7 @@ class HotspotMetricResult < KalibroClient::Entities::Processor::MetricResult
def initialize(attributes={}, persisted=false)
@line_number = attributes["line_number"].to_i
attributes.each do |field, value|
- if field != "line_number" and self.class.is_valid?(field)
+ if field != "line_number" and self.class.valid?(field)
send("#{field}=", value)
end
end
diff --git a/lib/kalibro_client/entities/processor/metric_collector_details.rb b/lib/kalibro_client/entities/processor/metric_collector_details.rb
index 8d8ba35..e544ba0 100644
--- a/lib/kalibro_client/entities/processor/metric_collector_details.rb
+++ b/lib/kalibro_client/entities/processor/metric_collector_details.rb
@@ -38,7 +38,7 @@ def find_metric_by_name(name)
def find_metric_by_name!(name)
metric = self.find_metric_by_name(name)
- raise KalibroClient::Errors::RecordNotFound if metric.nil?
+ raise Likeno::Errors::RecordNotFound if metric.nil?
metric
end
@@ -48,14 +48,14 @@ def find_metric_by_code(metric_code)
def find_metric_by_code!(metric_code)
metric = self.find_metric_by_code(metric_code)
- raise KalibroClient::Errors::RecordNotFound if metric.nil?
+ raise Likeno::Errors::RecordNotFound if metric.nil?
metric
end
def self.find_by_name(metric_collector_name)
begin
self.find_by_name!(metric_collector_name)
- rescue KalibroClient::Errors::RecordNotFound
+ rescue Likeno::Errors::RecordNotFound
nil
end
end
@@ -67,10 +67,6 @@ def self.find_by_name!(metric_collector_name)
def self.all_names
request(:names, {}, :get)['metric_collector_names'].to_a
end
-
- def self.all
- create_objects_array_from_hash(request('', {}, :get))
- end
end
end
end
diff --git a/lib/kalibro_client/entities/processor/module_result.rb b/lib/kalibro_client/entities/processor/module_result.rb
index ff64138..7fb47e0 100644
--- a/lib/kalibro_client/entities/processor/module_result.rb
+++ b/lib/kalibro_client/entities/processor/module_result.rb
@@ -89,19 +89,6 @@ def hotspot_metric_results
HotspotMetricResult.create_objects_array_from_hash(self.class.request(":id/hotspot_metric_results",
{id: self.id}, :get))
end
-
- # FIXME: KalibroProcessor should return a 404 if the object does not exist instead of 422
- def self.find(id)
- begin
- super
- rescue KalibroClient::Errors::RequestError => e
- if(e.response.status == 422)
- raise KalibroClient::Errors::RecordNotFound.new(response: e.response)
- else
- raise e
- end
- end
- end
end
end
end
diff --git a/lib/kalibro_client/entities/processor/project.rb b/lib/kalibro_client/entities/processor/project.rb
index 0333667..40fb33b 100644
--- a/lib/kalibro_client/entities/processor/project.rb
+++ b/lib/kalibro_client/entities/processor/project.rb
@@ -25,10 +25,6 @@ def id=(value)
@id = value.to_i
end
- def self.all
- create_objects_array_from_hash(request('', {}, :get))
- end
-
def repositories
Repository.create_objects_array_from_hash(self.class.request(':id/repositories', {id: id}, :get))
end
diff --git a/lib/kalibro_client/entities/processor/repository.rb b/lib/kalibro_client/entities/processor/repository.rb
index a728397..ef1bd55 100644
--- a/lib/kalibro_client/entities/processor/repository.rb
+++ b/lib/kalibro_client/entities/processor/repository.rb
@@ -112,10 +112,6 @@ def last_processing_before(date)
Processing.new(self.class.request("#{self.id}/last_processing/before", {:date => date})['processing'])
end
- def self.all
- create_objects_array_from_hash(request("", {}, :get))
- end
-
def self.branches(url, scm_type)
request("/branches", {url: url, scm_type: scm_type})
end
diff --git a/lib/kalibro_client/entities/processor/tree_metric_result.rb b/lib/kalibro_client/entities/processor/tree_metric_result.rb
index 9f942bf..7a30457 100644
--- a/lib/kalibro_client/entities/processor/tree_metric_result.rb
+++ b/lib/kalibro_client/entities/processor/tree_metric_result.rb
@@ -24,7 +24,7 @@ def initialize(attributes={}, persisted=false)
value = attributes["value"]
@value = (value == "NaN") ? attributes["aggregated_value"].to_f : value.to_f
attributes.each do |field, value|
- if field!= "value" and field!= "aggregated_value" and self.class.is_valid?(field)
+ if field!= "value" and field!= "aggregated_value" and self.class.valid?(field)
send("#{field}=", value)
end
end
diff --git a/lib/kalibro_client/errors.rb b/lib/kalibro_client/errors.rb
index 25150f3..a91a813 100644
--- a/lib/kalibro_client/errors.rb
+++ b/lib/kalibro_client/errors.rb
@@ -14,7 +14,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-require 'kalibro_client/errors/standard'
-require 'kalibro_client/errors/request_error'
-require 'kalibro_client/errors/record_not_found'
-require 'kalibro_client/errors/record_invalid'
+require 'likeno/errors'
diff --git a/lib/kalibro_client/errors/record_invalid.rb b/lib/kalibro_client/errors/record_invalid.rb
deleted file mode 100644
index fdf2dea..0000000
--- a/lib/kalibro_client/errors/record_invalid.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module KalibroClient
- module Errors
- class RecordInvalid < Standard
- attr_reader :record
-
- def initialize(record = nil)
- if record
- @record = record
- errors = @record.kalibro_errors.join(', ')
- message = "Record invalid: #{errors}"
- else
- message = 'Record invalid'
- end
-
- super(message)
- end
- end
- end
-end
diff --git a/lib/kalibro_client/errors/record_not_found.rb b/lib/kalibro_client/errors/record_not_found.rb
deleted file mode 100644
index c78945f..0000000
--- a/lib/kalibro_client/errors/record_not_found.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-module KalibroClient
- module Errors
- class RecordNotFound < RequestError
- end
- end
-end
diff --git a/lib/kalibro_client/errors/request_error.rb b/lib/kalibro_client/errors/request_error.rb
deleted file mode 100644
index 138ef70..0000000
--- a/lib/kalibro_client/errors/request_error.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-module KalibroClient
- module Errors
- class RequestError < Standard
- attr_reader :response
-
- def initialize(attributes={})
- @response = attributes[:response]
- end
- end
- end
-end
diff --git a/lib/kalibro_client/errors/standard.rb b/lib/kalibro_client/errors/standard.rb
deleted file mode 100644
index f84b1c0..0000000
--- a/lib/kalibro_client/errors/standard.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-#Inspired on:
-#https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb
-module KalibroClient
- module Errors
- class Standard < StandardError
- end
- end
-end
diff --git a/lib/kalibro_client/helpers/date_attributes.rb b/lib/kalibro_client/helpers/date_attributes.rb
deleted file mode 100644
index f4a01c9..0000000
--- a/lib/kalibro_client/helpers/date_attributes.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module DateAttributes
- attr_reader :created_at, :updated_at
-
- def created_at=(value)
- @created_at = DateTime.parse(value)
- end
-
- def updated_at=(value)
- @updated_at = DateTime.parse(value)
- end
-end
\ No newline at end of file
diff --git a/lib/kalibro_client/helpers/hash_converters.rb b/lib/kalibro_client/helpers/hash_converters.rb
deleted file mode 100644
index cea5448..0000000
--- a/lib/kalibro_client/helpers/hash_converters.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-require 'date'
-require 'kalibro_client/helpers/xml_converters'
-
-module HashConverters
- include XMLConverters
-
- #FIXME: we can think about a better name. This method actually receives an DateTime and converts it to string
- def date_with_milliseconds(date)
- milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s
- date.to_s[0..18] + milliseconds + date.to_s[19..-1]
- end
-
- def convert_to_hash(value)
- return value if value.nil?
- return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array)
- return value.to_hash if value.is_a?(KalibroClient::Entities::Base) || value.is_a?(KalibroClient::Entities::Miscellaneous::Base)
- return date_with_milliseconds(value) if value.is_a?(DateTime)
- return 'INF' if value.is_a?(Float) and value.infinite? == 1
- return '-INF' if value.is_a?(Float) and value.infinite? == -1
- value.to_s
- end
-
- def field_to_hash(field)
- hash = Hash.new
- field_value = send(field)
- if !field_value.nil?
- hash[field] = convert_to_hash(field_value)
- hash = get_xml(field, field_value).merge(hash)
- end
- hash
- end
-end
diff --git a/lib/kalibro_client/helpers/request_methods.rb b/lib/kalibro_client/helpers/request_methods.rb
deleted file mode 100644
index 6ae5d83..0000000
--- a/lib/kalibro_client/helpers/request_methods.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-module RequestMethods
- def save_params
- {instance_class_name.underscore.to_sym => self.to_hash}
- end
-
- def save_action
- ""
- end
-
- def save_prefix
- ""
- end
-
- def destroy_action
- ":id"
- end
- alias_method :update_action, :destroy_action
-
- def destroy_params
- {id: self.id}
- end
-
- def destroy_prefix
- ""
- end
-
- def update_params
- {instance_class_name.underscore.to_sym => self.to_hash, :id => self.id}
- end
-
- def update_prefix
- ""
- end
-
- module ClassMethods
- def exists_action
- ":id/exists"
- end
-
- def id_params(id)
- {id: id}
- end
-
- def find_action
- ":id"
- end
- end
-end
diff --git a/lib/kalibro_client/helpers/xml_converters.rb b/lib/kalibro_client/helpers/xml_converters.rb
deleted file mode 100644
index 4a36d89..0000000
--- a/lib/kalibro_client/helpers/xml_converters.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-module XMLConverters
- def xml_instance_class_name(object)
- xml_name = object.class.name
- xml_name["KalibroClient::Entities::"] = "" if xml_name.start_with?("KalibroClient::Entities::")
- xml_name[0..0] = xml_name[0..0].downcase
- xml_name + "Xml"
- end
-
- def get_xml(field, field_value)
- hash = Hash.new
- if field_value.is_a?(KalibroClient::Entities::Base)
- hash = {:attributes! => {}}
- hash[:attributes!][field.to_sym] = {
- 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
- 'xsi:type' => 'kalibro:' + xml_instance_class_name(field_value)
- }
- end
- hash
- end
-end
diff --git a/lib/kalibro_client/kalibro_cucumber_helpers.rb b/lib/kalibro_client/kalibro_cucumber_helpers.rb
index 053d7d1..4ec03c1 100644
--- a/lib/kalibro_client/kalibro_cucumber_helpers.rb
+++ b/lib/kalibro_client/kalibro_cucumber_helpers.rb
@@ -14,47 +14,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-require 'yaml'
-require 'kalibro_client/kalibro_cucumber_helpers/configuration'
+require 'kalibro_client/kalibro_cucumber_helpers/cleaner'
module KalibroClient
module KalibroCucumberHelpers
- @configuration = KalibroClient::KalibroCucumberHelpers::Configuration.new
-
- def KalibroCucumberHelpers.configure(&config_block)
- config_block.call(@configuration)
- end
-
- def KalibroCucumberHelpers.configure_from_yml(file_path)
- configuration = YAML.load(File.open("features/support/kalibro_cucumber_helpers.yml"))
-
- configuration["kalibro_cucumber_helpers"].each do |config, value|
- @configuration.send("#{config}=", value)
- end
- end
-
- def KalibroCucumberHelpers.configuration
- @configuration
+ def self.clean_processor
+ @processor_cleaner ||= KalibroClient::KalibroCucumberHelpers::Cleaner.new(:processor_address)
+ @processor_cleaner.clean_database
end
- def KalibroCucumberHelpers.clean_processor
- client = Faraday.new(:url => @configuration.kalibro_processor_address) do |conn|
- conn.request :json
- conn.response :json, :content_type => /\bjson$/
- conn.adapter Faraday.default_adapter # make requests with Net::HTTP
- end
-
- client.send(:post, "/tests/clean_database", {})
- end
-
- def KalibroCucumberHelpers.clean_configurations
- client = Faraday.new(:url => @configuration.kalibro_configurations_address) do |conn|
- conn.request :json
- conn.response :json, :content_type => /\bjson$/
- conn.adapter Faraday.default_adapter # make requests with Net::HTTP
- end
-
- client.send(:post, "/tests/clean_database", {})
+ def self.clean_configurations
+ @configurations_cleaner ||= KalibroClient::KalibroCucumberHelpers::Cleaner.new(:configurations_address)
+ @configurations_cleaner.clean_database
end
end
end
diff --git a/lib/kalibro_client/kalibro_cucumber_helpers/cleaner.rb b/lib/kalibro_client/kalibro_cucumber_helpers/cleaner.rb
new file mode 100644
index 0000000..5f8078f
--- /dev/null
+++ b/lib/kalibro_client/kalibro_cucumber_helpers/cleaner.rb
@@ -0,0 +1,27 @@
+require 'likeno'
+
+module KalibroClient
+ module KalibroCucumberHelpers
+ class Cleaner
+ include Likeno::RequestMethods
+
+ attr_reader :address_key
+
+ def initialize(address_key)
+ @address_key = address_key
+ end
+
+ def address
+ Likeno.config[address_key]
+ end
+
+ def endpoint
+ 'tests'
+ end
+
+ def clean_database
+ request('clean_database', {}, :post)
+ end
+ end
+ end
+end
diff --git a/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb b/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb
deleted file mode 100644
index 7e467d8..0000000
--- a/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-module KalibroClient
- module KalibroCucumberHelpers
- class Configuration
- attr_accessor :kalibro_processor_address, :kalibro_configurations_address
-
- def initialize(attributes={})
- self.kalibro_processor_address = "http://localhost:8082"
- self.kalibro_configurations_address = "http://localhost:8083"
-
- attributes.each { |field, value| send("#{field}=", value) if respond_to?("#{field}=") }
- end
- end
- end
-end
diff --git a/lib/kalibro_client/version.rb b/lib/kalibro_client/version.rb
index ab80568..4d0d995 100644
--- a/lib/kalibro_client/version.rb
+++ b/lib/kalibro_client/version.rb
@@ -15,5 +15,5 @@
# along with this program. If not, see .
module KalibroClient
- VERSION = "3.0.1"
+ VERSION = "4.0.0.alpha1"
end
diff --git a/spec/entities/base_spec.rb b/spec/entities/base_spec.rb
index fe61707..f207774 100644
--- a/spec/entities/base_spec.rb
+++ b/spec/entities/base_spec.rb
@@ -19,467 +19,35 @@
# Create a class that has the attribute assignment methods, since some methods expect they exist
# (and usually the subclasses do that).
+class MiscellaneousTest < KalibroClient::Entities::Miscellaneous::Base
+ attr_accessor :id
+end
+
class BaseTest < KalibroClient::Entities::Base
- attr_accessor :id, :created_at, :updated_at
+ attr_accessor :id, :miscellaneous
end
describe KalibroClient::Entities::Base do
subject { BaseTest.new }
- describe 'new' do
- subject { described_class.new({}) }
-
- it 'is expected to create a model from an empty hash' do
- expect(subject.kalibro_errors).to eq([])
- end
- end
-
- describe 'entity_name' do
- it 'is expected to be a String' do
- expect(subject.class.entity_name).to be_a(String)
- end
-
- it 'is expected to return Base' do
- expect(subject.class.entity_name).to eq('base')
- end
- end
-
- describe 'endpoint' do
- it 'is expected to return the entity_name' do
- endpoint = 'tests'
- described_class.expects(:entity_name).returns(endpoint)
- expect(described_class.endpoint).to eq(endpoint)
- end
- end
-
- describe 'client' do
- it 'returns a Faraday::Connection' do
- expect { described_class.client }.to raise_error(NotImplementedError)
- end
- end
-
- describe 'request' do
- context 'with successful responses' do
- let(:exists_response) { { 'exists' => false } }
- let(:bases_response) { { 'bases' => { 'id' => 1 } } }
- let(:prefix_bases_response) { { 'bases' => { 'id' => 2 } } }
- let(:faraday_stubs) { Faraday::Adapter::Test::Stubs.new }
- let(:connection) { Faraday.new { |builder| builder.adapter :test, faraday_stubs } }
-
- before :each do
- subject.class.expects(:client).at_least_once.returns(connection)
- subject.class.expects(:endpoint).at_least_once.returns('bases')
- end
-
- after :each do
- faraday_stubs.verify_stubbed_calls
- end
-
- context 'without an id parameter' do
- context 'without a prefix' do
- it 'is expected to make the request without the prefix' do
- # stub.get receives arguments: path, headers, block
- # The block should be a Array [status, headers, body]
- faraday_stubs.get('/bases/') { [200, {}, bases_response] }
- response = subject.class.request('', {}, :get)
- expect(response).to eq(bases_response)
- end
- end
-
- context 'with a prefix' do
- it 'is expected to make the request with the prefix' do
- # stub.get receives arguments: path, headers, block
- # The block should be a Array [status, headers, body]
- faraday_stubs.get('/prefix/bases/') { [200, {}, prefix_bases_response] }
- response = subject.class.request('', {}, :get, 'prefix')
- expect(response).to eq(prefix_bases_response)
- end
- end
- end
-
- context 'with an id parameter' do
- it 'is expected to make the request with the id included' do
- # stub.get receives arguments: path, headers, block
- # The block should be a Array [status, headers, body]
- faraday_stubs.get('/bases/1/exists') { [200, {}, exists_response] }
- response = subject.class.request(':id/exists', { id: 1 }, :get)
- expect(response).to eq(exists_response)
- end
- end
- end
-
- context 'when the record was not found' do
- context 'and or the status is 404' do
- let!(:faraday_stubs) do
- Faraday::Adapter::Test::Stubs.new do |stub|
- # stub.get receives arguments: path, headers, block
- # The block should be a Array [status, headers, body]
- stub.get('/bases/1') { [404, {}, {}] }
- end
- end
- let!(:connection) { Faraday.new { |builder| builder.adapter :test, faraday_stubs } }
-
- before :each do
- described_class.expects(:client).at_least_once.returns(connection)
- end
-
- it 'is expected to raise a RecordNotFound error' do
- expect { described_class.request(':id', { id: 1 }, :get) }.to raise_error(KalibroClient::Errors::RecordNotFound)
- faraday_stubs.verify_stubbed_calls
- end
- end
-
- context 'and or the response has a NotFound error message' do
- let!(:faraday_stubs) do
- Faraday::Adapter::Test::Stubs.new do |stub|
- # stub.get receives arguments: path, headers, block
- # The block should be a Array [status, headers, body]
- stub.get('/bases/1') { [422, {}, { 'errors' => 'RecordNotFound' }] }
- end
- end
- let!(:connection) { Faraday.new { |builder| builder.adapter :test, faraday_stubs } }
-
- before :each do
- described_class.expects(:client).at_least_once.returns(connection)
- end
-
- it 'is expected to raise a RecordNotFound error' do
- expect { described_class.request(':id', { id: 1 }, :get) }.to raise_error(KalibroClient::Errors::RecordNotFound)
- faraday_stubs.verify_stubbed_calls
- end
- end
- end
-
- context 'with an unsuccessful request' do
- let!(:stubs) { Faraday::Adapter::Test::Stubs.new { |stub| stub.get('/bases/1/exists') { [500, {}, {}] } } }
- let(:connection) { Faraday.new { |builder| builder.adapter :test, stubs } }
-
- before :each do
- subject.class.expects(:client).at_least_once.returns(connection)
- end
-
- it 'is expected to raise a RequestError with the response' do
- expect { subject.class.request(':id/exists', { id: 1 }, :get) }.to raise_error do |error|
- expect(error).to be_a(KalibroClient::Errors::RequestError)
- expect(error.response.status).to eq(500)
- expect(error.response.body).to eq({})
- end
- stubs.verify_stubbed_calls
- end
- end
- end
-
- describe 'to_hash' do
- it 'is expected to return an empty hash' do
- expect(subject.to_hash).to be_empty
- end
+ before do
+ subject.id = 24
+ subject.miscellaneous = MiscellaneousTest.new
+ subject.miscellaneous.id = 42
end
- describe 'to_object' do
- it 'is expected to return an Object with an empty hash' do
- expect(described_class.to_object({})).to eq(FactoryGirl.build(:model))
- end
-
- it "is expected to remain an object if it isn't a Hash" do
- expect(described_class.to_object(Object.new)).to be_an(Object)
- end
- end
-
- describe 'to_objects_array' do
- it 'is expected to convert [{}] to [Model]' do
- expect(described_class.to_objects_array({})).to eq([FactoryGirl.build(:model)])
- end
-
- it 'is expected to remain an array if it already is one' do
- object = Object.new
- expect(described_class.to_objects_array([object])).to eq([object])
- end
- end
-
- shared_examples 'persistence method' do |method_name, http_method, has_id = true|
- before :each do
- subject.id = 42 if has_id
- end
-
- let(:url) { has_id ? ':id' : '' }
- let(:params) { has_id ? has_entry(id: 42) : anything }
-
- context 'when a record does not exist with given id' do
- before :each do
- subject.class.expects(:request).with(url, params, http_method, '').
- raises(KalibroClient::Errors::RecordNotFound)
- end
-
- it 'is expected to raise a RecordNotFound error' do
- expect { subject.send(method_name) }.to raise_error(KalibroClient::Errors::RecordNotFound)
- end
- end
-
- context 'when a server error is returned' do
- before :each do
- error = KalibroClient::Errors::RequestError.new(response: mock(status: 500))
-
- subject.class.expects(:request).with(url, params, http_method, '').raises(error)
- end
-
- it 'is expected to raise a RequestError error' do
- expect { subject.send(method_name) }.to raise_error(KalibroClient::Errors::RequestError)
- end
- end
-
- context 'when a regular kind of error is returned' do
- before :each do
- error = KalibroClient::Errors::RequestError.new(response: mock(status: 422, body: { 'errors' => errors }))
-
- subject.class.expects(:request).with(url, params, http_method, '').raises(error)
- end
-
- context 'with a single error' do
- let(:errors) { "error" }
-
- it 'is expected to set the kalibro_errors field' do
- expect(subject.send(method_name)).to eq(false)
- expect(subject.kalibro_errors).to eq([errors])
- end
- end
-
- context 'with an array of errors' do
- let(:errors) { ["error_1", "error_2"] }
-
- it 'is expected to set the kalibro_errors field' do
- expect(subject.send(method_name)).to eq(false)
- expect(subject.kalibro_errors).to eq(errors)
- end
- end
-
- context 'with no error message at all' do
- let(:errors) { nil }
-
- it 'is expected to set the kalibro_errors field' do
- expect(subject.send(method_name)).to eq(false)
- expect(subject.kalibro_errors.first).to be_a(KalibroClient::Errors::RequestError)
- end
+ describe 'class method' do
+ describe 'module_name' do
+ it 'is expected to return the camelized gem name' do
+ expect(described_class.module_name).to eq('KalibroClient')
end
end
end
- describe 'save' do
- it_behaves_like 'persistence method', :save, :post, false # false means Don't use ids in URLs
-
- context 'with a successful response' do
- context 'when it is not persisted' do
- before :each do
- subject.class.expects(:request).at_least_once.with('', anything, :post, '').
- returns({ "base" => { 'id' => 42, 'errors' => [] } })
- end
-
- it 'is expected to make a request to save model with id and return true without errors' do
- expect(subject.save).to be(true)
- expect(subject.id).to eq(42)
- expect(subject.kalibro_errors).to be_empty
- end
- end
-
- context 'when it is persisted' do
- before :each do
- subject.expects(:persisted?).at_least_once.returns(true)
- end
-
- it 'is expected to call the update method' do
- subject.expects(:update).returns(true)
- expect(subject.save).to eq(true)
- end
- end
- end
- end
-
- describe 'update' do
- it_behaves_like 'persistence method', :update, :put
-
- context 'with valid parameters' do
- before :each do
- id = 42
-
- subject.expects(:id).at_least_once.returns(id)
- described_class.expects(:request).with(':id', has_entry(id: id), :put, '').
- returns({ "base" => { 'id' => id, 'errors' => [] }})
- end
-
- it 'is expected to return true' do
- expect(subject.update).to eq(true)
- end
- end
- end
-
- describe 'create' do
- before :each do
- subject.expects(:save)
- described_class.
- expects(:new).
- with({}).
- returns(subject)
- end
-
- it 'is expected to instantiate and save the model' do
- expect(described_class.create {}).to eq(subject)
- end
- end
-
- describe 'find' do
- context 'with an inexistent id' do
- before :each do
- subject.class.expects(:request).at_least_once.with(':id', has_entry(id: 0), :get).
- raises(KalibroClient::Errors::RecordNotFound)
- end
-
- it 'is expected to raise a RecordNotFound error' do
- expect { subject.class.find(0) }.to raise_error(KalibroClient::Errors::RecordNotFound)
- end
- end
-
- context 'with an existent id' do
- before :each do
- subject.class.expects(:request).with(':id', has_entry(id: 42), :get).
- returns("base" => { 'id' => 42 })
- end
-
- it 'is expected to return an empty model' do
- expect(subject.class.find(42).id).to eq(42)
- end
- end
- end
-
- describe 'destroy' do
- it_behaves_like 'persistence method', :destroy, :delete
-
- context 'when it gets successfully destroyed' do
- before :each do
- subject.expects(:id).at_least_once.returns(42)
- described_class.expects(:request).with(':id', { id: subject.id }, :delete, '').returns({})
- end
-
- it 'is expected to remain with the errors array empty and not persisted' do
- subject.destroy
- expect(subject.kalibro_errors).to be_empty
- expect(subject.persisted?).to eq(false)
- end
- end
- end
-
- describe 'save!' do
- it 'is expected to call save and not raise when saving works' do
- subject.expects(:save).returns(true)
- expect { subject.save! }.not_to raise_error
- end
-
- it 'is expected to call save and raise RecordInvalid when saving fails' do
- subject.expects(:kalibro_errors).returns(['test1', 'test2'])
- subject.expects(:save).returns(false)
-
- expect { subject.save! }.to raise_error { |error|
- expect(error).to be_a(KalibroClient::Errors::RecordInvalid)
- expect(error.record).to be(subject)
- expect(error.message).to eq('Record invalid: test1, test2')
- }
- end
- end
-
- describe '==' do
- subject { FactoryGirl.build(:model) }
-
- context 'comparing objects from different classes' do
- it 'is expected to return false' do
- expect(subject).not_to eq(Object.new)
- end
- end
-
- context 'with two models with different attribute values' do
- let(:another_model) { FactoryGirl.build(:model) }
-
- before :each do
- subject.expects(:variable_names).returns(["answer"])
- subject.expects(:send).with("answer").returns(42)
- another_model.expects(:send).with("answer").returns(41)
- end
-
- it 'is expected to return false' do
- expect(subject).not_to eq(another_model)
- end
- end
-
- context 'with two empty models' do
- it 'is expected to return true' do
- expect(subject).to eq(FactoryGirl.build(:model))
- end
- end
- end
-
- describe 'exists?' do
- context 'with an inexistent id' do
- before :each do
- described_class.
- expects(:request).
- with(':id/exists', { id: 0 }, :get).
- returns({ 'exists' => false })
- end
-
- it 'is expected to return false' do
- expect(described_class.exists?(0)).to eq(false)
- end
- end
-
- context 'with an existent id' do
- before :each do
- described_class.
- expects(:request).
- with(':id/exists', { id: 42 }, :get).
- returns({ 'exists' => true })
- end
-
- it 'is expected to return false' do
- expect(described_class.exists?(42)).to eq(true)
- end
- end
- end
-
- describe 'create_objects_array_from_hash' do
- subject { FactoryGirl.build(:model) }
-
- context 'with nil' do
- it 'is expected to return an empty array' do
- expect(described_class.create_objects_array_from_hash("bases" => [])).to eq([])
- end
- end
-
- context 'with a Hash' do
- it 'is expected to return the correspondent object to the given hash inside of an Array' do
- expect(described_class.create_objects_array_from_hash("bases" => {})).to eq([subject])
- end
- end
- end
-
- describe 'is_valid?' do
- context 'with a global var' do
- it 'is expected to return false' do
- expect(described_class.is_valid?('@test')).to be_falsey
- end
- end
-
- context 'with the attributes var' do
- it 'is expected to return false' do
- expect(described_class.is_valid?(:attributes!)).to be_falsey
- end
- end
-
- context 'with a xsi var' do
- it 'is expected to return false' do
- expect(described_class.is_valid?('test_xsi')).to be_falsey
- end
- end
-
- context 'with a valid var' do
- it 'is expected to return true' do
- expect(described_class.is_valid?('test')).to be_truthy
+ describe 'instance method' do
+ describe 'convert_to_hash' do
+ it 'is expected to convert miscellaneous nested objects' do
+ expect(subject.to_hash).to eq({'id' => "24", 'miscellaneous' => {'id' => "42"}})
end
end
end
diff --git a/spec/entities/configurations/kalibro_configuration_spec.rb b/spec/entities/configurations/kalibro_configuration_spec.rb
index 53363dc..86f52aa 100644
--- a/spec/entities/configurations/kalibro_configuration_spec.rb
+++ b/spec/entities/configurations/kalibro_configuration_spec.rb
@@ -24,41 +24,6 @@
end
end
- describe 'all' do
- context 'with no configurations' do
- before :each do
- KalibroClient::Entities::Configurations::KalibroConfiguration.
- expects(:request).
- with('', {}, :get).
- returns({'kalibro_configurations' => []})
- end
-
- it 'is expected to return nil' do
- expect(KalibroClient::Entities::Configurations::KalibroConfiguration.all).to be_empty
- end
- end
-
- context 'with many configurations' do
- let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
- let(:another_kalibro_configuration) { FactoryGirl.build(:another_kalibro_configuration) }
-
- before :each do
- KalibroClient::Entities::Configurations::KalibroConfiguration.
- expects(:request).
- with('', {}, :get).
- returns({'kalibro_configurations' => [kalibro_configuration.to_hash, another_kalibro_configuration.to_hash]})
- end
-
- it 'is expected to return the two elements' do
- kalibro_configurations = KalibroClient::Entities::Configurations::KalibroConfiguration.all
-
- expect(kalibro_configurations.size).to eq(2)
- expect(kalibro_configurations.first.name).to eq(kalibro_configuration.name)
- expect(kalibro_configurations.last.name).to eq(another_kalibro_configuration.name)
- end
- end
- end
-
describe 'metric_configurations' do
context 'with no metric configurations' do
before :each do
diff --git a/spec/entities/configurations/kalibro_range_spec.rb b/spec/entities/configurations/kalibro_range_spec.rb
index aab6540..3a38115 100644
--- a/spec/entities/configurations/kalibro_range_spec.rb
+++ b/spec/entities/configurations/kalibro_range_spec.rb
@@ -123,7 +123,7 @@
before :each do
KalibroClient::Entities::Configurations::KalibroRange.
expects(:request).
- with('', {:kalibro_range => subject.to_hash, :metric_configuration_id => subject.metric_configuration_id}, :post, "metric_configurations/#{subject.metric_configuration_id}").
+ with('', {:kalibro_range => subject.to_hash, :metric_configuration_id => subject.metric_configuration_id}, :post, "metric_configurations/#{subject.metric_configuration_id}", {}).
returns("kalibro_range" => { 'id' => 2, 'kalibro_errors' => []})
end
@@ -140,7 +140,7 @@
before :each do
KalibroClient::Entities::Configurations::KalibroRange.
expects(:request).
- with(":id", {id: subject.id}, :delete, "metric_configurations/#{subject.metric_configuration_id}").returns({})
+ with(":id", {id: subject.id}, :delete, "metric_configurations/#{subject.metric_configuration_id}", {}).returns({})
end
it 'should make a request to destroy' do
@@ -156,7 +156,7 @@
subject.end = "555"
KalibroClient::Entities::Configurations::KalibroRange.
expects(:request).
- with(':id', {:kalibro_range => subject.to_hash, :id => subject.id}, :put, "metric_configurations/#{subject.metric_configuration_id}").
+ with(':id', {:kalibro_range => subject.to_hash, :id => subject.id}, :put, "metric_configurations/#{subject.metric_configuration_id}", {}).
returns("errors" => nil)
end
diff --git a/spec/entities/configurations/metric_configuration_spec.rb b/spec/entities/configurations/metric_configuration_spec.rb
index a49f7a7..406febe 100644
--- a/spec/entities/configurations/metric_configuration_spec.rb
+++ b/spec/entities/configurations/metric_configuration_spec.rb
@@ -159,7 +159,7 @@
before :each do
KalibroClient::Entities::Configurations::MetricConfiguration.
expects(:request).
- with('', {:metric_configuration => subject.to_hash, :kalibro_configuration_id => subject.kalibro_configuration_id}, :post, '').
+ with('', {:metric_configuration => subject.to_hash, :kalibro_configuration_id => subject.kalibro_configuration_id}, :post, '', {}).
returns("metric_configuration" => {'id' => 1, 'kalibro_errors' => []})
end
@@ -169,63 +169,6 @@
end
end
- describe 'exists?' do
- subject {FactoryGirl.build(:metric_configuration_with_id)}
-
- context 'when the metric configuration exists' do
- before :each do
- KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).returns(subject)
- end
-
- it 'should return true' do
- expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_truthy
- end
- end
-
- context 'when the metric configuration does not exist' do
- before :each do
- KalibroClient::Entities::Configurations::MetricConfiguration.expects(:find).with(subject.id).raises(KalibroClient::Errors::RecordNotFound)
- end
-
- it 'should return false' do
- expect(KalibroClient::Entities::Configurations::MetricConfiguration.exists?(subject.id)).to be_falsey
- end
- end
- end
-
- describe 'find' do
- let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
-
- context 'with an existant MetricConfiguration' do
- before :each do
- KalibroClient::Entities::Configurations::MetricConfiguration.
- expects(:request).
- with(':id', {id: metric_configuration.id}, :get).
- returns({'metric_configuration' => metric_configuration.to_hash})
- end
-
- it 'should return the metric_configuration' do
- found_metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id)
- expect(found_metric_configuration.id).to eq(metric_configuration.id)
- expect(found_metric_configuration.persisted).to be_truthy
- end
- end
-
- context 'with an inexistant MetricConfiguration' do
- before :each do
- KalibroClient::Entities::Configurations::MetricConfiguration.
- expects(:request).
- with(':id', {id: metric_configuration.id}, :get).
- raises(KalibroClient::Errors::RequestError)
- end
-
- it 'should raise the RecordNotFound error' do
- expect {KalibroClient::Entities::Configurations::MetricConfiguration.find(metric_configuration.id)}.
- to raise_error(KalibroClient::Errors::RecordNotFound)
- end
- end
- end
-
describe 'kalibro ranges' do
let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
let(:kalibro_range_1) { FactoryGirl.build(:range, metric_configuration_id: metric_configuration.id) }
diff --git a/spec/entities/configurations/reading_group_spec.rb b/spec/entities/configurations/reading_group_spec.rb
index c85f1df..8380bb9 100644
--- a/spec/entities/configurations/reading_group_spec.rb
+++ b/spec/entities/configurations/reading_group_spec.rb
@@ -26,38 +26,6 @@
end
end
- describe 'all' do
- context 'with no reading_groups' do
- before :each do
- KalibroClient::Entities::Configurations::ReadingGroup.
- expects(:request).
- with('', {}, :get).
- returns({'reading_groups' => []})
- end
-
- it 'should return nil' do
- expect(KalibroClient::Entities::Configurations::ReadingGroup.all).to be_empty
- end
- end
-
- context 'with many reading_groups' do
- let(:reading_group) { FactoryGirl.build(:reading_group_with_id) }
- before :each do
- KalibroClient::Entities::Configurations::ReadingGroup.
- expects(:request).
- with('', {}, :get).
- returns({'reading_groups' => [reading_group.to_hash, reading_group.to_hash]})
- end
-
- it 'should return nil' do
- reading_groups = KalibroClient::Entities::Configurations::ReadingGroup.all
-
- expect(reading_groups.first.name).to eq(reading_group.name)
- expect(reading_groups.last.name).to eq(reading_group.name)
- end
- end
- end
-
describe 'readings' do
let(:reading_group) { FactoryGirl.build(:reading_group_with_id) }
diff --git a/spec/entities/configurations/reading_spec.rb b/spec/entities/configurations/reading_spec.rb
index 6e92970..2737ff9 100644
--- a/spec/entities/configurations/reading_spec.rb
+++ b/spec/entities/configurations/reading_spec.rb
@@ -52,7 +52,7 @@
before :each do
KalibroClient::Entities::Configurations::Reading.
expects(:request).
- with('', {reading: reading.to_hash, reading_group_id: reading.reading_group_id}, :post, "reading_groups/#{reading.reading_group_id}").
+ with('', {reading: reading.to_hash, reading_group_id: reading.reading_group_id}, :post, "reading_groups/#{reading.reading_group_id}", {}).
returns("reading" => {'id' => reading_id, 'kalibro_errors' => []})
end
@@ -70,7 +70,7 @@
before :each do
KalibroClient::Entities::Configurations::Reading.
expects(:request).
- with(":id", {id: subject.id}, :delete, "reading_groups/#{subject.reading_group_id}").returns({})
+ with(":id", {id: subject.id}, :delete, "reading_groups/#{subject.reading_group_id}", {}).returns({})
end
it 'should make a request to destroy' do
@@ -85,7 +85,7 @@
before :each do
KalibroClient::Entities::Configurations::Reading.
expects(:request).
- with(":id", {reading: subject.to_hash, id: subject.id}, :put, "reading_groups/#{subject.reading_group_id}").returns({})
+ with(":id", {reading: subject.to_hash, id: subject.id}, :put, "reading_groups/#{subject.reading_group_id}", {}).returns({})
end
it 'should make a request to update' do
diff --git a/spec/entities/processor/metric_collector_details_spec.rb b/spec/entities/processor/metric_collector_details_spec.rb
index 6e6b842..aff5708 100644
--- a/spec/entities/processor/metric_collector_details_spec.rb
+++ b/spec/entities/processor/metric_collector_details_spec.rb
@@ -52,41 +52,6 @@
end
end
- describe 'all' do
- context 'with no metric collector details' do
- before :each do
- KalibroClient::Entities::Processor::MetricCollectorDetails.
- expects(:request).
- with('', {}, :get).
- returns({"metric_collector_details" => []})
- end
-
- it 'should return empty array' do
- expect(KalibroClient::Entities::Processor::MetricCollectorDetails.all).to be_empty
- end
- end
-
- context 'with many metric collector details' do
- let!(:metric_collector_details_hash) { FactoryGirl.attributes_for(:metric_collector_details) }
- let!(:another_metric_collector_details_hash) { FactoryGirl.attributes_for(:another_metric_collector_details) }
-
- before :each do
- KalibroClient::Entities::Processor::MetricCollectorDetails.
- expects(:request).
- with('', {}, :get).
- returns({"metric_collector_details" => [metric_collector_details_hash, another_metric_collector_details_hash]})
- end
-
- it 'should return the two elements' do
- metric_collector_details = KalibroClient::Entities::Processor::MetricCollectorDetails.all
-
- expect(metric_collector_details.size).to eq(2)
- expect(metric_collector_details.first.name).to eq(metric_collector_details_hash[:name])
- expect(metric_collector_details.last.name).to eq(another_metric_collector_details_hash[:name])
- end
- end
- end
-
describe 'find_by_name' do
subject { FactoryGirl.build(:metric_collector_details) }
@@ -95,7 +60,7 @@
KalibroClient::Entities::Processor::MetricCollectorDetails.
expects(:find_by_name!).
with(subject.name).
- raises(KalibroClient::Errors::RecordNotFound)
+ raises(Likeno::Errors::RecordNotFound)
end
it 'is expected to return nil' do
@@ -125,12 +90,12 @@
KalibroClient::Entities::Processor::MetricCollectorDetails.
expects(:request).
with(:find, {name: subject.name}).
- raises(KalibroClient::Errors::RecordNotFound)
+ raises(Likeno::Errors::RecordNotFound)
end
it 'should raise a RecordNotFound error' do
expect { KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name!(subject.name)}.
- to raise_error(KalibroClient::Errors::RecordNotFound)
+ to raise_error(Likeno::Errors::RecordNotFound)
end
end
@@ -181,7 +146,7 @@
let(:metric) { subject.supported_metrics["loc"] }
it 'should return nil with an inexistent name' do
- expect { subject.find_metric_by_name!("fake name") }.to raise_error(KalibroClient::Errors::RecordNotFound)
+ expect { subject.find_metric_by_name!("fake name") }.to raise_error(Likeno::Errors::RecordNotFound)
end
it 'should return a metric with an existent name' do
@@ -207,7 +172,7 @@
let(:metric) { subject.supported_metrics["loc"] }
it 'should return nil with an inexistent code' do
- expect{subject.find_metric_by_code!("fake code")}.to raise_error(KalibroClient::Errors::RecordNotFound)
+ expect{subject.find_metric_by_code!("fake code")}.to raise_error(Likeno::Errors::RecordNotFound)
end
it 'should return a metric with an existent code' do
diff --git a/spec/entities/processor/module_result_spec.rb b/spec/entities/processor/module_result_spec.rb
index cf566ff..5d3aca8 100644
--- a/spec/entities/processor/module_result_spec.rb
+++ b/spec/entities/processor/module_result_spec.rb
@@ -223,45 +223,4 @@
expect(subject.processing).to eq(processing)
end
end
-
- describe 'find' do
- let(:id) { 1 }
-
- context 'when the ModuleResult exists' do
- let!(:module_result) { FactoryGirl.build(:module_result) }
- before :each do
- KalibroClient::Entities::Base.expects(:find).with(id).returns(module_result)
- end
-
- it 'is expected to return the found module result' do
- expect(described_class.find(id)).to eq(module_result)
- end
- end
-
- context 'when the ModuleResult does not exist' do
- before :each do
- response = mock('response')
- response.expects(:status).at_least_once.returns(422)
-
- KalibroClient::Entities::Base.expects(:find).with(id).raises(KalibroClient::Errors::RequestError.new(response: response))
- end
-
- it 'is expected to raise a RecordNotFound error' do
- expect { described_class.find(id) }.to raise_error(KalibroClient::Errors::RecordNotFound)
- end
- end
-
- context 'when there is an unexpected server error' do
- before :each do
- response = mock('response')
- response.expects(:status).at_least_once.returns(500)
-
- KalibroClient::Entities::Base.expects(:find).with(id).raises(KalibroClient::Errors::RequestError.new(response: response))
- end
-
- it 'is expected to raise a RequestError' do
- expect { described_class.find(id) }.to raise_error(KalibroClient::Errors::RequestError)
- end
- end
- end
end
diff --git a/spec/entities/processor/project_spec.rb b/spec/entities/processor/project_spec.rb
index 836b258..8f36311 100644
--- a/spec/entities/processor/project_spec.rb
+++ b/spec/entities/processor/project_spec.rb
@@ -31,40 +31,6 @@
end
end
- describe 'all' do
- context 'with no projects' do
- before :each do
- KalibroClient::Entities::Processor::Project.
- expects(:request).
- with('', {}, :get).
- returns({"projects" => []})
- end
-
- it 'should return nil' do
- expect(KalibroClient::Entities::Processor::Project.all).to be_empty
- end
- end
-
- context 'with many projects' do
- let(:project) { FactoryGirl.build(:project) }
- let(:another_project) { FactoryGirl.build(:another_project) }
-
- before :each do
- KalibroClient::Entities::Processor::Project.
- expects(:request).
- with('', {}, :get).
- returns({"projects" => [project.to_hash, another_project.to_hash]})
- end
-
- it 'should return a list with projects' do
- projects = KalibroClient::Entities::Processor::Project.all
-
- expect(projects.first.name).to eq(project.name)
- expect(projects.last.name).to eq(another_project.name)
- end
- end
- end
-
describe 'repositories' do
let(:project) { FactoryGirl.build(:project) }
let(:repository) { FactoryGirl.build(:repository) }
@@ -102,7 +68,7 @@
before :each do
KalibroClient::Entities::Processor::Project.
expects(:request).
- with(':id', {project: {"name" => "Another Name", "description" => subject.description, "id" => subject.id.to_s}, id: subject.id}, :put, '').
+ with(':id', {project: {"name" => "Another Name", "description" => subject.description, "id" => subject.id.to_s}, id: subject.id}, :put, '', {}).
returns({"project" => {"id" => subject.id, "name" => "Another Name", "kalibro_errors" => []}})
end
diff --git a/spec/entities/processor/repository_spec.rb b/spec/entities/processor/repository_spec.rb
index a5b812a..9f629c1 100644
--- a/spec/entities/processor/repository_spec.rb
+++ b/spec/entities/processor/repository_spec.rb
@@ -99,19 +99,6 @@
end
end
- describe 'all' do
- before :each do
- KalibroClient::Entities::Processor::Repository.
- expects(:request).
- with("", {}, :get).
- returns({'repositories' => [subject.to_hash]})
- end
-
- it 'should list all the repositories' do
- expect(KalibroClient::Entities::Processor::Repository.all).to include(subject)
- end
- end
-
# The only purpose of this test is to cover the overrided save_params method
describe 'save' do
subject {FactoryGirl.build(:repository)}
@@ -119,7 +106,7 @@
before :each do
KalibroClient::Entities::Processor::Repository.
expects(:request).
- with('', {:repository => subject.to_hash, :project_id => 1}, :post, '').
+ with('', {:repository => subject.to_hash, :project_id => 1}, :post, '', {}).
returns("repository" => {'id' => 1, 'kalibro_errors' => []})
KalibroClient::Entities::Processor::Repository.any_instance.
diff --git a/spec/errors/record_invalid_spec.rb b/spec/errors/record_invalid_spec.rb
deleted file mode 100644
index ffcef3a..0000000
--- a/spec/errors/record_invalid_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-require 'spec_helper'
-
-describe KalibroClient::Errors::RecordInvalid do
- describe 'initialize' do
- let(:default_message){ "Record invalid" }
-
- context 'without a record' do
- subject { KalibroClient::Errors::RecordInvalid.new }
-
- it 'is expected to have the default message' do
- expect(subject.message).to eq(default_message)
- end
- end
-
- context 'with a given record' do
- let!(:record) { mock('record') }
- let!(:kalibro_errors) { ['Kalibro', 'Error'] }
- subject { KalibroClient::Errors::RecordInvalid.new(record) }
-
- before :each do
- record.expects(:kalibro_errors).returns(kalibro_errors)
- end
-
- it 'is expected to return the default message concatenated with the errors' do
- expect(subject.message).to eq("#{default_message}: #{kalibro_errors.join(', ')}")
- end
- end
- end
-end
\ No newline at end of file
diff --git a/spec/helpers/date_attributes_spec.rb b/spec/helpers/date_attributes_spec.rb
deleted file mode 100644
index 580a536..0000000
--- a/spec/helpers/date_attributes_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require 'spec_helper'
-require 'kalibro_client/helpers/date_attributes'
-
-include DateAttributes
-
-class Klass
- include DateAttributes
-end
-
-
-describe 'DateAttributes' do
- subject { Klass.new }
- let(:time){ "2015-02-04T15:53:18.452Z" }
-
- describe 'created_at=' do
- it 'is expected to parse it to DateTime' do
- DateTime.expects(:parse).with(time)
-
- subject.created_at = time
- end
- end
-
- describe 'updated_at=' do
- it 'is expected to parse it to DateTime' do
- DateTime.expects(:parse).with(time)
-
- subject.updated_at = time
- end
- end
-end
\ No newline at end of file
diff --git a/spec/helpers/hash_converters_spec.rb b/spec/helpers/hash_converters_spec.rb
deleted file mode 100644
index bffa649..0000000
--- a/spec/helpers/hash_converters_spec.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-require 'spec_helper'
-require 'kalibro_client/helpers/hash_converters'
-
-include HashConverters
-
-describe HashConverters do
- describe 'date_with_miliseconds' do
- context 'with 21/12/1995 (first Ruby publication)' do
- it 'should return 1995-12-21T00:00:00.0/1+00:00' do
- expect(date_with_milliseconds(DateTime.parse("21/12/1995"))).to eq("1995-12-21T00:00:00.0/1+00:00")
- end
- end
- end
-
- describe 'convert_to_hash' do
- context 'with a nil value' do
- it 'should return nil' do
- expect(convert_to_hash(nil)).to be_nil
- end
- end
-
- context 'with an Array' do
- before :each do
- @array = []
- @element1 = :kalibro
-
- @array << @element1
- end
-
- it 'should return the Array wth its elements converted' do
- expect(convert_to_hash(@array)[0]).to eq(@element1.to_s)
- end
- end
-
- context 'with a Base' do
- before :each do
- @model = KalibroClient::Entities::Base.new
- end
-
- it "should return the Base's Hash" do
- expect(convert_to_hash(@model)).to eq(@model.to_hash)
- end
- end
-
- context 'with a DateTime' do
- before :each do
- @date = DateTime.parse("21/12/1995")
- end
-
- it 'should return th date with miliseconds' do
- expect(convert_to_hash(@date)).to eq(date_with_milliseconds(@date))
- end
- end
-
- context 'with an + infinite Float' do
- it 'should return INF' do
- expect(convert_to_hash(1.0/0.0)).to eq('INF')
- end
- end
-
- context 'with an - infinite Float' do
- it 'should return -INF' do
- expect(convert_to_hash(-1.0/0.0)).to eq('-INF')
- end
- end
-
- context 'with a granularity' do
- let(:granularity) { FactoryGirl.build(:granularity) }
-
- it 'is expected to convert the granularity to a hash' do
- expect(convert_to_hash(granularity)).to be_a Hash
- expect(convert_to_hash(granularity)).to include 'type'
- end
- end
- end
-
- describe 'field_to_hash' do
- context 'with a nil field value' do
- before do
- @model = KalibroClient::Entities::Base.new
- @model.expects(:send).with(:field_getter).returns(nil)
- end
-
- it 'should return an instance of Hash' do
- expect(@model.field_to_hash(:field_getter)).to be_a(Hash)
- end
-
- it 'should return an empty Hash' do
- expect(@model.field_to_hash(:field_getter)).to eq({})
- end
- end
-
- context 'with a Float field value' do
- before do
- @model = KalibroClient::Entities::Base.new
- @model.expects(:send).with(:field_getter).returns(1.0)
- end
-
- it 'should return an instance of Hash' do
- expect(@model.field_to_hash(:field_getter)).to be_a(Hash)
- end
- end
- end
-end
diff --git a/spec/helpers/xml_converters_spec.rb b/spec/helpers/xml_converters_spec.rb
deleted file mode 100644
index 64b7d0a..0000000
--- a/spec/helpers/xml_converters_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-require 'spec_helper'
-require 'kalibro_client/helpers/xml_converters'
-
-include XMLConverters
-
-describe XMLConverters do
- describe 'xml_instance_class_name' do
- before { @model = KalibroClient::Entities::Base.new }
-
- it 'should return modelXml' do
- expect(xml_instance_class_name(@model)).to eq('baseXml')
- end
- end
-
- describe 'get_xml' do
- context 'with an object that is not an instance of Base' do
- before { @object = "kalibro" }
-
- it 'should return a Hash' do
- expect(get_xml("field", @object)).to be_a(Hash)
- end
-
- it 'should return an empty Hash' do
- expect(get_xml("field", @object)).to eq({})
- end
- end
-
- context 'with an instance of Base' do
- before { @object = KalibroClient::Entities::Base.new }
-
- it 'should return a Hash' do
- expect(get_xml("field", @object)).to be_a(Hash)
- end
-
- it 'should return the XML Hash' do
- field_xml_hash = {:attributes! =>
- {:field =>
- {"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
- "xsi:type"=>"kalibro:baseXml"
- }
- }
- }
-
- expect(get_xml("field", @object)).to eq(field_xml_hash)
- end
- end
- end
-end
diff --git a/spec/kalibro_cucumber_helpers/cleaner_spec.rb b/spec/kalibro_cucumber_helpers/cleaner_spec.rb
new file mode 100644
index 0000000..a1fd9f7
--- /dev/null
+++ b/spec/kalibro_cucumber_helpers/cleaner_spec.rb
@@ -0,0 +1,32 @@
+require 'rspec/mocks'
+require 'faraday'
+require 'likeno'
+require 'kalibro_client/kalibro_cucumber_helpers'
+
+describe KalibroClient::KalibroCucumberHelpers::Cleaner do
+ let(:address_key) { :test_address }
+ let(:likeno_config) { {address_key => 'http://test'} }
+
+ subject { described_class.new(address_key) }
+
+ describe 'endpoint' do
+ it 'is expected to return "tests"' do
+ expect(subject.endpoint).to eq('tests')
+ end
+ end
+
+ describe 'address' do
+ it 'is expected to find the address in Likeno' do
+ Likeno.expects(:config).returns likeno_config
+ expect(subject.address).to eq(likeno_config[address_key])
+ end
+ end
+
+ describe 'clean_database' do
+ it 'is expected to make a request to the correct address' do
+ subject.expects(:request).with('clean_database', {}, :post)
+
+ subject.clean_database
+ end
+ end
+end
diff --git a/spec/kalibro_entities_spec.rb b/spec/kalibro_entities_spec.rb
deleted file mode 100644
index 3dac586..0000000
--- a/spec/kalibro_entities_spec.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-# This file is part of KalibroClient
-# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-require 'spec_helper'
-
-describe KalibroClient do
-
- context 'configuration' do
- #FIXME: there should be a better way to keep the default values
- let(:config) { { processor_address: "http://localhost:8082",
- configurations_address: "http://localhost:8083" } }
-
- describe 'config' do
- it 'should return the default configuration' do
- expect(KalibroClient.config).to eq({
- processor_address: "http://localhost:8082",
- configurations_address: "http://localhost:8083"
- })
- end
- end
-
- describe 'configure' do
- after(:each) {KalibroClient.configure(config)}
-
- it 'should set the address' do
- KalibroClient.configure({processor_address: 'http://test.test'})
- expect(KalibroClient.config[:processor_address]).to eq('http://test.test')
- end
- end
-
- describe 'configure_with' do
- context 'with an existent YAML' do
- after(:each) {KalibroClient.configure(config)}
-
- it 'should set the config' do
- KalibroClient.configure_with('spec/fixtures/config.yml')
-
- expect(KalibroClient.config).to eq({
- processor_address: 'http://test1.test1',
- configurations_address: 'http://test2.test2'})
- end
- end
-
- context 'with an inexistent YAML' do
- before :each do
- @logger = Logger.new(File::NULL)
- KalibroClient.expects(:logger).returns(@logger)
- end
-
- it 'should keep the defaults' do
- KalibroClient.configure_with('spec/fixtures/inexistent_file.yml')
- expect(KalibroClient.config).to eq(config)
- end
-
- it 'should log an warning' do
- @logger.expects(:warn).with("YAML configuration file couldn't be found. Using defaults.")
-
- KalibroClient.configure_with('spec/fixtures/inexistent_file.yml')
- end
- end
-
- context 'with an invalid YAML' do
- before :each do
- @logger = Logger.new(File::NULL)
- KalibroClient.expects(:logger).returns(@logger)
- end
-
- it 'should keep the defaults' do
- KalibroClient.configure_with('spec/fixtures/invalid_config.yml')
- expect(KalibroClient.config).to eq(config)
- end
-
- it 'should log an warning' do
- @logger.expects(:warn).with("YAML configuration file contains invalid syntax. Using defaults.")
-
- KalibroClient.configure_with('spec/fixtures/invalid_config.yml')
- end
- end
- end
- end
-
- context 'Logger' do
- describe 'logger' do
- it 'should return the default logger' do
- expect(KalibroClient.logger).to be_a(Logger)
- end
- end
-
- describe 'logger=' do
- it 'should set the logger' do
- logger = Logger.new(STDOUT)
-
- KalibroClient.logger = logger
-
- expect(KalibroClient.logger).to eq(logger)
- end
- end
- end
-end