has_scope_matchers 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b589a04df480e8df69d7d48813fa8878acc5b648
4
+ data.tar.gz: e66e84919b2a1a594f849383a30e6c86a3baa7c1
5
+ SHA512:
6
+ metadata.gz: 95c97926b9b739daa5254057227c2768cbb4f599fff73a17b6ba6e42afeaf053d754d9a9daae39f8df86fbc7bcf47876dfbc3f8d2771d9eb8ff83d9a28128051
7
+ data.tar.gz: 4c4cb54a90498fcaf475bcfe99e15099493e877f6197d3627c256c757f2010f0dea1e3acb0a46a62e7f190ba119a9303af3b4e6592addafe7dc29173f728aa15
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ has_scope_matchers
@@ -0,0 +1 @@
1
+ ruby-2.2.1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in has_scope_matchers.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nick DeLuca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # HasScopeMatchers
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/has_scope_matchers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'has_scope_matchers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install has_scope_matchers
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/has_scope_matchers.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "has_scope_matchers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'has_scope_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "has_scope_matchers"
8
+ spec.version = HasScopeMatchers::VERSION
9
+ spec.authors = ["Nick DeLuca"]
10
+ spec.email = ["nickdeluca08@gmail.com"]
11
+
12
+ spec.summary = %q{ Rspec matchers for the has_scope gem}
13
+ spec.homepage = "https://github.com/halftime/has_scope_matchers"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "actionpack"
25
+ spec.add_development_dependency "has_scope"
26
+ end
@@ -0,0 +1,7 @@
1
+ require "has_scope_matchers/define_scope_matcher"
2
+ require "has_scope_matchers/integration"
3
+ require "has_scope_matchers/version"
4
+
5
+ module HasScopeMatchers
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,188 @@
1
+ module HasScopeMatchers
2
+ module DefineScopeMatcher
3
+
4
+ def define_scope(scope_name)
5
+ DefineScopeMatcher.new(scope_name)
6
+ end
7
+
8
+ class DefineScopeMatcher
9
+
10
+ def initialize(scope_name)
11
+ @scope_name = scope_name
12
+ end
13
+
14
+ def matches?(subject)
15
+ @subject = subject
16
+
17
+ scope_exists? &&
18
+ as_correct? &&
19
+ type_correct? &&
20
+ only_correct? &&
21
+ if_correct? &&
22
+ unless_correct? &&
23
+ allow_blank_correct? &&
24
+ using_correct?
25
+ end
26
+
27
+ def failure_message
28
+ @failure_message
29
+ end
30
+
31
+ def failure_message_when_negated
32
+ @negated_failure_message
33
+ end
34
+
35
+ def description
36
+ "Tests the scopes defined by the has_scope gem for rails controllers"
37
+ end
38
+
39
+ def as(value)
40
+ @as = value
41
+ self
42
+ end
43
+
44
+ def type(value)
45
+ @type = value
46
+ self
47
+ end
48
+
49
+ def using(value)
50
+ @using = value
51
+ self
52
+ end
53
+
54
+ def only(value)
55
+ @only = value
56
+ self
57
+ end
58
+
59
+ def except(value)
60
+ @except = value
61
+ self
62
+ end
63
+
64
+ def unless(condition)
65
+ @unless_condition = condition
66
+ self
67
+ end
68
+
69
+ def if(condition)
70
+ @if_condition = condition
71
+ self
72
+ end
73
+
74
+ def allow_blank(value)
75
+ @allow_blank = value
76
+ self
77
+ end
78
+
79
+ private
80
+
81
+ def scopes_configuration
82
+ @subject.scopes_configuration
83
+ end
84
+
85
+ def configuration
86
+ scopes_configuration[@scope_name]
87
+ end
88
+
89
+ def scope_exists?
90
+ if configuration
91
+ @negated_failure_message = "#{@subject} defines #{@scope_name} when it should not"
92
+ true
93
+ else
94
+ @failure_message = "#{@subject} does not define #{@scope_name}"
95
+ false
96
+ end
97
+ end
98
+
99
+ def as_correct?
100
+ return true if @as.nil?
101
+
102
+ if configuration[:as] != @as
103
+ @failure_message = "expected scope to be defined as #{@as}, got #{configuration[:as] || 'nil'}"
104
+ false
105
+ else
106
+ true
107
+ end
108
+ end
109
+
110
+ def type_correct?
111
+ return true if @type.nil?
112
+
113
+ if configuration[:type] != @type
114
+ @failure_message = "expected scope to have type #{@type}, got #{configuration[:type] || 'nil'}"
115
+ false
116
+ else
117
+ true
118
+ end
119
+ end
120
+
121
+ def using_correct?
122
+ return true if @using.nil?
123
+
124
+ if configuration[:using] != @using
125
+ @failure_message = "expected scope to use #{@using}, got #{configuration[:using] || 'nil'}"
126
+ false
127
+ else
128
+ true
129
+ end
130
+ end
131
+
132
+ def only_correct?
133
+ return true if @only.nil?
134
+
135
+ if configuration[:only] != [ @only ]
136
+ @failure_message = "expected scope to only allow #{@only} actions, got #{configuration[:only] || 'nil'}"
137
+ false
138
+ else
139
+ true
140
+ end
141
+ end
142
+
143
+ def except_correct?
144
+ return true if @except.nil?
145
+
146
+ if configuration[:except] != [ @except ]
147
+ @failure_message = "expected scope to not allow #{@except} actions, got #{configuration[:except] || 'nil'}"
148
+ false
149
+ else
150
+ true
151
+ end
152
+ end
153
+
154
+ def if_correct?
155
+ return true if @if_condition.nil?
156
+
157
+ if configuration[:if] != @if_condition
158
+ @failure_message = "expected if condition #{@if_condition}, got #{configuration[:if] || 'nil'}"
159
+ false
160
+ else
161
+ true
162
+ end
163
+ end
164
+
165
+ def unless_correct?
166
+ return true if @unless_condition.nil?
167
+
168
+ if configuration[:unless] != @unless_condition
169
+ @failure_message = "expected unless condition #{@unless_condition}, got #{configuration[:unless] || 'nil'}"
170
+ false
171
+ else
172
+ true
173
+ end
174
+ end
175
+
176
+ def allow_blank_correct?
177
+ return true if @allow_blank.nil?
178
+
179
+ if configuration[:allow_blank] != @allow_blank
180
+ @failure_message = "expected allow_balnk to be #{@allow_blank}, got #{configuration[:allow_blank] || 'nil'}"
181
+ false
182
+ else
183
+ true
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,8 @@
1
+ module HasScopeMatchers
2
+ module Integration
3
+
4
+ if defined?(RSpec)
5
+ require 'has_scope_matchers/integration/rspec'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require 'has_scope_matchers/define_scope_matcher'
2
+
3
+ module HasScopeMatchers
4
+ module Integration
5
+ module RSpec
6
+
7
+ ::RSpec.configure do |config|
8
+ config.include(HasScopeMatchers::DefineScopeMatcher)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module HasScopeMatchers
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_scope_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick DeLuca
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-08 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: has_scope
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - nickdeluca08@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-gemset"
93
+ - ".ruby-version"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - has_scope_matchers.gemspec
102
+ - lib/has_scope_matchers.rb
103
+ - lib/has_scope_matchers/define_scope_matcher.rb
104
+ - lib/has_scope_matchers/integration.rb
105
+ - lib/has_scope_matchers/integration/rspec.rb
106
+ - lib/has_scope_matchers/version.rb
107
+ homepage: https://github.com/halftime/has_scope_matchers
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Rspec matchers for the has_scope gem
131
+ test_files: []