g5_updatable 0.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.
Files changed (86) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +116 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/g5_updatable/application.js +13 -0
  5. data/app/assets/stylesheets/g5_updatable/application.css +15 -0
  6. data/app/controllers/g5_updatable/application_controller.rb +4 -0
  7. data/app/controllers/g5_updatable/feed_controller.rb +9 -0
  8. data/app/helpers/g5_updatable/application_helper.rb +4 -0
  9. data/app/views/layouts/g5_updatable/application.html.erb +14 -0
  10. data/config/routes.rb +3 -0
  11. data/lib/g5_updatable.rb +5 -0
  12. data/lib/g5_updatable/client_feed_processor.rb +22 -0
  13. data/lib/g5_updatable/client_updater.rb +25 -0
  14. data/lib/g5_updatable/engine.rb +28 -0
  15. data/lib/g5_updatable/feed_mapper.rb +57 -0
  16. data/lib/g5_updatable/g5_client.rb +10 -0
  17. data/lib/g5_updatable/g5_location.rb +21 -0
  18. data/lib/g5_updatable/locations_updater.rb +29 -0
  19. data/lib/g5_updatable/version.rb +3 -0
  20. data/lib/generators/g5_updatable/install/USAGE +11 -0
  21. data/lib/generators/g5_updatable/install/install_generator.rb +13 -0
  22. data/lib/generators/g5_updatable/install/templates/g5_updatable.rb +25 -0
  23. data/lib/tasks/g5_updatable_tasks.rake +4 -0
  24. data/spec/dummy/README.rdoc +28 -0
  25. data/spec/dummy/Rakefile +6 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/models/client.rb +2 -0
  31. data/spec/dummy/app/models/location.rb +2 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/spec/dummy/bin/bundle +3 -0
  34. data/spec/dummy/bin/rails +4 -0
  35. data/spec/dummy/bin/rake +4 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/config/application.rb +23 -0
  38. data/spec/dummy/config/boot.rb +5 -0
  39. data/spec/dummy/config/database.yml +25 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +37 -0
  42. data/spec/dummy/config/environments/production.rb +82 -0
  43. data/spec/dummy/config/environments/test.rb +39 -0
  44. data/spec/dummy/config/initializers/assets.rb +8 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/spec/dummy/config/initializers/g5_updatable.rb +4 -0
  49. data/spec/dummy/config/initializers/inflections.rb +16 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  51. data/spec/dummy/config/initializers/session_store.rb +3 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +23 -0
  54. data/spec/dummy/config/routes.rb +3 -0
  55. data/spec/dummy/config/secrets.yml +22 -0
  56. data/spec/dummy/db/development.sqlite3 +0 -0
  57. data/spec/dummy/db/migrate/20140630175259_create_locations.rb +24 -0
  58. data/spec/dummy/db/migrate/20140630175330_create_clients.rb +13 -0
  59. data/spec/dummy/db/schema.rb +47 -0
  60. data/spec/dummy/db/test.sqlite3 +0 -0
  61. data/spec/dummy/log/development.log +6434 -0
  62. data/spec/dummy/log/test.log +6515 -0
  63. data/spec/dummy/public/404.html +67 -0
  64. data/spec/dummy/public/422.html +67 -0
  65. data/spec/dummy/public/500.html +66 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/spec/fabricators/client_fabricator.rb +6 -0
  68. data/spec/dummy/spec/fabricators/location_fabricator.rb +9 -0
  69. data/spec/dummy/spec/models/client_spec.rb +0 -0
  70. data/spec/dummy/spec/models/location_spec.rb +0 -0
  71. data/spec/dummy/spec/support/client_feed.html +97 -0
  72. data/spec/dummy/spec/support/updated_client_feed.html +148 -0
  73. data/spec/dummy/tmp/pids/server.pid +1 -0
  74. data/spec/fabricators/client_fabricator.rb +6 -0
  75. data/spec/fabricators/location_fabricator.rb +9 -0
  76. data/spec/lib/g5_updatable/client_feed_processor_spec.rb +38 -0
  77. data/spec/lib/g5_updatable/client_updater_spec.rb +58 -0
  78. data/spec/lib/g5_updatable/feed_mapper_spec.rb +115 -0
  79. data/spec/lib/g5_updatable/locations_updater_spec.rb +71 -0
  80. data/spec/lib/g5_updatable/version.rb +7 -0
  81. data/spec/lib/generators/g5_updatable/install_generator_spec.rb +51 -0
  82. data/spec/lib/generators/tmp/config/routes.rb +7 -0
  83. data/spec/lib/tmp/config/initializers/g5_updatable.rb +25 -0
  84. data/spec/lib/tmp/config/routes.rb +8 -0
  85. data/spec/spec_helper.rb +44 -0
  86. metadata +279 -0
