ballast 1.9.3 → 2.0.0

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/.travis-gemfile +4 -5
  4. data/.travis.yml +3 -2
  5. data/CHANGELOG.md +62 -6
  6. data/Gemfile +7 -8
  7. data/README.md +2 -2
  8. data/ballast.gemspec +9 -12
  9. data/doc/Ballast/AjaxResponse.html +1380 -0
  10. data/doc/Ballast/Concerns/AjaxHandling.html +662 -0
  11. data/doc/Ballast/Concerns/Common.html +81 -361
  12. data/doc/Ballast/Concerns/ErrorsHandling.html +18 -36
  13. data/doc/Ballast/Concerns/View.html +181 -157
  14. data/doc/Ballast/Concerns.html +6 -6
  15. data/doc/Ballast/Configuration.html +204 -31
  16. data/doc/Ballast/Emoji/Character.html +411 -0
  17. data/doc/Ballast/Emoji/Utils.html +794 -0
  18. data/doc/Ballast/Emoji.html +125 -0
  19. data/doc/Ballast/Errors/{BaseError.html → Base.html} +61 -34
  20. data/doc/Ballast/Errors/{PerformError.html → Failure.html} +21 -17
  21. data/doc/Ballast/Errors/InvalidDomain.html +11 -11
  22. data/doc/Ballast/Errors/{ValidationError.html → ValidationFailure.html} +24 -16
  23. data/doc/Ballast/Errors.html +5 -5
  24. data/doc/Ballast/Middlewares/DefaultHost.html +6 -6
  25. data/doc/Ballast/Middlewares.html +4 -4
  26. data/doc/Ballast/RequestDomainMatcher.html +28 -28
  27. data/doc/Ballast/Service/Response.html +1243 -0
  28. data/doc/Ballast/Service.html +1314 -0
  29. data/doc/Ballast/Version.html +7 -7
  30. data/doc/Ballast.html +15 -15
  31. data/doc/_index.html +59 -30
  32. data/doc/class_list.html +6 -2
  33. data/doc/css/style.css +1 -0
  34. data/doc/file.README.html +6 -6
  35. data/doc/file_list.html +5 -1
  36. data/doc/frames.html +1 -1
  37. data/doc/index.html +6 -6
  38. data/doc/js/full_list.js +4 -1
  39. data/doc/method_list.html +167 -79
  40. data/doc/top-level-namespace.html +41 -4
  41. data/lib/ballast/ajax_response.rb +76 -0
  42. data/lib/ballast/concerns/ajax_handling.rb +73 -0
  43. data/lib/ballast/concerns/common.rb +25 -47
  44. data/lib/ballast/concerns/errors_handling.rb +21 -30
  45. data/lib/ballast/concerns/view.rb +24 -22
  46. data/lib/ballast/configuration.rb +30 -10
  47. data/lib/ballast/emoji.rb +114 -0
  48. data/lib/ballast/errors.rb +16 -13
  49. data/lib/ballast/middlewares/default_host.rb +3 -3
  50. data/lib/ballast/request_domain_matcher.rb +7 -7
  51. data/lib/ballast/service.rb +147 -0
  52. data/lib/ballast/version.rb +3 -3
  53. data/lib/ballast.rb +22 -22
  54. data/spec/ballast/ajax_response_spec.rb +61 -0
  55. data/spec/ballast/concerns/ajax_handling_spec.rb +86 -0
  56. data/spec/ballast/concerns/common_spec.rb +17 -52
  57. data/spec/ballast/concerns/errors_handling_spec.rb +35 -29
  58. data/spec/ballast/concerns/view_spec.rb +21 -32
  59. data/spec/ballast/configuration_spec.rb +66 -16
  60. data/spec/ballast/emoji_spec.rb +103 -0
  61. data/spec/ballast/errors_spec.rb +5 -5
  62. data/spec/ballast/middlewares/default_host_spec.rb +3 -5
  63. data/spec/ballast/request_domain_matcher_spec.rb +4 -4
  64. data/spec/ballast/service_spec.rb +137 -0
  65. data/spec/spec_helper.rb +1 -13
  66. metadata +42 -80
  67. data/doc/Ballast/Concerns/Ajax.html +0 -945
  68. data/doc/Ballast/Context.html +0 -417
  69. data/doc/Ballast/Operation.html +0 -1304
  70. data/doc/Ballast/OperationsChain.html +0 -597
  71. data/lib/ballast/concerns/ajax.rb +0 -134
  72. data/lib/ballast/context.rb +0 -38
  73. data/lib/ballast/operation.rb +0 -136
  74. data/lib/ballast/operations_chain.rb +0 -45
  75. data/spec/ballast/concerns/ajax_spec.rb +0 -141
  76. data/spec/ballast/context_spec.rb +0 -23
  77. data/spec/ballast/operation_spec.rb +0 -177
  78. data/spec/ballast/operations_chain_spec.rb +0 -61
