mardi 16 juillet 2019

Fixture record not found during bitbucket pipeline test

My rails app has many tests which all pass locally. When trying to run them in a bitbucket pipeline environment, they're failing when attempting to find the records:


Error:
ChannelActionTest#test_archive_channel_missing_id:
ActiveRecord::RecordNotFound: Couldn't find SocialChannel with 'id'=0f5de94a-a07b-535f-8204-be29371a5cf4 [WHERE "social_channels"."type" IN ('SocialChannel', 'FacebookChannel', 'InstagramChannel', 'LinkedinChannel', 'TwitterChannel')]
    test/actions/channel_action_test.rb:764:in `block in <class:ChannelActionTest>'
bin/rails test test/actions/channel_action_test.rb:761

The test that is failing (ironically, is suppose to fail in the end for other reasons...) because it's not finding the fixutre...

  test "archive channel missing channel" do
    channel = social_channels(:tw_channel) # fails here apparently? 

    action = ArchiveChannel.call
    assert action.failed?
  end

The fixture in question:

tw_channel:
  type: "TwitterChannel"
  name: "Twitter Channel"
  avatar: null
  settings: null
  network: "twitter"
  external_id: "tw1"
  authenticated: true

The social_channel model. It's a STI model, that inherits from channel

class SocialChannel < Channel
  self.table_name = "social_channels"

  # SCOPES ...

  # ASSOCIATIONS ...

  # METHODS ... 
end

class Channel < ApplicationRecord
  # SCOPES 

  # ASSOCIATIONS

  # METHODS ...
end


Not really sure what's happening... Here's my bitbucket-pipeline.yml file:


image: ruby:2.5

pipelines:
  default:
    - step:
        caches:
          - bundler
        script:
          #  cd to our build directory
          - cd $BITBUCKET_CLONE_DIR

          # add in some other needed stuff before bunder will run
          - echo "installing build essentials"
          - apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs ruby-dev libidn11 libidn11-dev yarn

          - echo "running bundler"
          - bundle install

          - echo "drop database"
          - rails db:drop RAILS_ENV=test

          - echo "create database"
          - rails db:create RAILS_ENV=test

          - echo "migrate database"
          - rails db:migrate RAILS_ENV=test

          - echo "test database"
          - rails test RAILS_ENV=test

        services:
          - postgres
          - redis
definitions:
  services:
    redis:
      image: redis
    postgres:
      image: postgres
      environment:
        POSTGRES_DB: $db_name
        POSTGRES_USER: $db_user
        POSTGRES_PASSWORD: $db_password
  caches:
    bundler: vendor/bundle


Aucun commentaire:

Enregistrer un commentaire