tax_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.inch.yml +10 -0
  4. data/.reek +10 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +72 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +154 -0
  9. data/LICENSE +20 -0
  10. data/README.md +131 -0
  11. data/Rakefile +26 -0
  12. data/bin/tax_generator +7 -0
  13. data/data/input/.gitignore +25 -0
  14. data/data/input/destinations.xml +1073 -0
  15. data/data/input/taxonomy.xml +78 -0
  16. data/data/output/.gitignore +4 -0
  17. data/init.rb +1 -0
  18. data/lib/tax_generator/all.rb +26 -0
  19. data/lib/tax_generator/application.rb +125 -0
  20. data/lib/tax_generator/classes/destination.rb +103 -0
  21. data/lib/tax_generator/classes/file_creator.rb +100 -0
  22. data/lib/tax_generator/classes/processor.rb +270 -0
  23. data/lib/tax_generator/classes/taxonomy_tree.rb +97 -0
  24. data/lib/tax_generator/cli.rb +14 -0
  25. data/lib/tax_generator/helpers/application_helper.rb +154 -0
  26. data/lib/tax_generator/version.rb +27 -0
  27. data/lib/tax_generator.rb +1 -0
  28. data/spec/lib/tax_generator/application_spec.rb +0 -0
  29. data/spec/lib/tax_generator/classes/destination_spec.rb +62 -0
  30. data/spec/lib/tax_generator/classes/file_creator_spec.rb +96 -0
  31. data/spec/lib/tax_generator/classes/processor_spec.rb +30 -0
  32. data/spec/lib/tax_generator/classes/taxonomy_tree_spec.rb +0 -0
  33. data/spec/lib/tax_generator/cli_spec.rb +0 -0
  34. data/spec/lib/tax_generator/helpers/application_helper_spec.rb +0 -0
  35. data/spec/spec_helper.rb +60 -0
  36. data/tax_generator.gemspec +40 -0
  37. data/templates/static/all.css +586 -0
  38. data/templates/template.html.erb +91 -0
  39. metadata +452 -0
