rainforest-cli 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba717beff0c92befa7902d611e480080e717c607
4
- data.tar.gz: 377bbc58b3ea971c1a028db37480245dfa808dc7
3
+ metadata.gz: a4691d682cea9f0800d51a9b83efa292c0dacccd
4
+ data.tar.gz: f213e7432e7a48f8c6d3ae797d3d5df41ab86b2d
5
5
  SHA512:
6
- metadata.gz: daa1731fd6dab4c06c3d6f5ed07a81f7104b299498476eda2b370913e86dac4ebaf4dabc799305dfd647af5a5792949154bef81e8692a68f5a640bb3e4715606
7
- data.tar.gz: 3bd19eb1863e67789b83aa6bf7597c61cf0a7d01cf442a7cc149ffb3fdad84b819e10246a4f51b64587392f549fa6e3c12fc381040f0ca7bdfa26c013b514bf8
6
+ metadata.gz: bfa83c307d2fed9acd62bac1517d55ffe8bbabba2644f753c7a2dd5b2ce6c5f4a3188c068d9c98b46de95909387d3eb905a7a3c4ff69f1e953a3958b6b4770c3
7
+ data.tar.gz: 0566f2c4a89978464b52492d38b07607a57f8f63f55604e18a6a60dd649a9b2e17316a2fa8378d18b2e51ce29e5e847ce2c984b8d314290952506a7a0f7befee
data/README.md CHANGED
@@ -14,7 +14,7 @@ You can install rainforest-cli with the [gem](https://rubygems.org/) utility.
14
14
  gem install rainforest-cli
15
15
  ```
16
16
 
17
- Alternatively, you can add to your Gemfile if you're in a ruby project.
17
+ Alternatively, you can add to your Gemfile if you're in a ruby project. This is *not recommended* for most users. The reason being that we update this gem frequently and you usually want to ensure you have the latest version.
18
18
 
19
19
  ```ruby
20
20
  gem "rainforest-cli", require: false
@@ -7,14 +7,12 @@ require 'ruby-progressbar'
7
7
  module Rainforest
8
8
  module Cli
9
9
  class CSVImporter
10
+ attr_reader :client
11
+
10
12
  def initialize name, file, token
11
13
  @generator_name = name
12
14
  @file = file
13
- @token = token
14
- end
15
-
16
- def post url, body
17
- HTTParty.post(Rainforest::Cli::API_URL + url, body: body.to_json, headers: {'Content-Type' => 'application/json', "CLIENT_TOKEN" => @token})
15
+ @client = HttpClient.new token: token
18
16
  end
19
17
 
20
18
  def row_data columns, values
@@ -34,10 +32,10 @@ module Rainforest
34
32
  raise 'Invalid schema in CSV. You must include headers in first row.' if not columns
35
33
 
36
34
  print "Creating custom step variable"
37
- response = post "/generators", { name: @generator_name, description: @generator_name, columns: columns }
38
- raise "Error creating custom step variable: #{response.code}, #{response.body}" unless response.code == 201
35
+ response = client.post "/generators", { name: @generator_name, description: @generator_name, columns: columns }
36
+ raise "Error creating custom step variable: #{response['error']}" if response['error']
39
37
  puts "\t[OK]"
40
-
38
+
41
39
  @columns = response['columns']
42
40
  @generator_id = response['id']
43
41
 
@@ -45,11 +43,11 @@ module Rainforest
45
43
  p = ProgressBar.create(title: 'Rows', total: rows.count, format: '%a %B %p%% %t')
46
44
 
47
45
  # Insert the data
48
- Parallel.each(rows, in_processes: 16, finish: lambda { |item, i, result| p.increment }) do |row|
49
- response = post("/generators/#{@generator_id}/rows", {data: row_data(@columns, row)})
50
- raise response.to_json unless response.code == 201
46
+ Parallel.each(rows, in_threads: 16, finish: lambda { |item, i, result| p.increment }) do |row|
47
+ response = client.post("/generators/#{@generator_id}/rows", {data: row_data(@columns, row)})
48
+ raise response['error'] if response['error']
51
49
  end
52
50
  end
53
51
  end
54
52
  end
55
- end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module Rainforest
2
2
  module Cli
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -0,0 +1,49 @@
1
+ describe Rainforest::Cli::CSVImporter do
2
+ let(:csv_file) { "#{File.dirname(__FILE__)}/fixtures/variables.txt" }
3
+
4
+ describe '.import' do
5
+ subject { described_class.new('variables', csv_file, 'abc123') }
6
+
7
+ let(:http_client) { double }
8
+ let(:columns) { %w(email pass) }
9
+
10
+ let(:success_response) do
11
+ {
12
+ 'id' => 12345,
13
+ 'columns' => columns.each_with_index.map { |col, i| { 'id' => i, 'name' => col } }
14
+ }
15
+ end
16
+
17
+ before do
18
+ Rainforest::Cli::HttpClient.stub(:new).and_return(http_client)
19
+ end
20
+
21
+ it 'should post the schema to the generators API' do
22
+ expect(http_client).to receive(:post)
23
+ .with('/generators', {
24
+ name: 'variables',
25
+ description: 'variables',
26
+ columns: columns.map {|col| { name: col } }
27
+ })
28
+ .and_return success_response
29
+
30
+ expect(http_client).to receive(:post)
31
+ .with('/generators/12345/rows', {
32
+ data: {
33
+ 0 => 'russ@rainforestqa.com',
34
+ 1 => 'abc123'
35
+ }
36
+ }).and_return({})
37
+
38
+ expect(http_client).to receive(:post)
39
+ .with('/generators/12345/rows', {
40
+ data: {
41
+ 0 => 'bob@example.com',
42
+ 1 => 'hunter2'
43
+ }
44
+ }).and_return({})
45
+
46
+ subject.import
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ email,pass
2
+ russ@rainforestqa.com,abc123
3
+ bob@example.com,hunter2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-30 00:00:00.000000000 Z
12
+ date: 2015-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -111,6 +111,8 @@ files:
111
111
  - lib/rainforest/cli/version.rb
112
112
  - rainforest-cli.gemspec
113
113
  - spec/cli_spec.rb
114
+ - spec/csv_importer_spec.rb
115
+ - spec/fixtures/variables.txt
114
116
  - spec/git_trigger_spec.rb
115
117
  - spec/options_spec.rb
116
118
  - spec/runner_spec.rb
@@ -141,6 +143,8 @@ specification_version: 4
141
143
  summary: Command line utility for Rainforest QA
142
144
  test_files:
143
145
  - spec/cli_spec.rb
146
+ - spec/csv_importer_spec.rb
147
+ - spec/fixtures/variables.txt
144
148
  - spec/git_trigger_spec.rb
145
149
  - spec/options_spec.rb
146
150
  - spec/runner_spec.rb