hydroponics 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # Hydroponics 0.3.5
2
+
3
+ * Added a simple UI for randomizing foreign keys, "Fuzz Key"
4
+
1
5
  # Hydroponics 0.3.4
2
6
 
3
7
  * Refactored templates into partials with a common layout in views/single
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -0,0 +1,22 @@
1
+ module Hydroponics
2
+ module Actions
3
+ # Fuzz key
4
+ #
5
+ # Randomize a given column which is a foreign key
6
+ def fuzz_key(table, data)
7
+ table = table.to_sym
8
+ data.stringify_keys!
9
+ foreign_table = data['foreign_table'].to_sym
10
+ foreign_key_col = data['foreign_key'] || (foreign_table.to_s.singularize + "_id")
11
+ foreign_key_col = foreign_key_col.to_sym
12
+
13
+ values = @db[foreign_table].map(:id)
14
+ old_data = @db[table].all
15
+ new_data = old_data.collect { |r| r[foreign_key_col] = values[rand(values.size)]; r }
16
+ @db[table].delete
17
+ @db[table].multi_insert(new_data)
18
+
19
+ @db[table].count.to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ <script type="text/javascript">
2
+ $(function() {
3
+ $("button").button();
4
+
5
+ $("button").click(function() {
6
+ var postData = {
7
+ foreign_table: j("<%= params[:foreign_table] %>")
8
+ };
9
+
10
+ if($("#foreign_key").val() != "") {
11
+ postData.foreign_key = $("#foreign_key").val();
12
+ }
13
+
14
+ $.ajax({
15
+ type: "POST",
16
+ url: "/fuzz_key/" + j("<%= @table %>"),
17
+ data: JSON.stringify(postData),
18
+ success: function(data, status, xhr) {
19
+ $("p").show();
20
+ $("p").delay(2000).fadeOut();
21
+ },
22
+ processData: false
23
+ });
24
+ });
25
+ });
26
+ </script>
27
+
28
+ <div class="column dupecontainer span-10">
29
+ <div class="fuzz-key">
30
+ <h3>Fuzz Key: <%= @table %></h3>
31
+ <p style="display:none;">done!</p>
32
+ <div id="button"><button>Fuzz</button></div>
33
+ <input id='foreign_key'></input>
34
+ </div>
35
+ </div>
@@ -19,7 +19,7 @@
19
19
 
20
20
  <link href="../dupe.css" media="screen" rel="stylesheet" type="text/css" />
21
21
 
22
- <title>Hydroponics <%= settings.version.split(".").collect(&:to_i).collect(&:to_s).join(".") %></title>
22
+ <title>Hydroponics <%= settings.version %></title>
23
23
  </head>
24
24
 
25
25
  <body class="container">
data/hydroponics.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hydroponics}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tyler Boyd"]
12
- s.date = %q{2010-11-15}
12
+ s.date = %q{2010-11-22}
13
13
  s.default_executable = %q{hydro}
14
14
  s.description = %q{A user interface to seed or destroy large quantities of data in a Rails app.}
15
15
  s.email = %q{tboyd47@gmail.com}
@@ -29,8 +29,10 @@ Gem::Specification.new do |s|
29
29
  "VERSION",
30
30
  "app/actions/dupe.rb",
31
31
  "app/actions/foreigndupe.rb",
32
+ "app/actions/fuzz_key.rb",
32
33
  "app/views/dupe.erb",
33
34
  "app/views/foreign_dupe.erb",
35
+ "app/views/fuzz_key.erb",
34
36
  "app/views/single/index.erb",
35
37
  "bin/hydro",
36
38
  "config/hydro_app.rb",
@@ -23,45 +23,28 @@ describe "HydroApp" do
23
23
  @app || HydroApp.new
24
24
  end
25
25
 
26
- describe "/dupe/*" do
27
- it "should open dupe/index.erb" do
26
+ describe "GET /action/table" do
27
+ it "should open single/index.erb" do
28
28
  get '/dupe/users'
29
29
  last_response.should be_ok
30
30
  end
31
31
 
32
+ it "should open foreigndupe/index.erb" do
33
+ get '/foreign_dupe/portfolios'
34
+ last_response.should be_ok
35
+ end
36
+
32
37
  it "should show the table's count" do
33
38
  get '/dupe/users'
34
39
  last_response.body.include?(@db[:users].count.to_s).should be_true
35
40
  end
36
41
  end
37
42
 
38
- describe "/dupe/*" do
39
- it "should copy the first row n times" do
40
- post '/dupe/users', {:count => 10}.to_json
41
- last_response.should be_ok
42
- @db[:users].count.should == 10
43
- end
44
-
43
+ describe "POST /action/table" do
45
44
  it "should return the final count on success" do
