Skip to content

Commit

Permalink
fix almost all specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Holek committed Jun 8, 2014
1 parent d51113c commit 6707f46
Show file tree
Hide file tree
Showing 21 changed files with 206 additions and 104 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ group :test do
gem 'shoulda-matchers'
gem 'simplecov'
gem 'vcr'
gem 'webmock'
end
group :development do
gem 'better_errors'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.6)
arel (4.0.2)
better_errors (1.1.0)
coderay (>= 1.0.0)
Expand All @@ -64,6 +65,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
crack (0.4.2)
safe_yaml (~> 1.0.0)
curb (0.8.5)
daemons (1.1.9)
debug_inspector (0.0.2)
Expand Down Expand Up @@ -150,6 +153,7 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
safe_yaml (1.0.3)
sass (3.3.7)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -196,6 +200,9 @@ GEM
rack
raindrops (~> 0.7)
vcr (2.9.0)
webmock (1.18.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)

PLATFORMS
ruby
Expand Down Expand Up @@ -230,3 +237,4 @@ DEPENDENCIES
uglifier
unicorn
vcr
webmock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ChangeDocumentTypeLimitInMappings < ActiveRecord::Migration
def up
change_column :mappings, :document_type, :string, limit: 12
end

def down
change_column :mappings, :document_type, :string, limit: 10
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140524131520) do
ActiveRecord::Schema.define(version: 20140608102213) do

create_table "attachments", force: true do |t|
t.string "filename", limit: 100
Expand Down Expand Up @@ -65,7 +65,7 @@
t.datetime "updated_at"
t.string "import_type"
t.string "document_id", limit: 22
t.string "document_type", limit: 10
t.string "document_type", limit: 12
end

end
4 changes: 0 additions & 4 deletions spec/controllers/imports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
describe ImportsController do
render_views

before(:each) do
stub_sk_contact
end

context "for unauthenticated user" do
describe "GET #index" do
it "triggers access_denied" do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/attachments.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :attachment do
uploaded_data { file_upload('test1.csv') }
column_separator ';'
column_separator ','
quote_character '"'
encoding 'utf-8'
association :mapping
Expand Down
9 changes: 7 additions & 2 deletions spec/factories/mapping_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
source 4
target 'gender'
conversion_type 'enum'
conversion_options "{\"male\":\"Herr\",\" female\":\"Frau\"}"
conversion_options JSON.parse("{\"male\":\"Herr\",\" female\":\"Frau\"}")
end

factory :birthday_mapping_element do
source 5
target 'birthday'
conversion_type 'date'
conversion_options "{\"date\":\"%Y-%M-%d\"}"
conversion_options JSON.parse("{\"date\":\"%Y-%M-%d\"}")
end

factory :line_item_mapping_element do
Expand All @@ -41,6 +41,11 @@
target 'description'
conversion_type 'join'
end

factory :price_line_item_mapping_element do
conversion_type 'price'
target 'price_single'
end
end
end
end
3 changes: 2 additions & 1 deletion spec/factories/mappings.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FactoryGirl.define do
factory :mapping do
import_type 'invoice'
import_type 'document'
document_type 'invoice'
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed spec/fixtures/google_native_test_.csv
Binary file not shown.
4 changes: 0 additions & 4 deletions spec/fixtures/google_outlook_test.csv

This file was deleted.

4 changes: 2 additions & 2 deletions spec/fixtures/test1.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"Firma";"Information";"Vormerkung";"Anrede";"Titel";"Vorname";"Name";"Mailing";"ZustellStrasse";"ZustellPLZ";"ZustellOrt";"Staat";"Email";"Geburtstag";"Kundennummer";"Telefon1";"Telefax";"Handy";"SStichwort1";"SStichwort2";"SStichwort3";"SStichwort4";"SStichwort5";"BAttr:Vorname";"BAttr:Nachname";"BAttr:E-Mail-Adresse";"BAttr:Rufnummer";"BAttr:Faxnummer"
;;"";"Herr";;"Theo";"Heineman";;"Hubertstr. 205";"83620";"Feldkirchen";;;;"1721";"08063-98766543";" ";;"Messe";"Presse";;;;;;;;
Order Date,Order ID,Title,Category,ASIN/ISBN,Release Date,Condition,Seller,List Price Per Unit,Purchase Price Per Unit,Quantity,Payment - Last 4 Digits,Purchase Order Number,Ordering Customer Email,Shipment Date,Shipping Address Name,Shipping Address Street 1,Shipping Address Street 2,Shipping Address City,Shipping Address State,Shipping Address Zip,Order Status,Carrier Name & Tracking Number,Item Subtotal,Item Subtotal Tax,Buyer Name
01/05/12,002-3913772-6927453,Sandisk 32GB MicroSDHC Micro SD Card with MicroSD to SD adapter & Mobilemate Reader,Personal Computers,B003XKWLSS,,new,BoBotechnic,$32.79,$32.79,1,Gift Certificate/Card,,[email protected],01/07/12,Some Body,42 High Street Lower,,Dublin,,12,Shipped,,$32.79,$0.00,Some Body
10 changes: 0 additions & 10 deletions spec/models/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,4 @@
attachment.rows(1).size.should == 1
end

