miraculous 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in miraculous.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "rspec/expectations"
3
+
4
+ associations_and_matchers = {
5
+ belongs_to: 'belong_to',
6
+ has_many: 'have_many',
7
+ has_one: 'have_one'
8
+ }
9
+
10
+ associations_and_matchers.each do |association_type, association_matcher|
11
+ RSpec::Matchers.define association_matcher do |associated_class, options|
12
+ options ||= {}
13
+ options.reverse_merge!(:extend => []) if association_type == :has_many
14
+
15
+ match do |current_subject|
16
+ main_class = current_subject.kind_of?(Class) ? current_subject : current_subject.class
17
+
18
+ association = main_class.reflect_on_association(associated_class.to_sym)
19
+ association.should_not be_nil
20
+ association.macro.should == association_type
21
+
22
+ association_options = association.options
23
+
24
+ association_options.should == options
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "rspec/expectations"
3
+
4
+ RSpec::Matchers.define :allow_mass_assignment_of do |*options|
5
+ options.sort!
6
+
7
+ match do |current_subject|
8
+ main_class = current_subject.kind_of?(Class) ? current_subject : current_subject.class
9
+ accessible_attributes = main_class.accessible_attributes.to_a.map(&:to_sym).sort
10
+ accessible_attributes.should == options
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "rspec/expectations"
3
+
4
+ validations = {
5
+ validate_presence_of: ActiveModel::Validations::PresenceValidator,
6
+ validate_uniqueness_of: ActiveRecord::Validations::UniquenessValidator,
7
+ validate_associated_of: ActiveRecord::Validations::AssociatedValidator,
8
+ validate_length_of: ActiveModel::Validations::LengthValidator,
9
+ validate_inclusion_of: ActiveModel::Validations::InclusionValidator,
10
+ validate_numericality_of: ActiveModel::Validations::NumericalityValidator
11
+ }
12
+
13
+ validations.each do |validator_method, validator_class|
14
+ RSpec::Matchers.define validator_method do |attr, options|
15
+ options ||= {}
16
+ options.reverse_merge!(:case_sensitive => true) if validator_method == :validate_uniqueness_of
17
+
18
+ match do |current_subject|
19
+ main_class = current_subject.kind_of?(Class) ? current_subject : current_subject.class
20
+ validator_options = {}
21
+ validator_found = false
22
+
23
+ main_class.validators_on(attr).each do |validator|
24
+ next unless validator.is_a?(validator_class)
25
+ validator_found = true
26
+ validator_options.merge!(validator.instance_variable_get('@options'))
27
+ end
28
+
29
+ validator_found.should be_true
30
+ validator_options.should == options
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Miraculous
2
+ VERSION = "0.0.1.pre"
3
+ end
data/lib/miraculous.rb ADDED
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "miraculous/matchers/validations"
3
+ require "miraculous/matchers/associations"
4
+ require "miraculous/matchers/mass_assignment"
5
+ require "miraculous/version"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/miraculous/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["rafaeldx7"]
6
+ gem.email = ["rafaeldx7@gmail.com"]
7
+ gem.description = %q{Simple Rspec Matchers compatible with Remarkable gem.}
8
+ gem.summary = %q{Simple Rspec Matchers compatible with Remarkable gem.}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "miraculous"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Miraculous::VERSION
17
+
18
+ gem.add_runtime_dependency "rails", "~> 3.1.0"
19
+ gem.add_runtime_dependency "rspec", "~> 2.7.0"
20
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miraculous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - rafaeldx7
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70094282108240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70094282108240
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70094282107480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70094282107480
36
+ description: Simple Rspec Matchers compatible with Remarkable gem.
37
+ email:
38
+ - rafaeldx7@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
46
+ - lib/miraculous.rb
47
+ - lib/miraculous/matchers/associations.rb
48
+ - lib/miraculous/matchers/mass_assignment.rb
49
+ - lib/miraculous/matchers/validations.rb
50
+ - lib/miraculous/version.rb
51
+ - miraculous.gemspec
52
+ homepage: ''
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
65
+ - 0
66
+ hash: -1154775062114956795
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>'
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.1
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.10
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Simple Rspec Matchers compatible with Remarkable gem.
79
+ test_files: []