mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 07:23:46 +08:00
b8cbe51026
This conversion is done by Transpec 3.1.0 with the following command: transpec * 424 conversions from: obj.should to: expect(obj).to * 325 conversions from: == expected to: eq(expected) * 38 conversions from: obj.should_not to: expect(obj).not_to * 15 conversions from: =~ /pattern/ to: match(/pattern/) * 9 conversions from: it { should ... } to: it { is_expected.to ... } * 5 conversions from: lambda { }.should_not to: expect { }.not_to * 4 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: -> { }.should to: expect { }.to * 2 conversions from: -> { }.should_not to: expect { }.not_to * 1 conversion from: === expected to: be === expected * 1 conversion from: =~ [1, 2] to: match_array([1, 2]) For more details: https://github.com/yujinakayama/transpec#supported-conversions
68 lines
1.7 KiB
Ruby
68 lines
1.7 KiB
Ruby
module Helpers
|
|
def self.next_seq
|
|
@next_seq = (@next_seq || 0) + 1
|
|
end
|
|
|
|
def log_in(fabricator=nil)
|
|
user = Fabricate(fabricator || :user)
|
|
log_in_user(user)
|
|
user
|
|
end
|
|
|
|
def log_in_user(user)
|
|
provider = Discourse.current_user_provider.new(request.env)
|
|
provider.log_on_user(user,session,cookies)
|
|
end
|
|
|
|
def fixture_file(filename)
|
|
return '' if filename.blank?
|
|
file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
|
|
File.read(file_path)
|
|
end
|
|
|
|
def build(*args)
|
|
Fabricate.build(*args)
|
|
end
|
|
|
|
def create_topic(args={})
|
|
args[:title] ||= "This is my title #{Helpers.next_seq}"
|
|
user = args.delete(:user) || Fabricate(:user)
|
|
guardian = Guardian.new(user)
|
|
args[:category] = args[:category].name if args[:category].is_a?(Category)
|
|
TopicCreator.create(user, guardian, args)
|
|
end
|
|
|
|
def create_post(args={})
|
|
args[:title] ||= "This is my title #{Helpers.next_seq}"
|
|
args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}"
|
|
args[:topic_id] = args[:topic].id if args[:topic]
|
|
user = args.delete(:user) || Fabricate(:user)
|
|
args[:category] = args[:category].name if args[:category].is_a?(Category)
|
|
PostCreator.create(user, args)
|
|
end
|
|
|
|
def generate_username(length=10)
|
|
range = [*'a'..'z']
|
|
Array.new(length){range.sample}.join
|
|
end
|
|
|
|
def stub_guardian(user)
|
|
guardian = Guardian.new(user)
|
|
yield(guardian) if block_given?
|
|
Guardian.stubs(new: guardian).with(user)
|
|
end
|
|
|
|
def wait_for(&blk)
|
|
i = 0
|
|
result = false
|
|
while !result && i < 300
|
|
result = blk.call
|
|
i += 1
|
|
sleep 0.001
|
|
end
|
|
|
|
expect(result).to eq(true)
|
|
end
|
|
|
|
end
|