rapids 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,7 +30,7 @@ module Rapids
30
30
  "#{sql_column_name(column,path)} #{column_type}"
31
31
  end.join(",")
32
32
 
33
- "CREATE TABLE `#{batch_table_name}` (#{columns_sql}) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
33
+ "CREATE TABLE `#{batch_table_name}` (#{columns_sql}) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=#{@model.connection.collation}"
34
34
  end
35
35
  end
36
36
  end
@@ -30,14 +30,20 @@ module Rapids
30
30
  specific_object = path.inject(row) do |memo,association|
31
31
  if memo.respond_to?(association)
32
32
  memo.send(association)
33
+ elsif memo.is_a?(Hash) && memo[association.to_s]
34
+ memo[association.to_s]
33
35
  elsif association.is_a?(String)
34
36
  memo
35
37
  end
36
38
  end
37
39
 
38
- if specific_object.respond_to?(:each)
40
+ if specific_object.is_a?(Array)
39
41
  many_attributes = specific_object.map do |s|
40
- s.instance_variable_get(:@attributes)[source_column_name]
42
+ if s.is_a?(ActiveRecord::Base)
43
+ s.instance_variable_get(:@attributes)[source_column_name]
44
+ else
45
+ s[source_column_name]
46
+ end
41
47
  end.compact
42
48
  if many_attributes.empty?
43
49
  default_on_nil(nil,destination_column)
@@ -45,7 +51,11 @@ module Rapids
45
51
  default_on_nil(many_attributes.sort.join(","),destination_column)
46
52
  end
47
53
  else
48
- val = specific_object.instance_variable_get(:@attributes)[source_column_name] #speeds things up a bit since it's not typed first before being quoted
54
+ val = if specific_object.is_a?(ActiveRecord::Base)
55
+ specific_object.instance_variable_get(:@attributes)[source_column_name] #speeds things up a bit since it's not typed first before being quoted
56
+ else
57
+ specific_object[source_column_name]
58
+ end
49
59
  default_on_nil(val,destination_column)
50
60
  end
51
61
  end
@@ -1,3 +1,3 @@
1
1
  module Rapids
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -6,7 +6,7 @@ module Rapids::Batch
6
6
  batch = Rapids::Batch::DefineBatch.new
7
7
 
8
8
  create_table = CreateTable.new(Category,batch)
9
- create_table.to_sql.should == "CREATE TABLE `$categories_batch` (`category` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
9
+ create_table.to_sql.should == "CREATE TABLE `$categories_batch` (`category` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"
10
10
  end
11
11
 
12
12
  it "should generate sql for a basic definition" do
@@ -14,7 +14,7 @@ module Rapids::Batch
14
14
  batch.find_or_create(:author,[:name])
15
15
 
16
16
  create_table = CreateTable.new(Post,batch)
17
- create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$author$name` varchar(255),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
17
+ create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$author$name` varchar(255),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"
18
18
  end
19
19
 
20
20
  it "should generate sql for a manual definition" do
@@ -22,7 +22,7 @@ module Rapids::Batch
22
22
  batch.find_or_create("Category",[:category])
23
23
 
24
24
  create_table = CreateTable.new(Post,batch)
25
- create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$Category$category` varchar(255),`author_id` int(11),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
25
+ create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$Category$category` varchar(255),`author_id` int(11),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"
26
26
  end
27
27
 
28
28
  it "should generate sql for a manual definition, with explicit source column" do
@@ -30,7 +30,7 @@ module Rapids::Batch
30
30
  batch.find_or_create("AltCategory",[[:name,:category]])
31
31
 
32
32
  create_table = CreateTable.new(Post,batch)