46
45
  post '/dupe/users', {:count => 10}.to_json
47
46
  last_response.body.match("10").should be_true
48
47
  end
49
48
  end
50
-
51
- describe "/foreigndupe/*" do
52
- it "should open foreigndupe/index.erb" do
53
- get '/foreign_dupe/portfolios'
54
- last_response.should be_ok
55
- end
56
- end
57
-
58
- describe "/foreign_dupe/*/*" do
59
- it "should copy the first row n times" do
60
- @db[:users].multi_insert([{:name => "ABC", :email => "123@example.com"}] * 10)
61
- post '/foreign_dupe/portfolios', {:count => 10, :foreign_table => 'users'}.to_json
62
- last_response.should be_ok
63
- @db[:portfolios].count.should == 10
64
- end
65
- end
66
49
  end
67
50
  end
@@ -124,4 +124,49 @@ describe "Hydroponics::Actions" do
124
124
  @db[:portfolios].map(:user_id)[10].should == @db[:users].map(:id)[0]
125
125
  end
126
126
  end
127
+
128
+ describe "#fuzz_key" do
129
+ before(:each) do
130
+ @db.drop_table :users if @db.table_exists?(:users)
131
+ @db.create_table :users do
132
+ primary_key :id
133
+ Integer :portfolio_id
134
+ end
135
+ @db[:users].multi_insert([{:portfolio_id => 1}] * 100)
136
+
137
+ @db.drop_table :portfolios if @db.table_exists?(:portfolios)
138
+ @db.create_table :portfolios do
139
+ primary_key :id
140
+ String :info
141
+ end
142
+ @db[:portfolios].multi_insert([{:info => "blah"}] * 5)
143
+ end
144
+
145
+ it "should distribute ids through the given column if it is an integer" do
146
+ fuzz_key('users', :foreign_table => 'portfolios')
147
+ @db[:users].map(:portfolio_id).select { |a| a == 1 }.size.should > 0 # highly unlikely that there are no 1s
148
+ end
149
+
150
+ it "should only assign real ids" do
151
+ @db[:portfolios].filter(:id => 1).delete
152
+ fuzz_key('users', :foreign_table => 'portfolios')
153
+ @db[:users].map(:portfolio_id).select { |i| i == 1 }.size.should == 0
154
+ @db[:users].map(:portfolio_id).select { |i| i > 1 }.size.should > 0
155
+ end
156
+
157
+ it "should return the table count" do
158
+ @db[:portfolios].filter(:id => 1).delete
159
+ fuzz_key('users', :foreign_table => 'portfolios').should == "100"
160
+ end
161
+
162
+ it "should allow a custom foreign key name" do
163
+ @db.drop_table :users if @db.table_exists?(:users)
164
+ @db.create_table :users do
165
+ primary_key :id
166
+ Integer :custom_id
167
+ end
168
+ @db[:users].multi_insert([{:custom_id => 1}] * 100)
169
+ fuzz_key('users', {:count => 10, :foreign_table => 'portfolios', :foreign_key => "custom_id"}).should == "100"
170
+ end
171
+ end
127
172
  end
data/static/dupe.css CHANGED
@@ -1,5 +1,5 @@
1
1
  .container {width:950px;margin:0 auto;}
2
- .dupe h3, .foreign-dupe h3 {
2
+ .dupe h3, .foreign-dupe h3, .fuzz-key h3 {
3
3
  margin: 10px 5px 10px 18px;
4
4
  color: #444;
5
5
  float: left;
@@ -18,7 +18,7 @@
18
18
  height: 130px;
19
19
  width: 501px;
20
20
  }
21
- .dupe, .foreign-dupe {
21
+ .dupe, .foreign-dupe, .fuzz-key {
22
22
  height: 106px;
23
23
  width: 500px;
24
24
  border: 1px #ddd solid;
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydroponics
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyler Boyd
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-15 00:00:00 -05:00
18
+ date: 2010-11-22 00:00:00 -05:00
19
19
  default_executable: hydro
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -139,8 +139,10 @@ files:
139
139
  - VERSION
140
140
  - app/actions/dupe.rb
141
141
  - app/actions/foreigndupe.rb
142
+ - app/actions/fuzz_key.rb
142
143
  - app/views/dupe.erb
143
144
  - app/views/foreign_dupe.erb
145
+ - app/views/fuzz_key.erb
144
146
  - app/views/single/index.erb
145
147
  - bin/hydro
146
148
  - config/hydro_app.rb