Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: fluke777/es
base: 19aaef6561
...
head fork: fluke777/es
compare: 720bee9beb
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 11, 2012
@fluke777 Fixed tests refactored the compatibility mode a little a16cdcc
@fluke777 Changed the order of Timestamp and Id in deleted entity generator. It…
… is not siginificant since ES takes the columns from CSV by name but to be less confusing.
720bee9
View
13 bin/es
@@ -156,8 +156,7 @@ command :load_deleted do |c|
filenames = Dir::glob("#{base_dir}/gen_load*.json")
end
- compatibility_mode = options[:compatibility] || false
- deleted_type = compatibility_mode ? "isDeleted" : "attribute"
+ compatibility_mode = options[:compatibility]
filenames.each do |load_config_file|
load_config = Es::Helpers.load_config(load_config_file)
@@ -169,14 +168,8 @@ command :load_deleted do |c|
deleted_source = "#{source_dir}/#{deleted_filename}"
next unless File.exist? deleted_source
next unless Es::Helpers.has_more_lines?(deleted_source)
- e = Es::Entity.new(entity.name, {
- :file => deleted_source,
- :fields => [
- Es::Field.new('Id', 'recordid'),
- Es::Field.new('Timestamp', 'timestamp'),
- Es::Field.new('IsDeleted', deleted_type)
- ]
- })
+
+ e = Es::Entity.create_deleted_entity(entity.name, :compatibility_mode => compatibility, :file => deleted_source)
e.load(PID)
if !compatibility_mode
View
20 lib/es.rb
@@ -22,7 +22,7 @@ class UnableToMerge < RuntimeError
class Timeframe
INTERVAL_UNITS = [:day, :week, :month, :year]
DAY_WITHIN_PERIOD = [:first, :last]
- attr_accessor :to, :from, :interval_unit, :interval, :day_within_period
+ attr_accessor :to, :from, :interval_unit, :interval, :day_within_period, :spec_from, :spec_to
def self.parse(spec)
if spec == 'latest' then
@@ -40,11 +40,14 @@ def initialize(spec)
@spec = spec
@to = Chronic.parse(spec[:to])
@from = spec[:from] ? Chronic.parse(spec[:from]) : to.advance(:days => -1)
+ @spec_from = spec[:from]
+ @spec_to = spec[:to]
@interval_unit = spec[:interval_unit] || :day
@interval = spec[:interval] || 1
@day_within_period = spec[:day_within_period] || :last
end
+
def validate_spec(spec)
fail IncorrectSpecificationError.new("Timeframe should have a specification") if spec.nil?
fail InsufficientSpecificationError.new("To key was not specified during the Timeframe creation") unless spec.has_key?(:to)
@@ -191,6 +194,21 @@ def to_config_file(filename)
class Entity
attr_accessor :name, :fields, :file, :timeframes, :timezone
+ def self.create_deleted_entity(name, options = {})
+ compatibility_mode = options[:compatibility_mode]
+ deleted_type = compatibility_mode ? "isDeleted" : "attribute"
+ file = options[:file]
+
+ e = Es::Entity.new(name, {
+ :file => file,
+ :fields => [
+ Es::Field.new('Timestamp', 'timestamp'),
+ Es::Field.new('Id', 'recordid'),
+ Es::Field.new('IsDeleted', deleted_type)
+ ]
+ })
+ end
+
def self.parse(spec)
entity = Entity.new(spec[:entity], {
:file => spec[:file],
View
23 spec/entity_spec.rb
@@ -1,6 +1,16 @@
require 'es'
-describe Es::Entity do
+describe "MyEntity" do
+
+ it "should generate deleted as an attribute when not in compatibility mode" do
+ entity = Es::Entity.create_deleted_entity("deleted", :compatibility_mode => false, :file => "file")
+ entity.fields.last.type.should == "attribute"
+ end
+
+ it "should generate deleted as an deleted record when in compatibility mode" do
+ entity = Es::Entity.create_deleted_entity("deleted", :compatibility_mode => true, :file => "file")
+ entity.fields.last.type.should == "isDeleted"
+ end
it "should fail if the file is not defined" do
opts = {
@@ -68,16 +78,5 @@
lambda {Es::Entity.new("User", opts)}.should raise_error(Es::IncorrectSpecificationError)
end
- it "should fail if there are multiple fields with the same name" do
- lambda {
- Es::Entity.new("User", {
- :file => 'file',
- :fields => [
- Es::Field.new("Id", 'recordid'),
- Es::Field.new("Id", 'recordid')
- ]
- })}.should raise_error(Es::IncorrectSpecificationError)
- end
-
end
View
11 spec/generate_spec.rb
@@ -20,14 +20,17 @@
@timeframe = Es::Timeframe.parse(@full_spec)
end
+ it "should have to and from from spec" do
+ @bare_timeframe.spec_from.should == "today"
+ @bare_timeframe.spec_to.should == "tomorrow"
+ end
+
it "should have to and from" do
- @bare_timeframe.from.should == "today"
- @bare_timeframe.to.should == "tomorrow"
+ @bare_timeframe.from.should == Chronic.parse('today')
+ @bare_timeframe.to.should == Chronic.parse('tomorrow')
end
it "should have all the stuff" do
- @timeframe.from.should == "today"
- @timeframe.to.should == "tomorrow"
@timeframe.interval.should == 1
@timeframe.interval_unit.should == :month
@timeframe.day_within_period.should == :last
View
27 spec/helpers_spec.rb
@@ -1,17 +1,32 @@
require 'es'
describe "helpers" do
- it "should transform the directory on webdave from filename and project PID" do
+
+ before :each do
opts = {
:file => '/a/b/user.csv',
:fields => [
Es::Field.new("User", 'recordid')
]
}
-
- entity = Es::Entity.new("Users", opts)
- Es::Helpers::load_destination_dir("1234", entity).should == "/uploads/1234/Users"
- Es::Helpers::load_destination_file(entity, :with_date => true).should =~ /^user_....-..-.._..:..:..\.csv/
- Es::Helpers::load_destination_file(entity).should =~ /^user.csv/
+
+ @entity = Es::Entity.new("Users", opts)
+ end
+
+ it "should transform the directory on webdav from filename and project PID" do
+ Es::Helpers::load_destination_dir("1234", @entity).should == "1234"
+ end
+
+ it "should prvovide the web dav path" do
+ Es::Helpers::web_dav_load_destination_dir('1234', @entity).should == "/uploads/1234"
end
+
+ it "should provide the web dav extract path" do
+ Es::Helpers::web_dav_extract_destination_dir('1234', @entity).should == "/out_1234_Users"
+ end
+
+ it "should provide the web dav extract path" do
+ Es::Helpers::extract_destination_dir('1234', @entity).should == "out_1234_Users"
+ end
+
end
View
29 spec/load_parser_spec.rb
@@ -1,4 +1,3 @@
-require 'pry'
require 'es'
describe Es::Load do
@@ -65,30 +64,4 @@
entity.fields.count == 2
end
- it "should fail if there are multiple same fields in multiple entities of the same name" do
- spec = [
- {
- :entity => "User",
- :file => "user_file",
- :fields => [
- {
- :name => "Id",
- :type => "recordid"
- }
- ]
- },
- {
- :entity => "User",
- :file => "user_2_file",
- :fields => [
- {
- :name => "Id",
- :type => "fact"
- }
- ]
- }
- ]
- lambda{load = Es::Load.parse(spec)}.should raise_error(Es::IncorrectSpecificationError)
- end
-
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.