@@ -0,0 +1,96 @@
1
+ # encoding:utf-8
2
+ require 'spec_helper'
3
+ describe TaxGenerator::FileCreator do
4
+ let(:default_processor) {TaxGenerator::Processor.new}
5
+ let(:output_folder) {"some_other_path" }
6
+ let(:destinations_file_path) { "some_path" }
7
+ let(:destination_xml) { "some_xml" }
8
+ let(:subject) { TaxGenerator::FileCreator.new }
9
+ let(:first_destination) { "some destination" }
10
+
11
+ let(:fake_node) { FakeNode.new('something') }
12
+
13
+ let(:atlas_id_value) { 'some atlas id value' }
14
+ let(:atlas_id) { AtlasID.new(atlas_id_value) }
15
+ let(:fake_tilt) {FakeTilt.new}
16
+ let(:fake_condition) {FakeCelluloidCondition.new}
17
+
18
+ let(:job) { { atlas_id: atlas_id_value, taxonomy: fake_node, destination: first_destination, output_folder: output_folder } }
19
+ before(:each) do
20
+ destination_xml.stubs(:at_xpath).returns(fake_node)
21
+ destination_xml.stubs(:xpath).returns([fake_node])
22
+ subject.stubs(:start_work).returns(true)
23
+ subject.stubs(:log_message).returns(true)
24
+ default_processor.stubs(:register_worker_for_job).returns(true)
25
+ File.stubs(:open).returns(true)
26
+ Tilt.stubs(:new).returns(fake_tilt)
27
+ fake_tilt.stubs(:render).returns(true)
28
+ subject.stubs(:mark_job_completed).returns(true)
29
+ default_processor.stubs(:condition).returns(fake_condition)
30
+ default_processor.stubs(:all_workers_finished).returns(false)
31
+ fake_condition.stubs(:signal).returns(true)
32
+ end
33
+
34
+ context 'checks the job keys' do
35
+ before(:each) do
36
+ subject.work(job, default_processor)
37
+ end
38
+
39
+ specify { expect(subject.job).to eq job.stringify_keys }
40
+ specify { expect(subject.processor).to eq default_processor }
41
+ end
42
+
43
+ context 'processes the job' do
44
+ before(:each) do
45
+ subject.process_job(job)
46
+ end
47
+
48
+ specify { expect(subject.job_id).to eq atlas_id_value }
49
+ specify { expect(subject.destination).to eq first_destination }
50
+ specify { expect(subject.output_folder).to eq(output_folder) }
51
+ specify { expect(subject.taxonomy).to eq(fake_node) }
52
+ end
53
+
54
+ it 'gets the template name' do
55
+ File.expects(:join).with(root, 'templates', 'template.html.erb')
56
+ subject.template_name
57
+ end
58
+
59
+ context "job related " do
60
+
61
+ before(:each) do
62
+ subject.work(job, default_processor)
63
+ default_processor.stubs(:register_worker_for_job).returns(true)
64
+ end
65
+
66
+ it 'gets start work' do
67
+ details = {details: fake_node, root: root}
68
+ Actor.stubs(:current).returns(subject)
69
+ subject.stubs(:fetch_atlas_details).returns(details)
70
+ fake_tilt.stubs(:render).with(subject,details).returns(true)
71
+ subject.start_work
72
+ end
73
+
74
+ it 'mark_job_completed' do
75
+ default_processor.jobs.expects(:[]).with(subject.job_id).returns(job)
76
+ job.expects(:[]=).with('status', 'finished')
77
+ default_processor.expects(:all_workers_finished).returns(false)
78
+ subject.mark_job_completed
79
+ end
80
+
81
+ it 'mark_job_completed and signals complete' do
82
+ default_processor.expects(:all_workers_finished).returns(true)
83
+ fake_condition.stubs(:signal).with('completed')
84
+ subject.mark_job_completed
85
+ end
86
+
87
+ it 'fetch_atlas_details' do
88
+ subject.taxonomy.expects(:[]).with(subject.job_id).returns(fake_node)
89
+ TaxGenerator::Destination.expects(:new).with(first_destination).returns(first_destination)
90
+ first_destination.stubs(:to_hash).returns({})
91
+ actual = subject.fetch_atlas_details
92
+ expect(actual).to eq({details: fake_node, root: root})
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,30 @@
1
+ # encoding:utf-8
2
+ require 'spec_helper'
3
+ describe TaxGenerator::Processor do
4
+ let(:subject) {TaxGenerator::Processor.new}
5
+
6
+ # it 'parses the xml' do
7
+ # subject.expects(:nokogiri_xml).with(destinations_file_path).returns(destination_xml)
8
+ # actual = subject.destinations
9
+ # expect(actual).to eq destination_xml
10
+ # end
11
+ #
12
+ # it 'generates the files with 0' do
13
+ # subject.expects(:create_file).with(0, taxonomy, nil).returns(true)
14
+ # subject.generate_files(taxonomy)
15
+ # end
16
+ #
17
+ # it 'searches the destinations' do
18
+ # subject.destinations.expects(:xpath).with('//destination').returns([])
19
+ # subject.generate_files(taxonomy)
20
+ # end
21
+ #
22
+ # it 'tries to create all the files for all destinations' do
23
+ # destination_xml.xpath('//destination').each do |destination|
24
+ # destination.expects(:attributes).returns('atlas_id' => atlas_id)
25
+ # subject.expects(:create_file).with(atlas_id.value, taxonomy, destination).returns(true)
26
+ # end
27
+ # subject.generate_files(taxonomy)
28
+ # end
29
+
30
+ end
File without changes
@@ -0,0 +1,60 @@
1
+ # Configure Rails Envinronment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ require 'simplecov'
5
+ require 'simplecov-summary'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(SimpleCov::Formatter::HTMLFormatter)
8
+
9
+ SimpleCov.start 'rails' do
10
+ add_filter 'spec'
11
+
12
+ at_exit {}
13
+ end
14
+
15
+ # fake class to use for elements that need atlas id as attribute
16
+ AtlasID = Struct.new(:value)
17
+
18
+ # fake class to use for elements that need atlas id as attribute
19
+ FakeNode = Struct.new(:value)
20
+
21
+ #fake class for tilt
22
+ class FakeTilt
23
+
24
+ def render(*args) end
25
+ end
26
+
27
+ require 'bundler/setup'
28
+ require 'tax_generator'
29
+ require_relative '../lib/tax_generator/helpers/application_helper'
30
+ require 'rspec'
31
+ # fake class for actors
32
+ class Actor
33
+ def self.current
34
+ end
35
+ end
36
+
37
+ class FakeCelluloidCondition
38
+
39
+ def signal
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ require 'rspec/expectations'
45
+ config.include RSpec::Matchers
46
+ config.include TaxGenerator::ApplicationHelper
47
+
48
+ config.mock_with :mocha
49
+
50
+
51
+ config.after(:suite) do
52
+ if SimpleCov.running
53
+ SimpleCov::Formatter::HTMLFormatter.new.format(SimpleCov.result)
54
+
55
+ SimpleCov::Formatter::SummaryFormatter.new.format(SimpleCov.result)
56
+ end
57
+ end
58
+ end
59
+
60
+ Celluloid.logger = nil
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../lib/tax_generator/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'tax_generator'
5
+ s.version = TaxGenerator.gem_version
6
+ s.platform = Gem::Platform::RUBY
7
+ s.description = 'Tax generator is a simple XML processor and generator of HTMl files and uses celluloid to generate files in asyncronous way'
8
+ s.email = 'raoul_ice@yahoo.com'
9
+ s.homepage = 'http://github.com/bogdanRada/tax_generator/'
10
+ s.summary = 'Tax generator is a simple XML processor and generator of HTMl files and generates files asynchronously'
11
+ s.authors = ['bogdanRada']
12
+ s.date = Date.today
13
+
14
+ s.licenses = ['MIT']
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = s.files.grep(/^(spec)/)
17
+ s.require_paths = ['lib']
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+
20
+ s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.7'
21
+ s.add_runtime_dependency 'celluloid', '~> 0.16', '~> 0.16.0'
22
+ s.add_runtime_dependency 'celluloid-pmap', '~> 0.2', '~> 0.2.2'
23
+ s.add_runtime_dependency 'slop', '~> 4.2', '>= 4.2.1'
24
+ s.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.5'
25
+ s.add_runtime_dependency 'rubytree', '~> 0.9', '>= 0.9.6'
26
+ s.add_runtime_dependency 'tilt', '~> 1.4', '>= 1.4.1'
27
+
28
+ s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
29
+ s.add_development_dependency 'rspec', '~> 3.3', '>= 3.3'
30
+ s.add_development_dependency 'simplecov', '~> 0.10', '>= 0.10'
31
+ s.add_development_dependency 'simplecov-summary', '~> 0.0.4', '>= 0.0.4'
32
+ s.add_development_dependency 'mocha', '~> 1.1', '>= 1.1'
33
+
34
+ s.add_development_dependency 'rubocop', '~> 0.33', '>= 0.33'
35
+ s.add_development_dependency 'reek', '~> 3.7', '>= 3.7'
36
+ s.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7'
37
+ s.add_development_dependency 'yard-rspec', '~> 0.1', '>= 0.1'
38
+ s.add_development_dependency 'redcarpet', '~> 3.3', '>= 3.3'
39
+ s.add_development_dependency 'github-markup', '~> 1.3', '>= 1.3.3'
40
+ end