@@ -1,134 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- module Ballast
7
- # A set of concerns to address common issues.
8
- module Concerns
9
- # A concern to handle AJAX and HTTP requests.
10
- module Ajax
11
- extend ActiveSupport::Concern
12
-
13
- # Checks if the current request is AJAX.
14
- #
15
- # @return [Boolean] `true` if the request is AJAX, `false` otherwise.
16
- def is_ajax?
17
- ((request.respond_to?(:xhr?) && request.xhr?) || params[:xhr].to_boolean) ? true : false
18
- end
19
-
20
- # Prepares an AJAX response.
21
- #
22
- # @param status [Symbol|Fixnum] The HTTP status of the response.
23
- # @param data [Object] Additional data to append to the response.
24
- # @param error [Object] A error to append to the response.
25
- def prepare_ajax(status = :ok, data = nil, error = nil)
26
- rv = {status: status}.ensure_access(:indifferent)
27
- rv[:error] = error if error.present?
28
- rv[:data] = data if data.present?
29
- rv
30
- end
31
-
32
- # Sends an AJAX response to the client.
33
- #
34
- # @param data [Hash] The response to send.
35
- # @param status [Symbol|Fixnum] The HTTP status of the response, *ignored if already set in data*.
36
- # @param format [Symbol] The content type of the response.
37
- # @param pretty_json [Boolean] If JSON response must be pretty formatted.
38
- def send_ajax(data, status: :ok, format: :json, pretty_json: false)
39
- if !performed? then
40
- # Prepare data
41
- data = prepare_ajax_send(data, status)
42
-
43
- # Setup callback and format
44
- format, callback, content_type = format_ajax_send(format)
45
- status = data[:status]
46
-
47
- # Adjust data
48
- data = (pretty_json ? Oj.dump(data) : ActiveSupport::JSON.encode(data)) if [:json, :jsonp, :text].include?(format)
49
-
50
- # Render
51
- render(format => data, status: status, callback: callback, content_type: content_type)
52
- end
53
- end
54
-
55
- # Updates an AJAX response from a operation, taking either the response data or the first error.
56
- #
57
- # @param data [Hash] The current data.
58
- # @param operation [Operation] The operation to gather data from.
59
- # @return [Hash] The updated data.
60
- def update_ajax(data, operation = nil)
61
- operation ||= @operation
62
- data.merge!(operation.success? ? {data: operation.response[:data]} : {error: operation.errors.first})
63
- data
64
- end
65
-
66
- # Prevents HTTP caching.
67
- def prevent_caching
68
- response.headers.merge!({
69
- "Cache-Control" => "no-cache, no-store, max-age=0, must-revalidate",
70
- "Pragma" => "no-cache",
71
- "Expires" => "Fri, 01 Jan 1990 00:00:00 GMT"
72
- })
73
- end
74
-
75
- # Allows HTTP Cross-Origin Resource Sharing.
76
- #
77
- # @param allow_origin [String] The value for the `Access-Control-Allow-Origin` header.
78
- # @param allow_methods [Array] A list of methods for the `Access-Control-Allow-Methods` header.
79
- # @param allow_headers [String] The value for the `Access-Control-Allow-Headers` header.
80
- # @param max_age [Float|Fixnum] The value for the `Access-Control-Max-Age` header.
81
- # @param allow_credentials [Boolean] The value for the `Access-Control-Allow-Credentials` header.
82
- def allow_cors(allow_origin: "*", allow_methods: [:post, :get, :options], allow_headers: "*", max_age: 1.year, allow_credentials: false)
83
- headers.merge!({
84
- "Access-Control-Allow-Origin" => allow_origin,
85
- "Access-Control-Allow-Methods" => allow_methods.collect {|m| m.to_s.upcase }.join(", "),
86
- "Access-Control-Allow-Headers" => allow_headers,
87
- "Access-Control-Max-Age" => max_age.to_i.to_s
88
- })
89
-
90
- headers["Access-Control-Allow-Credentials"] = "true" if allow_credentials
91
- end
92
-
93
- # Generates a robots.txt file.
94
- #
95
- # @param configuration [Array] An array of list of agent and paths to include.
96
- def generate_robots_txt(configuration = nil)
97
- rv = configuration.ensure_array([["*", "/"]], true, true, false) { |entry|
98
- agent = entry.shift
99
- paths = entry.map {|e| "Disallow: #{e}" }
100
-
101
- "User-agent: #{agent}\n#{paths.join("\n")}"
102
- }.join("\n\n")
103
-
104
- render(text: rv, content_type: "text/plain")
105
- end
106
- alias_method :disallow_robots, :generate_robots_txt
107
-
108
- private
109
- # Prepares data for sending back to the client.
110
- #
111
- # @param data [Object] The data to send back. Can be a full response or partial data.
112
- # @param status [Symbol|Fixnum] The HTTP status to set if a new response must be created.
113
- # @return [Hash] An HTTP response.
114
- def prepare_ajax_send(data, status)
115
- data = prepare_ajax(status, data) if !data.is_a?(Hash)
116
- data[:status] ||= status
117
- data[:status] = Rack::Utils.status_code(data[:status].to_s.to_sym) if !data[:status].is_a?(Fixnum)
118
- data
119
- end
120
-
121
- # Sets up parameters to send a response.
122
- #
123
- # @param format [Symbol] The format of the data.
124
- # @return [Array] An array of format, callback and content_type.
125
- def format_ajax_send(format)
126
- format = (format || params[:format] || request.format || "json").to_sym
127
- callback = [:jsonp, :pretty_jsonp].include?(format) ? (params[:callback] || "jsonp#{Time.now.to_i}") : nil
128
- content_type = (format == :text) ? "text/plain" : nil
129
-
130
- [format, callback, content_type]
131
- end
132
- end
133
- end
134
- end
@@ -1,38 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- module Ballast
7
- # A context for an operation. It is basically a Hash with few enhancements, like owner, errors and output support.
8
- class Context < Interactor::Context
9
- # Builds a new context.
10
- #
11
- # @param owner [Object] The owner of this context.
12
- # @param additional [Hash] Additional parameters to include into the context.
13
- def self.build(owner, additional = {})
14
- super({
15
- owner: owner,
16
- errors: [],
17
- output: nil,
18
- response: HashWithIndifferentAccess.new
19
- }.merge(additional).ensure_access(:indifferent))
20
- end
21
-
22
- # Lookups missing methods in the delegatee hash.
23
- #
24
- # @param method [Symbol] The method to lookup.
25
- # @param args [Array] The arguments passed to the method. *This is ignored.*
26
- # @param block [Proc] The block passed to the method. *This is ignored.*
27
- # @return [Object] The value for the method, if present.
28
- def method_missing(method, *args, &block)
29
- object = __getobj__
30
-
31
- if object[method] then
32
- object[method]
33
- else
34
- super(method, *args, &block)
35
- end
36
- end
37
- end
38
- end
@@ -1,136 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- module Ballast
7
- # A operation represents a single responsibility class. Subclasses should only expose and override the #perform method.
8
- class Operation
9
- extend ::Forwardable
10
- include Interactor
11
- def_delegators :context, :owner, :errors, :response, :output
12
-
13
- # Performs the operation.
14
- #
15
- # @param owner_or_context [Object|Context] If is a context, then it will be the context of the operation, otherwise a blank a context with the object
16
- # as owner will be created.
17
- # @param context [NilClass] The context for the operation. *Ignored if `owner_or_context` is a context.*
18
- # @param params [Hash] The additional parameters for the new context. *Ignored if `owner_or_context` is a context.*
19
- # @return [Operation] The performed operation.
20
- def self.perform(owner_or_context, context: nil, params: {})
21
- arg = owner_or_context
22
- arg = (context || ::Ballast::Context.build(owner_or_context, params)) if !arg.is_a?(::Ballast::Context)
23
- super(arg)
24
- end
25
-
26
- # Creates a new operation.
27
- #
28
- # @param context [Context] The context for the operation.
29
- def initialize(context)
30
- @context = context
31
- setup
32
- end
33
-
34
- # Sets up the response hash from instance variables.
35
- #
36
- # @param force [Boolean] Whether to setup the response even if the operation failed.
37
- # @return [Hash] The response hash.
38
- def setup_response(force = false)
39
- if success? || force then
40
- vars = instance_variables
41
- vars.delete(:@context)
42
-
43
- context.response.merge!(vars.reduce({}){ |rv, var|
44
- rv[var.to_s.gsub(/[:@]/, "")] = instance_variable_get(var)
45
- rv
46
- })
47
- end
48
-
49
- context.response
50
- end
51
-
52
- # Imports the response hash into the target instance variables.
53
- #
54
- # @param target [Object] The target of the import.
55
- # @param fields [Array] The keys to import.
56
- # @param overwrite [Boolean] Whether to overwrite existing variables into the target. If set to `false`, any overwrite will raise an `ArgumentError`.
57
- def import_response(target, *fields, overwrite: true)
58
- fields.each do |field|
59
- raise ArgumentError.new(field) if target.instance_variable_get("@#{field}") && !overwrite
60
- target.instance_variable_set("@#{field}", response[field])
61
- end
62
- end
63
-
64
- # Performs the operation handling base errors.
65
- #
66
- # @param setup_response_after [Boolean] Whether to setup the response after processing.
67
- def perform_with_handling(setup_response_after = true)
68
- begin
69
- yield
70
- rescue Lazier::Exceptions::Debug => de
71
- raise de
72
- rescue => e
73
- e.is_a?(::Ballast::Errors::BaseError) ? fail!(e.response) : raise(e)
74
- end
75
-
76
- setup_response if setup_response_after
77
- end
78
-
79
- # Marks failure of the operation appending the error to the context.
80
- #
81
- # @param error [Object|NilClass] The error to store.
82
- def fail!(error = nil)
83
- errors << error if error
84
- super()
85
- end
86
-
87
- # Imports the current operation errors into the target's `@error` instance variable or in the flash hash.
88
- #
89
- # @param target [Object] The target of the import.
90
- # @param to_flash [Boolean] If to import the error in the target's flash object rather than the instance variable.
91
- # @param first_only [Boolean] If to only import the first error.
92
- def import_error(target, to_flash = true, first_only = true)
93
- values = errors
94
- values = values.map {|v| v[:error] } if to_flash
95
- values = values.first if first_only
96
-
97
- if to_flash then
98
- target.flash[:error] = values
99
- else
100
- target.instance_variable_set(:@error, values)
101
- end
102
- end
103
-
104
- # Resolves a numeric error to a human readable message.
105
- #
106
- # @param error [BaseError|Fixnum] The error to resolve.
107
- # @param supported_messages [Hash] The list of supported error codes.
108
- # @param only_message [Boolean] If to only return the message string rather than a full error hash.
109
- # @return [String|Hash] The error with a human readable message or the message alone.
110
- def resolve_error(error, supported_messages = {}, only_message = false)
111
- code = (error.respond_to?(:response) ? error.response : 500).to_integer(500)
112
- rv = {status: code, error: supported_messages.fetch(code, "Oops! We're having some issue. Please try again later.")}
113
- only_message ? rv[:error] : rv
114
- end
115
-
116
- # If running under eventmachine, run the block in a thread of its threadpool using EM::Synchrony, otherwise run the block normally.
117
- #
118
- # @param block [Proc] The block to run.
119
- def in_em_thread(&block)
120
- Ballast.in_em_thread(&block)
121
- end
122
-
123
- # Forwards any missing method to the owner.
124
- #
125
- # @param method [Symbol] The method to forward.
126
- # @param args [Array] The arguments to pass to the method.
127
- # @param block [Proc] The block to pass to the method.
128
- def method_missing(method, *args, &block)
129
- if owner.respond_to?(method)
130
- owner.send(method, *args, &block)
131
- else
132
- super(method, *args, &block)
133
- end
134
- end
135
- end
136
- end
@@ -1,45 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- module Ballast
7
- # A operation made of several operation run sequentially passing the common context. The chain will stop on the first failure.
8
- #
9
- # @attribute [r] operations
10
- # @return [Array] The list of operations performed.
11
- class OperationsChain < Operation
12
- include ::Interactor::Organizer
13
- attr_reader :operations
14
-
15
- # Performs the chain.
16
- #
17
- # @param argument [Object|Context] If is a context, then it will be the context of the operation, unless a blank a context with the object
18
- # as owner will be created.
19
- # @param operations [Array] The list of operations to perform.
20
- # @param context [NilClass] The context for the operation. *Ignored if `owner_or_context` is a context.*
21
- # @param params [Hash] The additional parameters for the new context. *Ignored if `owner_or_context` is a context.*
22
- # @return [Operation] The performed chain.
23
- def self.perform(argument, operations, context: nil, params: {})
24
- argument = (context || ::Ballast::Context.build(argument, params)) if !argument.is_a?(::Ballast::Context)
25
- new(operations, argument).tap(&:perform)
26
- end
27
-
28
- # Creates a new chain.
29
- #
30
- # @param operations [Array] The list of operations to perform.
31
- # @param context [Context] The context for the chain.
32
- def initialize(operations, context)
33
- @context = context
34
- @operations = operations.ensure_array
35
- end
36
-
37
- private
38
- # Returns the operations to perform.
39
- #
40
- # @return [Array] An array of operations to perform.
41
- def interactors
42
- @operations
43
- end
44
- end
45
- end
@@ -1,141 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- require "spec_helper"
7
-
8
- describe Ballast::Concerns::Ajax do
9
- class AjaxMockClass < OpenStruct
10
- include Ballast::Concerns::Ajax
11
-
12
- def initialize(attrs)
13
- @operation = OpenStruct.new(attrs.delete(:operation))
14
- super(attrs)
15
- end
16
- end
17
-
18
- subject{ AjaxMockClass.new(response: OpenStruct.new(headers: {}), headers: {}, params: {}, performed?: false) }
19
-
20
- describe "#is_ajax?" do
21
- it "should return false by default" do
22
- expect(AjaxMockClass.new(request: {}, params: {}).is_ajax?).to be(false)
23
- end
24
-
25
- it "should return true when the request is XHR" do
26
- expect(AjaxMockClass.new(request: OpenStruct.new(xhr?: true)).is_ajax?).to be(true)
27
- end
28
-
29
- it "should return true when the parameter is overriden" do
30
- expect(AjaxMockClass.new(params: {xhr: true}).is_ajax?).to be(true)
31
- end
32
- end
33
-
34
- describe "#prepare_ajax" do
35
- it "should return a default hash" do
36
- expect(subject.prepare_ajax).to be_a(HashWithIndifferentAccess)
37
- expect(subject.prepare_ajax).to eq({status: :ok}.with_indifferent_access)
38
- end
39
-
40
- it "should accept overrides for the status" do
41
- expect(subject.prepare_ajax(:forbidden)).to eq({status: :forbidden}.with_indifferent_access)
42
- end
43
-
44
- it "should accept overrides for the data" do
45
- expect(subject.prepare_ajax(:ok, "DATA")).to eq({status: :ok, data: "DATA"}.with_indifferent_access)
46
- end
47
-
48
- it "should accept overrides for the error" do
49
- expect(subject.prepare_ajax(:ok, nil, "ERROR")).to eq({status: :ok, error: "ERROR"}.with_indifferent_access)
50
- end
51
- end
52
-
53
- describe "#send_ajax" do
54
- before(:each) do
55
- allow(subject).to receive(:render) {|args| args}
56
- end
57
-
58
- it "should prepare the data if the data is not already an Hash" do
59
- expect(subject).to receive(:prepare_ajax).with(:ok, "DATA").and_call_original
60
- expect(subject).to receive(:render).with(json: "{\"status\":200,\"data\":\"DATA\"}", status: 200, callback: nil, content_type: nil)
61
- subject.send_ajax("DATA")
62
- end
63
-
64
- it "translate HTTP status" do
65
- expect(Rack::Utils).to receive(:status_code).with(:forbidden).and_call_original
66
- expect(subject.send_ajax("DATA", status: :forbidden)[:status]).to eq(403)
67
- end
68
-
69
- it "should setup the right content type for text" do
70
- expect(subject).to receive(:render).with(text: "{\"status\":200,\"data\":\"DATA\"}", status: 200, callback: nil, content_type: "text/plain")
71
- subject.send_ajax("DATA", format: :text)
72
- end
73
-
74
- it "should set the right callback for JSONP" do
75
- subject.params[:callback] = "callback"
76
- expect(subject).to receive(:render).with(jsonp: "{\"status\":200,\"data\":\"DATA\"}", status: 200, callback: "callback", content_type: nil)
77
- subject.send_ajax("DATA", format: :jsonp)
78
- end
79
- end
80
-
81
- describe "#update_ajax" do
82
- it "should merge the data from successful operations" do
83
- subject = AjaxMockClass.new(operation: {success?: true, response: {data: "DATA"}})
84
- expect(subject.update_ajax({existing: true})).to eq({existing: true, data: "DATA"})
85
- end
86
-
87
- it "should merge the data from failed operations" do
88
- subject = AjaxMockClass.new(operation: {success?: false, errors: ["ERROR"]})
89
- expect(subject.update_ajax({existing: true})).to eq({existing: true, error: "ERROR"})
90
- end
91
- end
92
-
93
- describe "#prevent_caching" do
94
- it "should append correct headers" do
95
- subject.prevent_caching
96
-
97
- expect(subject.response.headers).to eq({
98
- "Cache-Control" => "no-cache, no-store, max-age=0, must-revalidate",
99
- "Pragma" => "no-cache",
100
- "Expires" => "Fri, 01 Jan 1990 00:00:00 GMT"
101
- })
102
- end
103
- end
104
-
105
- describe "#allow_cors" do
106
- it "should append correct headers" do
107
- subject.allow_cors
108
-
109
- expect(subject.headers).to eq({
110
- "Access-Control-Allow-Origin" => "*",
111
- "Access-Control-Allow-Methods" => "POST, GET, OPTIONS",
112
- "Access-Control-Allow-Headers" => "*",
113
- "Access-Control-Max-Age" => "31557600"
114
- })
115
- end
116
-
117
- it "should append custom headers values" do
118
- subject.allow_cors(allow_origin: "ORIGIN", allow_methods: [:first, :second], allow_headers: "_", max_age: 1.day, allow_credentials: true)
119
-
120
- expect(subject.headers).to eq({
121
- "Access-Control-Allow-Origin" => "ORIGIN",
122
- "Access-Control-Allow-Methods" => "FIRST, SECOND",
123
- "Access-Control-Allow-Headers" => "_",
124
- "Access-Control-Max-Age" => "86400",
125
- "Access-Control-Allow-Credentials" => "true"
126
- })
127
- end
128
- end
129
-
130
- describe "#generate_robots_txt" do
131
- it "should generate a robots.txt file which prevents everything by default" do
132
- expect(subject).to receive(:render).with(text: "User-agent: *\nDisallow: /", content_type: "text/plain")
133
- subject.disallow_robots
134
- end
135
-
136
- it "should generate a robots.txt file which prevents everything by default" do
137
- expect(subject).to receive(:render).with(text: "User-agent: A\nDisallow: B\nDisallow: C\nDisallow: D\n\nUser-agent: E\nDisallow: F\nDisallow: \nDisallow: G", content_type: "text/plain")
138
- subject.generate_robots_txt([["A", "B", "C", "D"], ["E", "F", "", "G"]])
139
- end
140
- end
141
- end
@@ -1,23 +0,0 @@
1
- #
2
- # This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
3
- # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4
- #
5
-
6
- require "spec_helper"
7
-
8
- describe Ballast::Context do
9
- describe ".build" do
10
- it "should prepare data" do
11
- expect(Interactor::Context).to receive(:build).with({owner: "OWNER", errors: [], output: nil, response: an_instance_of(HashWithIndifferentAccess), a: 1, b: 2}.with_indifferent_access)
12
- Ballast::Context.build("OWNER", {a: 1, b: 2})
13
- end
14
- end
15
-
16
- describe "#method_missing" do
17
- it "should lookup for keys in the object" do
18
- context = Ballast::Context.build(nil, {output: 1})
19
- expect(context.output).to eq(1)
20
- expect { context.input }.to raise_error(NoMethodError)
21
- end
22
- end
23
- end