describe 'formats' do
{'google_native_test_.csv' => 3, 'google_outlook_test.csv' => 3, 'test1.csv' => 2}.each do |csv_file, count|
it "should able to read #{csv_file}" do
attachment = create(:attachment, :uploaded_data => file_upload(csv_file))
attachment.rows.first.size.should be > 1
attachment.rows.size.should == count
end
end
end

end
18 changes: 18 additions & 0 deletions spec/models/data_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
describe DataRow do
it { should belong_to(:import) }

let(:import) { build(:import) }
let(:data_row) { described_class.new(import: import) }

let(:pfudor) { %w(pink fluffy unicorns dancing on rainbows) }

describe '#mapping_element_assignment' do
let(:object_to_assign) { nil }
subject { data_row.send(:mapping_element_assignment, object_to_assign, pfudor) }
Expand All @@ -22,4 +27,17 @@
end
end
end

describe '#imported_class' do
let(:attachment) { create(:attachment, mapping: mapping) }
let(:import) { build(:import, attachment: attachment) }
%w(invoice order estimate credit_note).each do |valid_class|
context "when importing to #{valid_class}" do
let(:mapping) { create(:mapping, document_type: valid_class) }

subject { data_row.send(:imported_class) }
it { should be Sk.const_get(valid_class.classify) }
end
end
end
end
31 changes: 20 additions & 11 deletions spec/models/data_rows/document_data_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@

it { should belong_to :import }

describe '#create_document' do

end

describe '#create_line_item' do

end

describe '#imported_class' do
let(:import) { build(:import) }
let(:data_row) { described_class.new(import: import) }

describe '#create_document' do
pending
end

describe '#line_item_mapping_elements' do

describe '#line_item_mapping_elements and #document_mapping_elements' do
let(:mapping) { create(:mapping) }
let!(:document_mapping_element) { create(:mapping_element, mapping: mapping) }
let!(:line_item_mapping_element) { create(:line_item_mapping_element, mapping: mapping) }
let(:attachment) { create(:attachment, mapping: mapping) }
let(:import) { build(:import, attachment: attachment) }

context 'for document' do
subject { data_row.send(:document_mapping_elements) }
it { should eq [document_mapping_element] }
end

context 'for line item' do
subject { data_row.send(:line_item_mapping_elements) }
it { should eq [line_item_mapping_element] }
end
end

describe '#mapping' do
Expand Down
19 changes: 0 additions & 19 deletions spec/models/data_rows/line_item_data_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,12 @@
end
end

describe '#imported_class' do
let(:attachment) { create(:attachment, mapping: mapping) }
let(:import) { build(:import, attachment: attachment) }
%w(invoice order estimate credit_note).each do |valid_class|
context "when importing to #{valid_class}" do
let(:mapping) { create(:mapping, import_type: valid_class) }

subject { data_row.send(:imported_class) }
it { should be Sk.const_get(valid_class.classify) }
end
end
end

describe '#line_item_mapping_elements and #document_mapping_elements' do
let(:mapping) { create(:mapping) }
let!(:document_mapping_element) { create(:mapping_element, mapping: mapping) }
let!(:line_item_mapping_element) { create(:line_item_mapping_element, mapping: mapping) }
let(:attachment) { create(:attachment, mapping: mapping) }
let(:import) { build(:import, attachment: attachment) }

context 'for document' do
subject { data_row.send(:document_mapping_elements) }
it { should eq [document_mapping_element] }
end

context 'for line item' do
subject { data_row.send(:line_item_mapping_elements) }
it { should eq [line_item_mapping_element] }
Expand Down
Loading

0 comments on commit 6707f46

Please sign in to comment.