hyrax-spec 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56f98b28611537d25097f62fbb3fc0a29134a528
4
- data.tar.gz: 05bbf255025da7828354c8c789066666fbd7cedc
3
+ metadata.gz: 387b76ffb416aa87c56d3af3b5b9e3566e3e0628
4
+ data.tar.gz: e56c6f049baf9e5da3f3448642b2335cea1f3a5c
5
5
  SHA512:
6
- metadata.gz: a56166d2f65ffaffced6e014e655564804f9f80bfd154b2de60c64b5a1f3d41a0629c7cc2f49317c7f94719be3531d377309506a35ecd9e3bf1e0d8c442a3a42
7
- data.tar.gz: c7e4601bc82514dd2d978806bb9453f05d11bd6ae17e9bcaa55404b5e2a5f281b60bc7e22c47021102787b710fefceb2304bd04b4cc0e5668908f848d8d1c523
6
+ metadata.gz: 20e0e71dfb0ac50e471d30d5c792339a02b5ef8f7f45652c80d29988c7411981f58a6df4944fc6f0805818ec45b98474dfd4c3d0fadfdb05a823287689e0053f
7
+ data.tar.gz: d06bba5e9d9378edd4195ab21521c18a4aa2425b4b1c53b0d9d2cd0284d0c38d6d8c89bcb8a04be63703da5752e64905fde2f1e7e125daae104d411eef9536d6
data/README.md CHANGED
@@ -3,8 +3,48 @@ Hyrax::Spec
3
3
 
4
4
  Shared examples and smoke tests for [Hyrax](https://github.com/samvera/hyrax) applications.
5
5
 
6
- ## License
6
+ ## `FactoryBot` Build Strategies for Hyrax
7
7
 
8
- `Hyrax::Spec` is available under [the Apache 2.0 license](LICENSE).
8
+ If your test suite uses `FactoryBot` (formerly `FactoryGirl`) to create test objects, `Hyrax::Spec` provides useful
9
+ custom build strategies that may simplify the setup phase of your tests. To register the build stratgies add the
10
+ following to your test helper (usually `spec/rails_helper.rb`):
11
+
12
+ ```ruby
13
+ # spec/rails_helper.rb
14
+
15
+ require 'hyrax/spec/factory_bot/build_strategies'
16
+ ```
17
+
18
+ ### `ActorCreate`
19
+
20
+ The `ActorCreate` strategy builds an object and passes it to the [Hyrax Actor
21
+ Stack](https://github.com/samvera/hyrax/wiki/Customizing-Actors) to be processed. In a normal RSpec Rails environment,
22
+ this will enqueue (but not perform) several background jobs (charactarization, derivatives, etc...). The specific actor
23
+ middleware called is `Hyrax::CurationConcern.actor`.
24
+
25
+ This strategy is registered by default as `actor_create`. You can use it with an existing factory, which must define
26
+ `user` as a [transient attribute](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#transient).
9
27
 
28
+ ```ruby
29
+ # factories/my_works.rb
30
+ FactoryBot.define do
31
+ factory(:my_work) do
32
+ title ['Comet in Moominland']
10
33
 
34
+ transient do
35
+ user { FactoryBot.create(:user) }
36
+ end
37
+ end
38
+ end
39
+
40
+ # my_work_spec.rb
41
+ RSpec.describe MyWork do
42
+ subject(:my_work) { FactoryBot.actor_create(:my_work) }
43
+
44
+ it { is_expected.to have_attributes(date_uploaded: an_instance_of(DateTime)) }
45
+ end
46
+ ```
47
+
48
+ ## License
49
+
50
+ `Hyrax::Spec` is available under [the Apache 2.0 license](LICENSE).
@@ -0,0 +1,12 @@
1
+ module Hyrax
2
+ module Spec
3
+ if defined?(FactoryBot) || defined?(FactoryGirl)
4
+ # support legacy FactoryGirl name, but use always FactoryBot internally
5
+ FactoryBot = FactoryGirl unless defined?(FactoryBot)
6
+
7
+ require 'hyrax/spec/factory_bot/build_strategies/actor_create'
8
+
9
+ FactoryBot.register_strategy(:actor_create, Hyrax::Spec::ActorCreate)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ module Hyrax
2
+ module Spec
3
+ ##
4
+ # A FactoryBot build strategy for creating Hyrax Works and running them
5
+ # through the actor stack.
6
+ #
7
+ # In a normal RSpec Rails environment, this will enqueue (but not perform)
8
+ # several background jobs (charactarization, derivatives, etc...). If you
9
+ # want to perform the jobs, configure that with:
10
+ #
11
+ # ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
12
+ # ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
13
+ #
14
+ # If you only want to perform specific job classes, you can do:
15
+ #
16
+ # ActiveJob::Base.queue_adapter.filter = [SpecificJobClassYouWantToRun]
17
+ #
18
+ # @example Registering the strategy and creating using an existing factory
19
+ # FactoryBot.register_strategy(:actor_create, ActorCreate)
20
+ #
21
+ # work = FactoryBot.actor_create(:a_work_factory)
22
+ #
23
+ # @see Hyrax::CurationConcern#actor
24
+ # @see https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#custom-strategies
25
+ class ActorCreate
26
+ def initialize
27
+ @association_strategy = FactoryBot.strategy_by_name(:create).new
28
+ end
29
+
30
+ delegate :association, to: :@association_strategy
31
+
32
+ def result(evaluation)
33
+ evaluation.object.tap do |instance|
34
+ evaluation.notify(:after_build, instance)
35
+
36
+ # @todo: is there a better way to get the evaluator at this stage?
37
+ # how should we handle a missing user?
38
+ ability = ::Ability.new(evaluation.instance_variable_get(:@evaluator).user)
39
+ env = Hyrax::Actors::Environment.new(instance, ability, {})
40
+
41
+ evaluation.notify(:before_create, instance)
42
+ evaluation.notify(:before_actor_create, instance)
43
+ Hyrax::CurationConcern.actor.create(env)
44
+ evaluation.notify(:after_create, instance)
45
+ evaluation.notify(:after_actor_create, instance)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
2
  module Spec
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyrax-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-21 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -70,6 +70,8 @@ files:
70
70
  - Rakefile
71
71
  - hyrax-spec.gemspec
72
72
  - lib/hyrax/spec.rb
73
+ - lib/hyrax/spec/factory_bot/build_strategies.rb
74
+ - lib/hyrax/spec/factory_bot/build_strategies/actor_create.rb
73
75
  - lib/hyrax/spec/matchers.rb
74
76
  - lib/hyrax/spec/matchers/act.rb
75
77
  - lib/hyrax/spec/matchers/have_editable_property.rb