easy-resources 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/lib/easy/resources/version.rb +1 -1
  3. data/spec/dummy/Rakefile +6 -0
  4. data/spec/dummy/app/assets/config/manifest.js +3 -0
  5. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  6. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  7. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  8. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  9. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  10. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  11. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  12. data/spec/dummy/app/jobs/application_job.rb +2 -0
  13. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  14. data/spec/dummy/app/models/application_record.rb +3 -0
  15. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  16. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  17. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  18. data/spec/dummy/bin/bundle +3 -0
  19. data/spec/dummy/bin/rails +4 -0
  20. data/spec/dummy/bin/rake +4 -0
  21. data/spec/dummy/bin/setup +36 -0
  22. data/spec/dummy/bin/update +31 -0
  23. data/spec/dummy/bin/yarn +11 -0
  24. data/spec/dummy/config.ru +5 -0
  25. data/spec/dummy/config/application.rb +19 -0
  26. data/spec/dummy/config/boot.rb +5 -0
  27. data/spec/dummy/config/cable.yml +10 -0
  28. data/spec/dummy/config/database.yml +25 -0
  29. data/spec/dummy/config/environment.rb +5 -0
  30. data/spec/dummy/config/environments/development.rb +61 -0
  31. data/spec/dummy/config/environments/production.rb +94 -0
  32. data/spec/dummy/config/environments/test.rb +46 -0
  33. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  34. data/spec/dummy/config/initializers/assets.rb +14 -0
  35. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  37. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  38. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  39. data/spec/dummy/config/initializers/inflections.rb +16 -0
  40. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  41. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  43. data/spec/dummy/config/locales/en.yml +33 -0
  44. data/spec/dummy/config/puma.rb +34 -0
  45. data/spec/dummy/config/routes.rb +3 -0
  46. data/spec/dummy/config/spring.rb +6 -0
  47. data/spec/dummy/config/storage.yml +34 -0
  48. data/spec/dummy/db/test.sqlite3 +0 -0
  49. data/spec/dummy/log/development.log +0 -0
  50. data/spec/dummy/log/test.log +0 -0
  51. data/spec/dummy/package.json +5 -0
  52. data/spec/dummy/public/404.html +67 -0
  53. data/spec/dummy/public/422.html +67 -0
  54. data/spec/dummy/public/500.html +66 -0
  55. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  56. data/spec/dummy/public/apple-touch-icon.png +0 -0
  57. data/spec/dummy/public/favicon.ico +0 -0
  58. data/spec/easy_resources_spec.rb +8 -0
  59. data/spec/fixtures/files/easy_contact.json +71 -0
  60. data/spec/fixtures/files/easy_contact/show.xml +48 -0
  61. data/spec/fixtures/files/easy_crm_case.json +41 -0
  62. data/spec/fixtures/files/easy_crm_case/show.xml +36 -0
  63. data/spec/fixtures/files/easy_server/index.xml +36 -0
  64. data/spec/fixtures/files/easy_server/show.xml +33 -0
  65. data/spec/fixtures/files/easy_web_application/index.xml +32 -0
  66. data/spec/fixtures/files/easy_web_application/show.json +54 -0
  67. data/spec/fixtures/files/easy_web_application/show.xml +16 -0
  68. data/spec/fixtures/files/easy_web_application/with_custom_fields.xml +0 -0
  69. data/spec/fixtures/files/easy_web_application/with_easy_contact.xml +17 -0
  70. data/spec/fixtures/files/easy_web_application/with_easy_crm_case.xml +17 -0
  71. data/spec/fixtures/files/easy_web_application/with_ewaa.xml +7 -0
  72. data/spec/fixtures/files/issue.json +56 -0
  73. data/spec/fixtures/files/issue/show.xml +31 -0
  74. data/spec/fixtures/files/project.json +40 -0
  75. data/spec/fixtures/files/project/show.xml +32 -0
  76. data/spec/models/easy-resources/redmine/easy_contact_spec.rb +26 -0
  77. data/spec/models/easy-resources/redmine/easy_crm_case_spec.rb +19 -0
  78. data/spec/models/easy-resources/redmine/easy_web_application_activity_spec.rb +6 -0
  79. data/spec/models/easy-resources/redmine/easy_web_application_spec.rb +59 -0
  80. data/spec/models/easy-resources/redmine/issue_spec.rb +15 -0
  81. data/spec/models/easy-resources/redmine/project_spec.rb +11 -0
  82. data/spec/models/easy-resources/redmine/redmine_base_spec.rb +8 -0
  83. data/spec/models/easy-resources/resource_spec.rb +42 -0
  84. data/spec/spec_helper.rb +24 -0
  85. data/spec/support/active_resource.rb +57 -0
  86. data/spec/support/fixtures.rb +5 -0
  87. data/spec/support/redmine_active_resource.rb +28 -0
  88. metadata +173 -3
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <easy_web_application>
3
+ <id>65739</id>
4
+ <easy_external_id>3955</easy_external_id>
5
+ <application_type>trial</application_type>
6
+ <url>lukas.easyproject.cz</url>
7
+ <status>running</status>
8
+ <monitored>false</monitored>
9
+ <version>2017.1.3 (03.02)</version>
10
+ <easy_server id="22" host_name="bigdemo.cz" type="application" server_type="bigdemo"/>
11
+ <author id="14" name="Anonymní"/>
12
+ <internal_user_limit>0</internal_user_limit>
13
+ <git_repository type="string">git@git.easy.cz:package.git</git_repository>
14
+ <created_at>2018-03-22T09:10:47Z</created_at>
15
+ <updated_at>2018-05-24T10:55:28Z</updated_at>
16
+ </easy_web_application>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <easy_web_application>
3
+ <id>65739</id>
4
+ <easy_external_id>3955</easy_external_id>
5
+ <application_type>trial</application_type>
6
+ <url>lukas.easyproject.cz</url>
7
+ <status>running</status>
8
+ <monitored>false</monitored>
9
+ <version>2017.1.3 (03.02)</version>
10
+ <easy_server id="309" host_name="bigdemo.easyproject.cz" type="application" server_type="bigdemo"/>
11
+ <easy_contact id="2" name="Lukas"/>
12
+ <author id="14" name="Anonymní"/>
13
+ <internal_user_limit>0</internal_user_limit>
14
+ <git_repository type="string">git@git.easy.cz:easyproject_com/stable.git</git_repository>
15
+ <created_at>2018-03-22T09:10:47Z</created_at>
16
+ <updated_at>2018-05-24T10:55:28Z</updated_at>
17
+ </easy_web_application>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <easy_web_application>
3
+ <id>65739</id>
4
+ <easy_external_id>3955</easy_external_id>
5
+ <application_type>trial</application_type>
6
+ <url>lukas.easyproject.cz</url>
7
+ <status>running</status>
8
+ <monitored>false</monitored>
9
+ <version>2017.1.3 (03.02)</version>
10
+ <easy_server id="309" host_name="bigdemo.easyproject.cz" type="application" server_type="bigdemo"/>
11
+ <author id="14" name="Anonymní"/>
12
+ <easy_crm_case id="5" name="Lukas CRM"/>
13
+ <internal_user_limit>0</internal_user_limit>
14
+ <git_repository type="string">git@git.easy.cz:easyproject_com/stable.git</git_repository>
15
+ <created_at>2018-03-22T09:10:47Z</created_at>
16
+ <updated_at>2018-05-24T10:55:28Z</updated_at>
17
+ </easy_web_application>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <easy-web-application>
3
+ <url>awesome.ewa</url>
4
+ <easy-web-application-activities-attributes>
5
+ <activities-count-in-day type="integer">13</activities-count-in-day>
6
+ </easy-web-application-activities-attributes>
7
+ </easy-web-application>
@@ -0,0 +1,56 @@
1
+ {
2
+ "issue": {
3
+ "id": 4,
4
+ "project": {
5
+ "id": 1,
6
+ "name": "Default Project"
7
+ },
8
+ "tracker": {
9
+ "id": 1,
10
+ "name": "Task"
11
+ },
12
+ "status": {
13
+ "id": 2,
14
+ "name": "New"
15
+ },
16
+ "css_classes": "issue tracker-1 status-2 priority-20 priority-highest multieditable-container scheme scheme-0",
17
+ "priority": {
18
+ "id": 20,
19
+ "name": "Urgent"
20
+ },
21
+ "author": {
22
+ "id": 4,
23
+ "name": "Anonymous"
24
+ },
25
+ "assigned_to": {
26
+ "id": 1,
27
+ "name": "Easy Dummy",
28
+ "avatar_urls": {
29
+ "original": "/images/easy_images/easy_avatars/12/original/6541c74165cdea9842feca299a861244.jpg?1489412181",
30
+ "large": "/images/easy_images/easy_avatars/12/large/6541c74165cdea9842feca299a861244.jpg?1489412181",
31
+ "medium": "/images/easy_images/easy_avatars/12/medium/6541c74165cdea9842feca299a861244.jpg?1489412181",
32
+ "small": "/images/easy_images/easy_avatars/12/small/6541c74165cdea9842feca299a861244.jpg?1489412181"
33
+ }
34
+ },
35
+ "fixed_version": {
36
+ "id": 1,
37
+ "name": "Milestone 1"
38
+ },
39
+ "subject": "Default task 2",
40
+ "description": "Et aut omnis sed. Aut accusamus ut porro ipsa blanditiis deserunt perspiciatis nostrum. Reiciendis reiciendis nulla tempore ut. Dicta et velit ad aut quasi. Omnis porro ut et est molestiae.",
41
+ "start_date": "2018-01-21",
42
+ "due_date": "2018-03-13",
43
+ "done_ratio": 70,
44
+ "estimated_hours": 100.0,
45
+ "spent_hours": 0.0,
46
+ "total_spent_hours": 0.0,
47
+ "created_on": "2017-11-28T23:00:00Z",
48
+ "updated_on": "2017-01-02T23:00:00Z",
49
+ "closed_on": "2017-12-30T13:12:32Z",
50
+ "easy_sprint": {
51
+ "id": 1,
52
+ "name": "Sprint 1",
53
+ "due_date": "2018-01-18"
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issue>
3
+ <id>3356</id>
4
+ <project id="110" name="Partner Program Implementation"/>
5
+ <tracker id="1" name="Task"/>
6
+ <status id="1" name="New"/>
7
+ <css_classes>issue tracker-1 status-1 priority-15 priority-highest parent created-by-me multieditable-container scheme
8
+ scheme-1
9
+ </css_classes>
10
+ <priority id="15" name="DO IT NOW"/>
11
+ <author id="5" name="Manager Manager"/>
12
+ <subject>Identify areas for partnerships</subject>
13
+ <description></description>
14
+ <start_date>2018-05-21</start_date>
15
+ <due_date/>
16
+ <done_ratio>13</done_ratio>
17
+ <is_private>false</is_private>
18
+ <is_favorited>false</is_favorited>
19
+ <estimated_hours/>
20
+ <total_estimated_hours>0</total_estimated_hours>
21
+ <spent_hours>0.0</spent_hours>
22
+ <total_spent_hours>0.0</total_spent_hours>
23
+ <custom_fields type="array">
24
+ <custom_field id="85" name="Skill 1 required?" internal_name="" field_format="bool">
25
+ <value>0</value>
26
+ </custom_field>
27
+ </custom_fields>
28
+ <created_on>2017-11-29T15:39:24Z</created_on>
29
+ <updated_on>2017-11-30T12:52:52Z</updated_on>
30
+ <closed_on/>
31
+ </issue>
@@ -0,0 +1,40 @@
1
+ {
2
+ "project": {
3
+ "id": 1,
4
+ "name": "Default Project",
5
+ "identifier": "1",
6
+ "description": "\u003cp\u003eHere comes a short description of your project\u003c/p\u003e\r\n",
7
+ "homepage": "",
8
+ "parent": {
9
+ "id": 2,
10
+ "name": "Sample project"
11
+ },
12
+ "status": 1,
13
+ "is_public": true,
14
+ "author": {
15
+ "id": 1,
16
+ "name": "Easy Admin",
17
+ "easy_external_id": null
18
+ },
19
+ "sum_time_entries": 115.0,
20
+ "sum_estimated_hours": 520.0,
21
+ "custom_fields": [
22
+ {
23
+ "id": 35,
24
+ "name": "Project contact",
25
+ "internal_name": null,
26
+ "field_format": "easy_lookup"
27
+ },
28
+ {
29
+ "id": 36,
30
+ "name": "Test autoincrement",
31
+ "internal_name": null,
32
+ "field_format": "autoincrement",
33
+ "value": ""
34
+ }
35
+ ],
36
+ "created_on": "2017-11-28T23:00:00Z",
37
+ "updated_on": "2017-11-28T23:00:00Z",
38
+ "start_date": "2017-11-23"
39
+ }
40
+ }
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project>
3
+ <id>3</id>
4
+ <name>3. IT Projects</name>
5
+ <identifier>asddt</identifier>
6
+ <description>&lt;p&gt;This root project contains program that usually solved within IT department of companies&lt;/p&gt;
7
+ </description>
8
+ <homepage></homepage>
9
+ <status>1</status>
10
+ <is_public>false</is_public>
11
+ <easy_is_easy_template>false</easy_is_easy_template>
12
+ <easy_start_date/>
13
+ <easy_due_date/>
14
+ <easy_external_id/>
15
+ <author id="1" name="System Administrator" easy_external_id=""/>
16
+ <sum_time_entries>0.0</sum_time_entries>
17
+ <sum_estimated_hours>1200.0</sum_estimated_hours>
18
+ <currency>EUR</currency>
19
+ <custom_fields type="array">
20
+ <custom_field id="87" name="Project Manager" internal_name="" field_format="easy_lookup"></custom_field>
21
+ <custom_field id="88" name="Industry" internal_name="" field_format="list">
22
+ <value></value>
23
+ </custom_field>
24
+ <custom_field id="84" name="Project Phase" internal_name="" field_format="list">
25
+ <value></value>
26
+ </custom_field>
27
+ </custom_fields>
28
+ <created_on>2017-09-27T13:35:12Z</created_on>
29
+ <updated_on>2017-11-29T07:40:21Z</updated_on>
30
+ <start_date/>
31
+ <due_date/>
32
+ </project>
@@ -0,0 +1,26 @@
1
+ RSpec.describe Easy::Resources::Redmine::EasyContact do
2
+ include_context "redmine active resource shares" do
3
+ let(:entity_name) { 'easy_contact' }
4
+ end
5
+
6
+ it 'get contact' do
7
+ expect(find_entity).not_to be_nil
8
+ end
9
+
10
+ it '#name' do
11
+ expect(find_entity.name).to eq 'Darth Maul'
12
+ end
13
+
14
+ # it '#url' do
15
+ # expect(find_entity.url).to eq 'darth-maul.dummy.com'
16
+ # end
17
+ #
18
+ # it '#client?' do
19
+ # expect(find_entity.client?).to be_truthy
20
+ # end
21
+ #
22
+ # it '#demo?' do
23
+ # expect(find_entity.demo?).to be_falsey
24
+ # end
25
+
26
+ end
@@ -0,0 +1,19 @@
1
+ RSpec.describe Easy::Resources::Redmine::EasyCrmCase do
2
+ include_context "redmine active resource shares" do
3
+ let(:entity_name) { 'easy_crm_case' }
4
+ end
5
+
6
+
7
+ it 'get crm case' do
8
+ expect(find_entity.name).not_to be_empty
9
+ end
10
+
11
+ it 'crm case has project' do
12
+ expect(find_entity.project).to be_a Easy::Resources::Redmine::Project
13
+ end
14
+
15
+ it 'crm case has customer' do
16
+ expect(find_entity.customer).to be_a Easy::Resources::Redmine::EasyContact
17
+ end
18
+
19
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.describe Easy::Resources::Redmine::EasyWebApplicationActivity do
2
+ include_context "redmine active resource shares" do
3
+ let(:entity_name) { 'easy_web_application_activity' }
4
+ end
5
+
6
+ end
@@ -0,0 +1,59 @@
1
+ RSpec.shared_examples "optional reference" do |name|
2
+ describe "##{name}" do
3
+ it 'not include in request' do
4
+ expect(find_entity.send(name)).to be_nil
5
+ end
6
+
7
+ it 'is include in request' do
8
+ expect(find_entity("with_#{name}").send(name)).to be_a "Easy::Resources::Redmine::#{name.to_s.classify}".constantize
9
+ end
10
+ end
11
+ end
12
+
13
+ RSpec.describe Easy::Resources::Redmine::EasyWebApplication do
14
+ include_context "redmine active resource shares" do
15
+ let(:entity_name) { 'easy_web_application' }
16
+ end
17
+
18
+ it 'get ewa' do
19
+ expect(find_entity.attributes).to include *%w[id url git_repository version application_type created_at]
20
+ expect(find_entity.git_branch).to be_nil
21
+ expect(find_entity.name).not_to be_empty
22
+ end
23
+
24
+ it 'ewa has easy_server' do
25
+ expect(find_entity.easy_server).to be_a Easy::Resources::Redmine::EasyServer
26
+ end
27
+
28
+ include_examples "optional reference", :easy_crm_case
29
+ include_examples "optional reference", :easy_contact
30
+
31
+ describe ".get_all" do
32
+
33
+ it "with block" do
34
+ stub_xml(path: "easy_web_applications.xml", source_file: "index", response_headers: { 'Total' => '4' })
35
+ stub_xml(path: "easy_web_applications.xml?page=2", source_file: "index")
36
+ expect(described_class.get_all.count).to eq 4
37
+ end
38
+ end
39
+
40
+ it "create EWA" do
41
+ stub_xml(method: :post, path: "easy_web_applications.xml", request_body: { easy_web_application: { url: "xxx" } }.to_xml, response_body: "")
42
+ ewa = described_class.new(url: "xxx")
43
+ expect { ewa.save }.not_to raise_error
44
+ end
45
+
46
+ describe "easy_web_application_activity" do
47
+ subject { described_class.new(url: "awesome.ewa") }
48
+
49
+ it "update EWA with activity" do
50
+ req = ActiveResource::Request.new(:post, "/easy_web_applications.xml", file_fixture("easy_web_application/with_ewaa.xml").read, { "Content-Type" => "application/xml", "X-Redmine-API-Key" => api_key })
51
+ res = ActiveResource::Response.new("", 201, {})
52
+ ActiveResource::HttpMock.respond_to({ req => res })
53
+ subject.easy_web_application_activities_attributes = { activities_count_in_day: 13 }
54
+ subject.save
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.describe Easy::Resources::Redmine::Issue do
2
+ include_context "redmine active resource shares" do
3
+ let(:entity_name) { 'issue' }
4
+ end
5
+
6
+
7
+ it 'get issue' do
8
+ expect(find_entity.subject).not_to be_empty
9
+ end
10
+
11
+ it 'issue has project' do
12
+ expect(find_entity.project).to be_a Easy::Resources::Redmine::Project
13
+ end
14
+
15
+ end
@@ -0,0 +1,11 @@
1
+ RSpec.describe Easy::Resources::Redmine::Project do
2
+ include_context "redmine active resource shares" do
3
+ let(:entity_name) { 'project' }
4
+ end
5
+
6
+
7
+ it 'get project' do
8
+ expect(find_entity.name).not_to be_empty
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.describe Easy::Resources::Redmine::RedmineBase do
2
+
3
+ it 'no configuration specify' do
4
+ described_class.site = nil
5
+ described_class.api_key = nil
6
+ expect { described_class.find :first }.to raise_exception NoMethodError
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ class DummyResource < Easy::Resource
2
+ self.site = "easyredmine.com"
3
+ self.format = :json
4
+ end
5
+ RSpec.describe Easy::Resource do
6
+ subject { DummyResource.new({ id: 1 }, true) }
7
+ let(:value) { { att: 1 } }
8
+
9
+ it "#becomes" do
10
+ target_class = Easy::Resources::Redmine::Issue
11
+ expect(subject.becomes(target_class)).to be_a(target_class).and have_attributes id: 1
12
+ end
13
+
14
+ describe "#update_column" do
15
+ it "json" do
16
+ expect(subject).to receive(:patch).with nil, {}, value.to_json
17
+ subject.update_column :att, 1
18
+ end
19
+
20
+ it "xml" do
21
+ allow(DummyResource).to receive(:format).and_return ActiveResource::Formats::XmlFormat
22
+ expect(subject).to receive(:patch).with nil, {}, value.to_xml(root: "dummy-resource")
23
+ subject.update_column :att, 1
24
+ end
25
+
26
+ end
27
+
28
+ describe "#patch" do
29
+ let(:connection) { double "ActiveResource::Connection" }
30
+ before(:each) { allow(subject).to receive(:connection).and_return connection }
31
+
32
+ it "update columns" do
33
+ expect(connection).to receive(:patch).with "easyredmine.com/dummy_resources/1.json", value.to_json, {}
34
+ subject.update_columns value
35
+ end
36
+
37
+ it "custom url" do
38
+ expect(connection).to receive(:patch).with "easyredmine.com/dummy_resources/1/deployed.json", "", {}
39
+ subject.patch "deployed"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require "simplecov"
3
+ SimpleCov.start 'rails'
4
+
5
+ require "bundler/setup"
6
+ require "webmock/rspec"
7
+
8
+ require_relative "../spec/dummy/config/environment"
9
+
10
+ require "rspec/rails"
11
+ require "active_resource_response/http_mock"
12
+
13
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
14
+
15
+ RSpec.configure do |config|
16
+
17
+ # Disable RSpec exposing methods globally on `Module` and `main`
18
+ config.disable_monkey_patching!
19
+
20
+ config.expect_with :rspec do |c|
21
+ c.syntax = :expect
22
+ end
23
+ end
24
+