rnow 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.
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ describe Rnow::Connection do
3
+
4
+ ["test.acme.com", "116.136.168.68", "http://test.acme.com:3000", "https://test.acme.com"].each do |host|
5
+ it "should build URL #{host} without failure" do
6
+ conn_params = {
7
+ :username => "soheil",
8
+ :password => "password",
9
+ :host => host
10
+ }
11
+ uri = "services/rest/connect"
12
+
13
+ ic = Rnow::Connection.new(conn_params)
14
+ ic.adapter = :test
15
+ ic.adapter_block = stub_get(uri)
16
+
17
+ # execute the request. There should be no "URI::BadURIError: both URI are relative" error
18
+ ic.get(uri)
19
+ end
20
+ end
21
+
22
+ it "should raise authentication error response" do
23
+ host = 'test.acme.com'
24
+ conn_params = {
25
+ :username => "soheil",
26
+ :password => "password",
27
+ :host => host
28
+ }
29
+ uri = "/wapi/v1.0/record:host"
30
+
31
+ ic = Rnow::Connection.new(conn_params)
32
+ ic.adapter = :test
33
+ ic.adapter_block = stub_get(uri, 401)
34
+
35
+ # execute the request. There should be no "URI::BadURIError: both URI are relative" error
36
+
37
+ expect { ic.get(uri) }.to raise_error(Rnow::Error)
38
+ end
39
+
40
+ def stub_get(uri, status=200)
41
+ Proc.new do |stub|
42
+ stub.get(uri) { [ status, {}, 'SUCCESS'] }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ class FooResource < Rnow::Resource
3
+ remote_attr_accessor :name, :junction, :extattrs
4
+ remote_attr_writer :do_it
5
+ remote_post_accessor :sect
6
+ remote_attr_reader :readonly_thing
7
+ attr_accessor :animal
8
+ rnow_object "foo:animal"
9
+ end
10
+
11
+ FooResponse = Struct.new(:body)
12
+
13
+ describe Rnow::Resource do
14
+ it "hashes correctly" do
15
+ host = FooResource.new
16
+ host.href = "123"
17
+ host.animal = "mom"
18
+ host.name = "lol"
19
+ hsh = host.send(:remote_attribute_hash)
20
+ expect(hsh).to eq({:name => 'lol'})
21
+ end
22
+
23
+ it "return fields" do
24
+ hsh = FooResource._return_fields
25
+ expect(hsh).to eq('name,junction,extattrs,readonly_thing')
26
+ end
27
+
28
+ it "should have a correct resource_uri" do
29
+ expect(FooResource.resource_uri).to eq(Rnow.base_path + "foo:animal")
30
+ f=FooResource.new
31
+ expect(f.resource_uri).to eq(Rnow.base_path + "foo:animal")
32
+ f.href = "lkjlkj"
33
+ expect(f.resource_uri).to eq(Rnow.base_path + "lkjlkj")
34
+ end
35
+
36
+ it "should find with default attributes" do
37
+ conn = double
38
+ uri = Rnow.base_path + "foo:animal"
39
+ allow(conn).to receive(:get).with(uri,{}).and_return(FooResponse.new("{\"items\": []}"))
40
+ expect(FooResource.all(conn)).to eq([])
41
+ end
42
+
43
+ it "should allow .all with return fields or max results" do
44
+ conn = double
45
+ uri = Rnow.base_path + "queryResults"
46
+ allow(conn).to receive(:get).with(uri, {:query=>"select%20*%20from%20foo:animal%20limit%2020%20offset%201"}).and_return(FooResponse.new("{\"items\": [{\"columnNames\": {}, \"rows\": {}}]}"))
47
+ expect(FooResource.paginate(conn, {page: 1, count: 20})).to eq([])
48
+ end
49
+
50
+ it "should put with the right attributes" do
51
+ conn = double
52
+ uri = Rnow.base_path + "abcd"
53
+ allow(conn).to receive(:put).with(uri, {:name => "jerry", :junction => "32", :do_it => false}).and_return(FooResponse.new("{\"links\": [{\"href\": \"acme.com\"}]}"))
54
+ f = FooResource.new(:connection => conn)
55
+ f.href = "abcd"
56
+ f.do_it = false
57
+ f.junction = "32"
58
+ f.name = "jerry"
59
+ f.sect = :fulburns
60
+ f.put
61
+ expect(f.href).to eq("acme.com")
62
+ end
63
+
64
+ it "should post with the right attributes" do
65
+ conn = double
66
+ uri = Rnow.base_path + "foo:animal"
67
+ allow(conn).to receive(:post).with(uri, {:name => "jerry", :junction => "32", :do_it => false, :sect => :fulburns}).and_return(FooResponse.new("{\"links\": [{\"href\": \"acme.com\"}]}"))
68
+ f = FooResource.new(:connection => conn)
69
+ f.do_it = false
70
+ f.junction = "32"
71
+ f.name = "jerry"
72
+ f.sect = :fulburns
73
+ f.post
74
+ expect(f.href).to eq('acme.com')
75
+ end
76
+
77
+ it 'should set all attributes including readonly attrs' do
78
+ f = FooResource.new(:readonly_thing => 45, :do_it => false, :sect => :larry)
79
+ expect(f.readonly_thing).to eq(45)
80
+ expect(f.do_it).to be(false)
81
+ expect(f.sect).to eq(:larry)
82
+ end
83
+
84
+ it 'should load attributes on get' do
85
+ conn = double
86
+ uri = Rnow.base_path + "a:ref:that:is:fake"
87
+ json = {:name => "john", :junction => "hi", :extattrs => {"foo" => 3}}.to_json
88
+ response = FooResponse.new(json)
89
+ expect(conn).to receive(:get).with(uri, FooResource.default_params).and_return(response)
90
+ f = FooResource.new(:connection => conn, :href => "a:ref:that:is:fake")
91
+ f.get
92
+ expect(f.name).to eq("john")
93
+ expect(f.junction).to eq("hi")
94
+ expect(f.extattrs).to eq({"foo" => 3})
95
+ end
96
+
97
+ it 'should map wapi objects to classes' do
98
+ @expected = {}
99
+ ObjectSpace.each_object(Class) do |p|
100
+ if p < Rnow::Resource
101
+ @expected[p.rnow_object] = p
102
+ end
103
+ end
104
+ expect(Rnow::Resource.resource_map).to eq(@expected)
105
+ end
106
+ end
107
+
@@ -0,0 +1,103 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ # Bundler load only the gems inside our gemspec
21
+ require 'bundler/setup'
22
+ Bundler.setup
23
+
24
+ require 'rnow'
25
+
26
+ RSpec.configure do |config|
27
+ # rspec-expectations config goes here. You can use an alternate
28
+ # assertion/expectation library such as wrong or the stdlib/minitest
29
+ # assertions if you prefer.
30
+ config.expect_with :rspec do |expectations|
31
+ # This option will default to `true` in RSpec 4. It makes the `description`
32
+ # and `failure_message` of custom matchers include text for helper methods
33
+ # defined using `chain`, e.g.:
34
+ # be_bigger_than(2).and_smaller_than(4).description
35
+ # # => "be bigger than 2 and smaller than 4"
36
+ # ...rather than:
37
+ # # => "be bigger than 2"
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Prevents you from mocking or stubbing a method that does not exist on
45
+ # a real object. This is generally recommended, and will default to
46
+ # `true` in RSpec 4.
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = 'doc'
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rnow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Soheil Eizadi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: jsonapi-serializers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.6.4
97
+ description: Ruby Gem for Oracle RightNow REST interface, was available with version
98
+ 15.05 (May 2015). Use this gem to list, create, and delete RightNow organizations,
99
+ contacts and incdents.
100
+ email:
101
+ - seizadi@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".byebug_history"
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/rnow.rb
114
+ - lib/rnow/connection.rb
115
+ - lib/rnow/resource.rb
116
+ - lib/rnow/resources/.DS_Store
117
+ - lib/rnow/resources/account.rb
118
+ - lib/rnow/resources/category.rb
119
+ - lib/rnow/resources/contact.rb
120
+ - lib/rnow/resources/dispositions.rb
121
+ - lib/rnow/resources/incident.rb
122
+ - lib/rnow/resources/organization.rb
123
+ - lib/rnow/resources/product.rb
124
+ - lib/rnow/version.rb
125
+ - rnow.gemspec
126
+ - spec/connection_spec.rb
127
+ - spec/resource_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/seizadi/rnow
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.5
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Ruby wrapper for Oracle RightNow REST API
153
+ test_files:
154
+ - spec/connection_spec.rb
155
+ - spec/resource_spec.rb
156
+ - spec/spec_helper.rb