小编kun*_*nnu的帖子

如何从字符串中删除HTML编码字符?

我有一个包含一些HTML编码字符的字符串,我想删除它们:

"<div>Hi All,</div><div class=\"paragraph_break\">< /></div><div>Starting today we are initiating PoLS.</div><div class=\"paragraph_break\"><br /></div><div>Please use the following communication protocols:<br /></div><div>1. Task Breakup and allocation - Gravity<br /></div><div>2. All mail communications - BC messages<br /></div><div>3. Reports on PoC / Spikes: Writeboard<br /></div><div>4. Non story related tasks: BC To-Do<br /></div><div>5. All UI and HTML will communicated to you through BC.<br /></div><div>6. For File sharing, we'll be using Dropbox.<br /></div><div>7. Use Skype for lighter and generic desicussions. However, in case you need any approvals, data …
Run Code Online (Sandbox Code Playgroud)

ruby string html-parsing

6
推荐指数
1
解决办法
4387
查看次数

使用Rspec在模型中测试关系和方法

我正在研究rails项目和我在rails上的新功能,我想使用rspec在模型中测试我的模型关系和方法.我怎么能这样做我的模型关系是这样的

class Idea < ActiveRecord::Base

  belongs_to :person
  belongs_to :company
  has_many :votes
  validates_presence_of :title, :description
  def published?
    if self.status == "published"
      return true
    else
      return false
    end
  end

  def image_present
    if self.image_url
      return self.image_url
    else
      return "/images/image_not_found.jpg"
    end
  end



  def voted
    self.votes.present?
  end
end
Run Code Online (Sandbox Code Playgroud)

我的idea_spec.rb文件是

require 'spec_helper'

describe Idea do

  it "should have title" do
  Idea.new(:title=>'hello',:description=>'some_desc').should be_valid
  end

  it "should have description" do
  Idea.new(:title=>'hello',:description=>'some_desc').should be_valid
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails ruby-on-rails-3.1

4
推荐指数
1
解决办法
3776
查看次数

使用Rspec在单元测试中测试"accepts_nested_attributes_for"

我是rails和测试模型的新手.我的模型类是这样的:

class Tester < Person
  has_one :company
  accepts_nested_attributes_for :skill   
end
Run Code Online (Sandbox Code Playgroud)

而且我想使用rspec和任何其他gem测试"accepts_nested_attributes_for:skill".我怎么能做到这一点?

ruby testing unit-testing rspec ruby-on-rails-3

4
推荐指数
1
解决办法
2354
查看次数