33
- create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$AltCategory$name` varchar(255),`author_id` int(11),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
33
+ create_table.to_sql.should == "CREATE TABLE `$posts_batch` (`foc$AltCategory$name` varchar(255),`author_id` int(11),`category` varchar(255),`name` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"
34
34
  end
35
35
 
36
36
  it "should generate sql for a more complicated find or create with reliances on a has_many relationship" do
@@ -38,7 +38,7 @@ module Rapids::Batch
38
38
  batch.find_or_create(:post,[:name,{:post_tags => [:tag_id]}])
39
39
 
40
40
  create_table = CreateTable.new(Comment,batch)
41
- create_table.to_sql.should == "CREATE TABLE `$comments_batch` (`body` varchar(255),`foc$post$author_id` int(11),`foc$post$category` varchar(255),`foc$post$name` varchar(255),`foc$post$post_tags$tag_id` varchar(255),`title` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8"
41
+ create_table.to_sql.should == "CREATE TABLE `$comments_batch` (`body` varchar(255),`foc$post$author_id` int(11),`foc$post$category` varchar(255),`foc$post$name` varchar(255),`foc$post$post_tags$tag_id` varchar(255),`title` varchar(255)) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"
42
42
  end
43
43
  end
44
44
  end
@@ -38,5 +38,53 @@ module Rapids::Batch
38
38
  insert_into = InsertInto.new(Post,batch,collection)
39
39
  clean_sql(insert_into.to_sql).should == "INSERT INTO `$posts_batch` (`foc$AltCategory$name`,`author_id`,`category`,`name`) VALUES ('food',NULL,'food','Dining at 323 Butter St')"
40
40
  end
41
+
42
+ describe "Without model objects" do
43
+ it "should generate sql for a simple batch definition" do
44
+ batch = Rapids::Batch::DefineBatch.new
45
+ collection = %w{food politics}.map do |category_name|
46
+ {"category" => category_name}
47
+ end
48
+
49
+ insert_into = InsertInto.new(Category,batch,collection)
50
+ clean_sql(insert_into.to_sql).should == "INSERT INTO `$categories_batch` (`category`) VALUES ('food'),('politics')"
51
+ end
52
+
53
+ it "should generate sql for a basic definition" do
54
+ batch = Rapids::Batch::DefineBatch.new
55
+ batch.find_or_create(:author,[:name])
56
+ collection = [{"name" => "Dining at 323 Butter St","category" => "food","author" => {"name" => "Joe"}}]
57
+
58
+ insert_into = InsertInto.new(Post,batch,collection)
59
+ clean_sql(insert_into.to_sql).should == "INSERT INTO `$posts_batch` (`foc$author$name`,`category`,`name`) VALUES ('Joe','food','Dining at 323 Butter St')"
60
+ end
61
+
62
+ it "should generate sql for a manual definition" do
63
+ batch = Rapids::Batch::DefineBatch.new
64
+ batch.find_or_create("Category",[:name])
65
+ collection = [{"name" => "Dining at 323 Butter St","category" => "food"}]
66
+
67
+ insert_into = InsertInto.new(Post,batch,collection)
68
+ clean_sql(insert_into.to_sql).should == "INSERT INTO `$posts_batch` (`foc$Category$category`,`author_id`,`category`,`name`) VALUES ('food',NULL,'food','Dining at 323 Butter St')"
69
+ end
70
+
71
+ it "should generate sql for a manual definition, with explicit source column" do
72
+ batch = Rapids::Batch::DefineBatch.new
73
+ batch.find_or_create("AltCategory",[[:name,:category]])
74
+ collection = [{"name" => "Dining at 323 Butter St","category" => "food"}]
75
+
76
+ insert_into = InsertInto.new(Post,batch,collection)
77
+ clean_sql(insert_into.to_sql).should == "INSERT INTO `$posts_batch` (`foc$AltCategory$name`,`author_id`,`category`,`name`) VALUES ('food',NULL,'food','Dining at 323 Butter St')"
78
+ end
79
+
80
+ it "should generate sql for a more complicated find or create with reliances on a has_many relationship" do
81
+ batch = Rapids::Batch::DefineBatch.new
82
+ batch.find_or_create(:post,[:name,{:post_tags => [:tag_id]}])
83
+ collection = [{"title" => "You suck","body" => "Im a troll","post" => {"name" => "I just did something cool","post_tags" => [{"tag_id" => 1},{"tag_id" => 2}]}}]
84
+
85
+ create_table = InsertInto.new(Comment,batch,collection)
86
+ create_table.to_sql.should == "INSERT INTO `$comments_batch` (`body`,`foc$post$author_id`,`foc$post$category`,`foc$post$name`,`foc$post$post_tags$tag_id`,`title`) VALUES ('Im a troll',NULL,NULL,'I just did something cool','1,2','You suck')"
87
+ end
88
+ end
41
89
  end
42
90
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapids
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-22 00:00:00 -04:00
18
+ date: 2011-08-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency