Skip to content

Commit

Permalink
specs added
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshumishra31 committed Jun 13, 2018
1 parent faf8b36 commit 06b3529
Show file tree
Hide file tree
Showing 3,116 changed files with 243 additions and 186,635 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ bower.json

# Ignore node_modules
node_modules/
/spec/dummy/*

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ gem 'spree', github: 'spree/spree', branch: 'master'
# Provides basic authentication functionality for testing parts of your engine
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
gem 'rails-controller-testing'
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

gemspec

8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ GEM
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.3)
byebug (10.0.2)
camertron-eprun (1.1.1)
cancancan (2.2.0)
canonical-rails (0.2.3)
Expand Down Expand Up @@ -182,11 +183,6 @@ GEM
polyglot
rails (>= 4.1)
rainbow (>= 2.1.0)
delayed_job (4.1.5)
activesupport (>= 3.0, < 5.3)
delayed_job_active_record (4.1.3)
activerecord (>= 3.0, < 5.3)
delayed_job (>= 3.0, < 5)
devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -414,11 +410,11 @@ PLATFORMS

DEPENDENCIES
appraisal
byebug
capybara
capybara-screenshot
coffee-rails
database_cleaner
delayed_job_active_record
factory_bot
ffaker
mysql2
Expand Down
3 changes: 0 additions & 3 deletions app/models/spree/stock_item_decorator.rb

This file was deleted.

39 changes: 19 additions & 20 deletions app/services/notify_failed_stocks_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@ class NotifyFailedStocksService

def initialize(stock_updater_id)
@errors = Hash.new(Array.new())
stock_updater = Spree::StockUpdater.find(stock_updater_id)
@file = stock_updater.data_file
@stock_updater = Spree::StockUpdater.find_by(id: stock_updater_id)
update_stocks
stock_updater.update_column(:job_executed, true)
Spree::StockUpdaterMailer.update_admin(@errors, stock_updater).deliver_now
stock_updater.destroy if stock_updater.job_executed?
@stock_updater.update_column(:job_executed, true)
Spree::StockUpdaterMailer.update_admin(@errors, @stock_updater).deliver_now
@stock_updater.destroy if @stock_updater.job_executed?
end

private
def update_stocks
CSV.foreach(@file.path, headers: true) do |row|
CSV.foreach(@stock_updater.data_file.path, headers: true) do |row|
@row = row
find_variant_and_stock_location
if @variant && @stock_location
@stock_item = Spree::StockItem.find_by(variant_id: @variant.id, stock_location_id: @stock_location.id)
if @stock_item
set_backorderable(@row['backorderable'].to_s.downcase)
set_count_on_hand
update_stock_item
else
@errors['stock_items'] += ["#{row['uid']} and #{row['stock_location_name']} "]
end
update_stocks_with_csv_values
else
if @variant
@errors['stock_location'] += [row['stock_location_name']]
@errors['stock_location'] += [@row['stock_location_name']]
else
@errors['variant'] += [row['uid']]
@errors['variant'] += [@row['uid']]
end
end
end
end

def update_stocks_with_csv_values
if @stock_item
set_backorderable(@row['backorderable'].to_s.downcase)
set_count_on_hand
update_stock_item
else
@errors['stock_items'] += ["#{@row['uid']} and #{@row['stock_location_name']}"]
end
end

def find_variant_and_stock_location
@variant = Spree::Variant.find_by_sku(@row['uid'].to_s.upcase) || Spree::Variant.find_by_id(@row['uid'])
@stock_location = Spree::StockLocation.find_by_name(@row['stock_location_name'])
Expand All @@ -52,11 +55,7 @@ def set_backorderable(csv_backorderable)
end

def set_count_on_hand
if @row['count_on_hand']
@count_on_hand = @row['count_on_hand'].to_i
else
@count_on_hand = @stock_item.count_on_hand
end
@count_on_hand = @row['count_on_hand'].scan(/\D/).empty? ? @row['count_on_hand'] : @stock_item.count_on_hand
end

def update_stock_item
Expand Down
33 changes: 33 additions & 0 deletions app/views/spree/shared/_base_mailer_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- You can override this template to design your own header. -->
<table class="row header">
<tr>
<td class="center" align="center">
<center>

<table class="container">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>
<td class="twelve sub-columns last">
<% if frontend_available? %>
<%= link_to root_url, class: 'template-label' do %>
<%= image_tag Spree::Config.logo, class: 'logo', alt: Spree::Store.current.name, title: Spree::Store.current.name %>
<% end %>
<% else %>
<%= image_tag Spree::Config.logo, class: 'logo', alt: Spree::Store.current.name, title: Spree::Store.current.name %>
<% end %>
</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>

</center>
</td>
</tr>
</table>
20 changes: 12 additions & 8 deletions app/views/spree/stock_updater_mailer/update_admin.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<div>
<h5>Following Records could not be found. Rest all were updated successfully</h5>
<ul>
<% @errors.each do |error_name, error_values| %>
<li>
<%= "#{ error_name.pluralize.humanize } with values #{ error_values.join(', ') }" %>
</li>
<% end %>
</ul>
<% unless @errors.empty? %>
<h5>Following Records could not be found. Rest all were updated successfully</h5>
<ul>
<% @errors.each do |error_name, error_values| %>
<li>
<%= "#{ error_name.pluralize.humanize } with values #{ error_values.join(', ') }" %>
</li>
<% end %>
</ul>
<% else %>
<h5>All stocks were successfully updated.</h5>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
STOCK_CSV_FILE = {
sample_stock_file: SpreeOnePageStockManagement::Engine.root.join('lib', 'sample_csv', 'stock_items_example.csv')
}
ADMIN_EMAIL = ['[email protected]', '[email protected]']
ADMIN_EMAIL = ['[email protected]', '[email protected]', '[email protected]']
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ en:
select_stock_location: Select Stock Location
import: Import CSV Stock
example: Download Sample File
email_sent: Email with failed stock rows sent.
email_sent: Email with import data status has been mailed.
12 changes: 12 additions & 0 deletions lib/spree_one_page_stock_management/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
#
# Example adding this to your spec_helper will load these Factories for use:
# require 'spree_one_page_stock_management/factories'
factory :stock_updater, class: Spree::StockUpdater do
data_file { File.new(Rails.root + 'lib/test.csv') }
end

factory :stock_updater_with_fault_variant, class: Spree::StockUpdater do
data_file { File.new(Rails.root + 'lib/fault_variant.csv') }
end

factory :stock_updater_with_fault_stock_location, class: Spree::StockUpdater do
data_file { File.new(Rails.root + 'lib/fault_stock_location.csv') }
end

end
1 change: 0 additions & 1 deletion spec/dummy/.ruby-version

This file was deleted.

24 changes: 0 additions & 24 deletions spec/dummy/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions spec/dummy/Rakefile

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/app/assets/config/manifest.js

This file was deleted.

13 changes: 0 additions & 13 deletions spec/dummy/app/assets/javascripts/cable.js

This file was deleted.

15 changes: 0 additions & 15 deletions spec/dummy/app/assets/stylesheets/application.css

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/app/channels/application_cable/channel.rb

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/app/channels/application_cable/connection.rb

This file was deleted.

2 changes: 0 additions & 2 deletions spec/dummy/app/controllers/application_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions spec/dummy/app/helpers/application_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions spec/dummy/app/jobs/application_job.rb

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/app/mailers/application_mailer.rb

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/app/models/application_record.rb

This file was deleted.

6 changes: 0 additions & 6 deletions spec/dummy/app/models/spree/dummy_model.rb

This file was deleted.

15 changes: 0 additions & 15 deletions spec/dummy/app/views/layouts/application.html.erb

This file was deleted.

13 changes: 0 additions & 13 deletions spec/dummy/app/views/layouts/mailer.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion spec/dummy/app/views/layouts/mailer.text.erb

This file was deleted.

3 changes: 0 additions & 3 deletions spec/dummy/bin/bundle

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/bin/rails

This file was deleted.

4 changes: 0 additions & 4 deletions spec/dummy/bin/rake

This file was deleted.

33 changes: 0 additions & 33 deletions spec/dummy/bin/setup

This file was deleted.

Loading

0 comments on commit 06b3529

Please sign in to comment.