FAQ
Im using the spree_related_products<https://github.com/spree/spree_related_products> extension
on my project and added functionality to make the list of related products
an ordered list. This works fine. What I want to do now is write up a test
case to determine if the products are in the right position after their
positions have been updated.

I am currently trying something like this:

describe 'POST#update_positions' do

     before do

Spree::Admin::RelationsController.any_instance.stub(:model_class).and_return
Spree::Variant
     end

     it 'returns Ok on json' do
       variant = create(:variant)
       variant2 = create(:variant)
       expect {
    spree_post :update_positions, :id => variant.id, :positions => {
variant.id => '2', variant2.id => '1' }, :format => "js"
         variant.reload
       }.to change(variant, :position).from(nil).to(2)
     end

   end

which I found here<https://github.com/spree/spree/blob/11c9ce913531d19fd4ab19d7f95c8475c1a63cb1/backend/spec/controllers/spree/admin/resource_controller_spec.rb>.
When I try to test this following the *Development *instructions from
spree_related_products <https://github.com/spree/spree_related_products> repo,
I get the following error:

Failures:

   1) Spree::Admin::RelationsController POST#update_positions returns Ok on
json
      Failure/Error: variant = create(:variant)
      NoMethodError:
        undefined method `create' for
#<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9cab472af8>
      #
/Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-expectations-2.13.0/lib/rspec/matchers/method_missing.rb:9:in
`method_missing'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.14/lib/action_dispatch/testing/assertions/routing.rb:176:in
`method_missing'
      # ./spec/controllers/spree/admin/relations_controller_spec.rb:22:in
`block (3 levels) in <top (required)>'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in
`instance_eval'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in
`block in run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in
`instance_exec'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in
`instance_eval_with_args'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:247:in
`instance_eval_with_args'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:87:in
`block (2 levels) in run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in
`call'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in
`run_hook'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:329:in
`run_around_each_hooks'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:256:in
`with_around_each_hooks'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in
`block in run_examples'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in
`map'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in
`run_examples'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
`block in run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
`map'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
`block (2 levels) in run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
`map'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
`block in run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in
`report'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in
`run'
      # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in
`block in autorun'

Finished in 1.12 seconds
16 examples, 1 failure

Failed examples:

rspec ./spec/controllers/spree/admin/relations_controller_spec.rb:21 #
Spree::Admin::RelationsController POST#update_positions returns Ok on json

Search Discussions

  • Ryan Bigg at Jul 31, 2013 at 12:12 am
    create used to be a method added automatically by FactoryGirl. Now I think
    you need to "require 'factory_girl/syntax/methods'" to enable this
    functionality.

    On Wed, Jul 31, 2013 at 6:11 AM, cclerv wrote:

    Im using the spree_related_products<https://github.com/spree/spree_related_products> extension
    on my project and added functionality to make the list of related products
    an ordered list. This works fine. What I want to do now is write up a test
    case to determine if the products are in the right position after their
    positions have been updated.

    I am currently trying something like this:

    describe 'POST#update_positions' do

    before do

    Spree::Admin::RelationsController.any_instance.stub(:model_class).and_return
    Spree::Variant
    end

    it 'returns Ok on json' do
    variant = create(:variant)
    variant2 = create(:variant)
    expect {
    spree_post :update_positions, :id => variant.id, :positions => {
    variant.id => '2', variant2.id => '1' }, :format => "js"
    variant.reload
    }.to change(variant, :position).from(nil).to(2)
    end

    end

    which I found here<https://github.com/spree/spree/blob/11c9ce913531d19fd4ab19d7f95c8475c1a63cb1/backend/spec/controllers/spree/admin/resource_controller_spec.rb>.
    When I try to test this following the *Development *instructions from
    spree_related_products <https://github.com/spree/spree_related_products> repo,
    I get the following error:

    Failures:

    1) Spree::Admin::RelationsController POST#update_positions returns Ok on
    json
    Failure/Error: variant = create(:variant)
    NoMethodError:
    undefined method `create' for
    #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9cab472af8>
    #
    /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-expectations-2.13.0/lib/rspec/matchers/method_missing.rb:9:in
    `method_missing'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.14/lib/action_dispatch/testing/assertions/routing.rb:176:in
    `method_missing'
    # ./spec/controllers/spree/admin/relations_controller_spec.rb:22:in
    `block (3 levels) in <top (required)>'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in
    `instance_eval'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in
    `block in run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in
    `instance_exec'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in
    `instance_eval_with_args'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:247:in
    `instance_eval_with_args'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:87:in
    `block (2 levels) in run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in
    `call'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in
    `run_hook'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:329:in
    `run_around_each_hooks'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:256:in
    `with_around_each_hooks'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in
    `block in run_examples'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in
    `map'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in
    `run_examples'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
    `block in run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
    `map'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:372:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
    `block (2 levels) in run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
    `map'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in
    `block in run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in
    `report'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in
    `run'
    # /Users/{user}/.rvm/gems/ruby-1.9.3-p448/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in
    `block in autorun'

    Finished in 1.12 seconds
    16 examples, 1 failure

    Failed examples:

    rspec ./spec/controllers/spree/admin/relations_controller_spec.rb:21 #
    Spree::Admin::RelationsController POST#update_positions returns Ok on json





    --

    Ryan Bigg
    Community Manager
    Spree Commerce, Inc.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
categoriesrubyonrails
postedJul 30, '13 at 8:11p
activeJul 31, '13 at 12:12a
posts2
users2
websitespreecommerce.com
irc#RubyOnRails

2 users in discussion

Cclerv: 1 post Ryan Bigg: 1 post

People

Translate

site design / logo © 2022 Grokbase