@@ -0,0 +1 @@
1
+ 52393
@@ -0,0 +1,6 @@
1
+ Fabricator :client do
2
+ uid { "http://foo.com" }
3
+ name { Faker::Name.name }
4
+ vertical { "Apartments" }
5
+ domain { "http://bar.com" }
6
+ end
@@ -0,0 +1,9 @@
1
+ Fabricator :location do
2
+ uid { Faker::Internet.url }
3
+ urn { "g5-cl-2398223-#{Faker::Name.name.parameterize}" }
4
+ name { Faker::Name.name }
5
+ state { Faker::Address.state_abbr }
6
+ city { Faker::Address.city }
7
+ domain { Faker::Internet.url }
8
+ corporate { false }
9
+ end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe G5Updatable::ClientFeedProcessor do
4
+ let(:client_updater) { double(update: nil) }
5
+ let(:locations_updater) { double(update: nil) }
6
+
7
+ before do
8
+ allow(G5Updatable::ClientUpdater).to receive(:new) { client_updater }
9
+ allow(G5Updatable::LocationsUpdater).to receive(:new) { locations_updater }
10
+ end
11
+
12
+ describe "#work" do
13
+ after { described_class.new(urn).work }
14
+ let(:urn) { nil }
15
+
16
+ context "a nil urn" do
17
+ before { allow(G5Updatable).to receive(:client_identifier) { nil } }
18
+
19
+ it "does not call update on the client updater" do
20
+ expect(client_updater).to_not receive(:update)
21
+ end
22
+
23
+ it "does not call update on the locations updater" do
24
+ expect(locations_updater).to_not receive(:update)
25
+ end
26
+ end
27
+
28
+ context "a present urn" do
29
+ it "calls update on the client updater" do
30
+ expect(client_updater).to receive(:update)
31
+ end
32
+
33
+ it "calls update on the locations updater" do
34
+ expect(locations_updater).to receive(:update)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ describe G5Updatable::ClientUpdater do
4
+ let(:feed_endpoint) { "#{Rails.root}/spec/support/" }
5
+ let(:client_identifier) { "client_feed.html" }
6
+ let(:client_uid) { "#{Rails.root}/spec/support/client_feed.html" }
7
+ let(:g5_client) { G5Updatable::FeedMapper.new(client_identifier).client }
8
+ let(:updater) { described_class.new(g5_client) }
9
+
10
+ before do
11
+ allow(G5Updatable).to receive(:feed_endpoint) { feed_endpoint }
12
+ allow(G5Updatable).to receive(:client_identifier) { client_identifier }
13
+ end
14
+
15
+ describe "#update" do
16
+ let!(:client) do
17
+ Fabricate(:client, uid: client_uid, name: "Foo", vertical: "Self-Storage")
18
+ end
19
+
20
+ context "update client disabled" do
21
+ it "does nothing" do
22
+ expect(client).to_not receive(:save)
23
+ updater.update
24
+ end
25
+ end
26
+
27
+ context "update client enabled" do
28
+ before { allow(G5Updatable).to receive(:update_client) { true } }
29
+
30
+ context "default parameters" do
31
+ it "updates the name attribute" do
32
+ expect { updater.update }.to change { client.reload.name }.
33
+ from("Foo").to("Farmhouse")
34
+ end
35
+
36
+ it "does not update other attributes" do
37
+ expect { updater.update }.not_to change { client.reload.vertical }
38
+ end
39
+ end
40
+
41
+ context "custom parameters" do
42
+ before do
43
+ allow(G5Updatable).to receive(:client_parameters) { [:name, :vertical] }
44
+ end
45
+
46
+ it "updates the name attribute" do
47
+ expect { updater.update }.to change { client.reload.name }.
48
+ from("Foo").to("Farmhouse")
49
+ end
50
+
51
+ it "updates other attributes" do
52
+ expect { updater.update }.to change { client.reload.vertical }.
53
+ from("Self-Storage").to("Apartments")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,115 @@
1
+ require "spec_helper"
2
+
3
+ describe G5Updatable::FeedMapper do
4
+ let(:feed_endpoint) { "#{Rails.root}/spec/support/" }
5
+
6
+ before { allow(G5Updatable).to receive(:feed_endpoint) { feed_endpoint } }
7
+
8
+ describe "#client" do
9
+ subject(:client_mapper) { described_class.new(client_identifier).client }
10
+
11
+ context "a nil identifier" do
12
+ let(:client_identifier) { nil }
13
+
14
+ before { allow(G5Updatable).to receive(:client_identifier) { nil } }
15
+
16
+ it "does nothing" do
17
+ expect(client_mapper).to be_nil
18
+ end
19
+ end
20
+
21
+ context "a given identifier" do
22
+ let(:client_identifier) { "client_feed.html" }
23
+
24
+ it "maps to the correct name" do
25
+ expect(client_mapper.name).to eq("Farmhouse")
26
+ end
27
+
28
+ it "maps to the correct vertical" do
29
+ expect(client_mapper.vertical).to eq("Apartments")
30
+ end
31
+
32
+ it "maps to the correct domain" do
33
+ expect(client_mapper.domain).to eq("http://farmhouseapartments.com/")
34
+ end
35
+
36
+ it "maps to the correct type" do
37
+ expect(client_mapper.type).to eq("MultiDomainClient")
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#locations" do
43
+ subject(:location_mapper) { described_class.new(client_identifier).locations.first }
44
+
45
+ context "a nil identifier" do
46
+ let(:client_identifier) { nil }
47
+
48
+ before { allow(G5Updatable).to receive(:client_identifier) { nil } }
49
+
50
+ it "does nothing" do
51
+ expect(location_mapper).to be_nil
52
+ end
53
+ end
54
+
55
+ context "a given identifier" do
56
+ let(:client_identifier) { "client_feed.html" }
57
+
58
+ it "maps to the correct urn" do
59
+ expect(location_mapper.urn).to eq("g5-cl-1qrcyt46-hollywood")
60
+ end
61
+
62
+ it "maps to the correct name" do
63
+ expect(location_mapper.name).to eq("Hollywood")
64
+ end
65
+
66
+ it "maps to the correct domain" do
67
+ expect(location_mapper.domain).to eq("http://www.hollywood.com/")
68
+ end
69
+
70
+ it "maps to the correct street_address" do
71
+ expect(location_mapper.street_address).to eq("4567 Storage Drive Unit 5")
72
+ end
73
+
74
+ it "maps to the correct state" do
75
+ expect(location_mapper.state).to eq("CA")
76
+ end
77
+
78
+ it "maps to the correct city" do
79
+ expect(location_mapper.city).to eq("Hollywood")
80
+ end
81
+
82
+ it "maps to the correct neighborhood" do
83
+ expect(location_mapper.neighborhood).to eq("Westwood")
84
+ end
85
+
86
+ it "maps to the correct postal_code" do
87
+ expect(location_mapper.postal_code).to eq("80229")
88
+ end
89
+
90
+ it "maps to the correct phone_number" do
91
+ expect(location_mapper.phone_number).to eq("555-555-5555")
92
+ end
93
+
94
+ it "maps to the correct corporate" do
95
+ expect(location_mapper.corporate).to eq("False")
96
+ end
97
+
98
+ it "maps to the correct floor_plans" do
99
+ expect(location_mapper.floor_plans).to eq("2 Bedroom 2 Bath, Studio")
100
+ end
101
+
102
+ it "maps to the correct primary_amenity" do
103
+ expect(location_mapper.primary_amenity).to eq("Secret Passages")
104
+ end
105
+
106
+ it "maps to the correct qualifier" do
107
+ expect(location_mapper.qualifier).to eq("Luxury")
108
+ end
109
+
110
+ it "maps to the correct primary_landmark" do
111
+ expect(location_mapper.primary_landmark).to eq("Seattle Grace Hospital")
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ describe G5Updatable::LocationsUpdater do
4
+ let(:feed_endpoint) { "#{Rails.root}/spec/support/" }
5
+ let(:client_identifier) { "updated_client_feed.html" }
6
+ let(:locations) { G5Updatable::FeedMapper.new(client_identifier).locations }
7
+ let(:g5_location) { locations.first }
8
+ let(:urn) { g5_location.uid.to_s.split("/").last }
9
+ let(:updater) { described_class.new(locations) }
10
+
11
+ before do
12
+ allow(G5Updatable).to receive(:feed_endpoint) { feed_endpoint }
13
+ allow(G5Updatable).to receive(:client_identifier) { client_identifier }
14
+ end
15
+
16
+ describe "#update" do
17
+ let!(:location) do
18
+ Fabricate(:location, urn: urn, name: "Foo", neighborhood: "Eastside")
19
+ end
20
+
21
+ context "update locations disabled" do
22
+ before { allow(G5Updatable).to receive(:update_locations) { false } }
23
+
24
+ it "does not update existing locations" do
25
+ expect(locations).to_not receive(:save)
26
+ updater.update
27
+ end
28
+
29
+ it "creates new locations" do
30
+ expect { updater.update }.to change { Location.all.size }.from(1).to(2)
31
+ end
32
+ end
33
+
34
+ context "update locations enabled" do
35
+ context "default parameters" do
36
+ it "updates the name attribute" do
37
+ expect { updater.update }.to change { location.reload.name }.
38
+ from("Foo").to("Hollywood")
39
+ end
40
+
41
+ it "does not update other attributes" do
42
+ expect { updater.update }.not_to change { location.reload.neighborhood }
43
+ end
44
+
45
+ it "creates new locations" do
46
+ expect { updater.update }.to change { Location.all.size }.from(1).to(2)
47
+ end
48
+ end
49
+
50
+ context "custom parameters" do
51
+ before do
52
+ allow(G5Updatable).to receive(:location_parameters) { [:name, :neighborhood] }
53
+ end
54
+
55
+ it "updates the name attribute" do
56
+ expect { updater.update }.to change { location.reload.name }.
57
+ from("Foo").to("Hollywood")
58
+ end
59
+
60
+ it "updates other attributes" do
61
+ expect { updater.update }.to change { location.reload.neighborhood }.
62
+ from("Eastside").to("River West")
63
+ end
64
+
65
+ it "creates new locations" do
66
+ expect { updater.update }.to change { Location.all.size }.from(1).to(2)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe G5Updatable::VERSION do
4
+ it "should have a version" do
5
+ expect(G5Updatable::VERSION).to_not be_blank
6
+ end
7
+ end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+ require "generators/g5_updatable/install/install_generator"
3
+
4
+ describe G5Updatable::InstallGenerator, type: :generator do
5
+ destination File.expand_path("../../../tmp", __FILE__)
6
+ arguments %w()
7
+
8
+ before do
9
+ prepare_destination
10
+ setup_routes
11
+ run_generator
12
+ end
13
+
14
+ it "should copy the g5_updatable initializer" do
15
+ expect(destination_root).to have_structure {
16
+ directory "config" do
17
+ directory "initializers" do
18
+ file "g5_updatable.rb" do
19
+ contains "G5Updatable.setup do |config|"
20
+ end
21
+ end
22
+ end
23
+ }
24
+ end
25
+
26
+ it "should mount the engine" do
27
+ expect(destination_root).to have_structure {
28
+ directory "config" do
29
+ file "routes.rb" do
30
+ contains "mount G5Updatable::Engine => '/g5_updatable'"
31
+ end
32
+ end
33
+ }
34
+ end
35
+
36
+ def setup_routes
37
+ routes = <<-END
38
+ Rails.application.routes.draw do
39
+ resource :home, only: [:show, :index]
40
+
41
+ match "/some_path", to: "controller#action", as: :my_alias
42
+
43
+ root to: "home#index"
44
+ end
45
+ END
46
+ config_dir = File.join(destination_root, "config")
47
+
48
+ FileUtils.mkdir_p(config_dir)
49
+ File.write(File.join(config_dir, "routes.rb"), routes)
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ resource :home, only: [:show, :index]
3
+
4
+ match '/some_path', to: 'controller#action', as: :my_alias
5
+
6
+ root to: 'home#index'
7
+ end
@@ -0,0 +1,25 @@
1
+ G5Updatable.setup do |config|
2
+ # base path to the G5 Hub
3
+ #
4
+ #config.feed_endpoint = "..."
5
+
6
+ # identifier of the client (urn)
7
+ #
8
+ #config.client_identifier = "..."
9
+
10
+ # default is true. When set to true, existing locations in your app will be
11
+ # updated with any changes made to the hub. If set to false, existing locations
12
+ # will be skipped and only newly added locations will be created.
13
+ #
14
+ #config.update_locations = true
15
+
16
+ # default is false. When set to true, client data will update.
17
+ #
18
+ #config.update_client = false
19
+
20
+ # default is [:name]. A whitlist of parameters to create/update on the model
21
+ #config.location_parameters = [:name]
22
+
23
+ # default is [:name]. A whitlist of parameters to update on the model
24
+ #config.client_parameters = [:name]
25
+ end
@@ -0,0 +1,8 @@
1
+ Rails.application.routes.draw do
2
+ mount G5Updatable::Engine => '/g5_updatable'
3
+ resource :home, only: [:show, :index]
4
+
5
+ match "/some_path", to: "controller#action", as: :my_alias
6
+
7
+ root to: "home#index"
8
+ end
@@ -0,0 +1,44 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc,
10
+ # in spec/support/ and its subdirectories.
11
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
12
+
13
+ # Checks for pending migrations before tests are run.
14
+ # If you are not using ActiveRecord, you can remove this line.
15
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
16
+
17
+ RSpec.configure do |config|
18
+ # ## Mock Framework
19
+ #
20
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
21
+ #
22
+ # config.mock_with :mocha
23
+ # config.mock_with :flexmock
24
+ # config.mock_with :rr
25
+
26
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
27
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
28
+
29
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
30
+ # examples within a transaction, remove the following line or assign false
31
+ # instead of true.
32
+ config.use_transactional_fixtures = true
33
+
34
+ # If true, the base class of anonymous controllers will be inferred
35
+ # automatically. This will be the default behavior in future versions of
36
+ # rspec-rails.
37
+ config.infer_base_class_for_anonymous_controllers = false
38
+
39
+ # Run specs in random order to surface order dependencies. If you find an
40
+ # order dependency and want to debug it, you can fix the order by providing
41
+ # the seed, which is printed after each run.
42
+ # --seed 1234
43
+ config.order = "random"
44
+ end