a_r_mocker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6230cad73b222d649619c703d4b51c964066906a
4
+ data.tar.gz: bd970221b8047f0a0f71ef56f36bd938c8d03b10
5
+ SHA512:
6
+ metadata.gz: 77bf9fc4c2647025f6d56136c3ba766bc3fb96c72be41b78527819b9074fc93b1b10af1e270044b6d53c932d9c4d57af0552dfbd855d9ec29a119c1975275b78
7
+ data.tar.gz: 2a8a83fb8d82807e3e9c46aa6433db600cc17cae0affc01e8c3f497f6e62954864989528a6109f2836c22f161878853d97f9b9c3d1c00e3f3386c1ebf34fdbd5
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in a_r_mocker.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # ARMocker
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'a_r_mocker'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install a_r_mocker
18
+
19
+
20
+ ## Development
21
+
22
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+
24
+ 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).
data/Rakefile ADDED
@@ -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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'a_r_mocker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'a_r_mocker'
8
+ spec.version = ARMocker::VERSION
9
+ spec.authors = ['Steven Spiel']
10
+ spec.email = ['stevenspiel@gmail.com']
11
+
12
+ spec.summary = 'Mocks ActiveRecord models and relationships for form objects.'
13
+ spec.description = "Create relationships and models that work with form objects and don't dependant on a database schema."
14
+ spec.homepage = 'https://github.com/stevenspiel/a_r_mocker'
15
+ spec.licenses = ['MIT']
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3'
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "a_r_mocker"
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
data/bin/setup ADDED
@@ -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
data/lib/a_r_mocker.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'ostruct'
2
+ require 'a_r_mocker/version'
3
+ require 'a_r_mocker/models'
4
+ require 'a_r_mocker/model'
5
+ require 'a_r_mocker/relation'
6
+ require 'a_r_mocker/relation/has_many'
7
+
8
+ module ARMocker
9
+ end
@@ -0,0 +1,27 @@
1
+ module ARMocker
2
+ # Object that acts as an ActiveRecord model so form objects can use
3
+ # them as dummy data
4
+ class Model < OpenStruct
5
+ def initialize(hash = {})
6
+ @persisted = hash.delete(:persisted)
7
+ hash = default_attributes.merge(hash)
8
+ super
9
+ end
10
+
11
+ private def default_attributes
12
+ {
13
+ new_record?: !@persisted,
14
+ persisted?: @persisted,
15
+ id: @persisted ? 1 : nil,
16
+ created_at: @persisted ? Time.now : nil,
17
+ blank?: false
18
+ }
19
+ end
20
+
21
+ # for generating path from object (e.g. edit_model_path(model))
22
+ # For context, see ActionDispatch::Routing::RouteSet::Generator::PARAMETERIZE
23
+ def to_param
24
+ id
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module ARMocker
2
+ # Generates multiple Models. Attributes passed are applied to every model
3
+ # generated.
4
+ class Models
5
+ include Enumerable
6
+
7
+ # @param count [Integer] the number of models to be generated
8
+ # @param persisted [Boolean] whether the models will act as though they
9
+ # have persisted
10
+ # @param attributes [Hash] attributes to be applied to every model
11
+ def initialize(count, persisted, attributes = {})
12
+ @members = Array.new(count, ARMocker::Model.new(attributes.merge(persisted: persisted)))
13
+ end
14
+
15
+ def to_a
16
+ @members
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module ARMocker
2
+ module Relation
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ module ARMocker
2
+ module Relation
3
+ # A wrapper for models intended to act as an ActiveRecord::Relation
4
+ # for a has_many relationship
5
+ class HasMany
6
+ include Enumerable
7
+
8
+ def initialize(members)
9
+ @members = members.is_a?(ARMocker::Models) ? members.to_a : members
10
+ end
11
+
12
+ def each(&block)
13
+ @members.each(&block)
14
+ self
15
+ end
16
+
17
+ def build(attributes = {})
18
+ new_member = new_member(attributes.merge(persisted: false))
19
+ @members << new_member
20
+ new_member
21
+ end
22
+
23
+ def create(attributes = {})
24
+ created_member = new_member(attributes.merge(persisted: true))
25
+ @members << created_member
26
+ created_member
27
+ end
28
+
29
+ def delete(member)
30
+ @members.delete(member)
31
+ true
32
+ end
33
+
34
+ def to_ary
35
+ @members
36
+ end
37
+
38
+ private def new_member(attributes = {})
39
+ Model.new(attributes.merge(persisted: attributes.delete(:persisted)))
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module ARMocker
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: a_r_mocker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Spiel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-22 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: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ description: Create relationships and models that work with form objects and don't
56
+ dependant on a database schema.
57
+ email:
58
+ - stevenspiel@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - a_r_mocker.gemspec
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/a_r_mocker.rb
73
+ - lib/a_r_mocker/model.rb
74
+ - lib/a_r_mocker/models.rb
75
+ - lib/a_r_mocker/relation.rb
76
+ - lib/a_r_mocker/relation/has_many.rb
77
+ - lib/a_r_mocker/version.rb
78
+ homepage: https://github.com/stevenspiel/a_r_mocker
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Mocks ActiveRecord models and relationships for form objects.
102
+ test_files: []
103
+ has_rdoc: