Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Jiazhen Xie
@jiazhen
会员
第 15710 位会员 / 2014-11-02

3 篇帖子 / 78 条回帖
3 关注者
0 正在关注
0 收藏
GitHub Public Repos
  • em-capacity-app 8

    The app calculates engineering capacity by considering holidays, absences, and split roles where ...

  • releasehub 6

    Deliver codes faster and easier

  • LaTexCV 1

  • jiazhenxie-net 0

  • jiazhenxie 0

  • montecarlo-rb 0

    MonteCarloRB is a Ruby library designed to perform Monte Carlo simulations based on historical da...

  • docker-api-only 0

  • personal-website 0

    A personal resume website template built with React.js, Typescript, Next.js, and styled with Tail...

  • sheerdevelopment 0

    The personal website

  • etl-serverless 0

    build the API

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • Grape + RSpec 测试 如何 mock at 2014年11月04日

    #7 楼 @TsingHan @user生成于你 stub 之前,所以你此时不成功。

    before do
     Club.any_instance.stub(:is_admin?).and_return(true)
     @club   = create(:public_community)
       @member = @club.member
    end
    
    it "creates a conference" do
          post "/api/v1/conferences", @conference_params, {"HTTP_API_KEYAPI_KEY" => @member.api_token}
          expect(response.status).to eq(201)
        end
    

    应该就可以了

  • 新鲜信息的获取渠道 at 2014年11月04日

    同推荐 Hacker News. SHOW NH 的 session 很不错

  • ruby-china 里面 user 对象里面包含了 admin,但是我却找不到定义在哪里。 我理解不了 admin role 是哪里来的,有知道的可以帮我解答下吗,谢谢你了 at 2014年11月04日

    不知道你所谓的 ruby-china 里的 user 对象指的是什么?

  • Grape + RSpec 测试 如何 mock at 2014年11月04日

    @TsingHan allow(@club).to receive(:is_admin?).and_return(true) 只是 stub 了一个名叫@club的变量,它跟club = fetch_club 说的不是同一个,故而无用。

    假定fetch_club方法是Club.find,即 club 是 Club 的一个 instance, 你可以这样 stub

    Club.any_instance.stub(:is_admin?).and_return(true)
    

    Hope these help.

  • [上海徐汇] 招聘一名有经验的 Rails 工程师 at 2014年11月04日

    有缘帮顶

  • [远程] 每周休三天、凌晨工作,试着寻求一位可以晚上工作的同学 at 2014年11月03日

    好像不错,支持下

  • Rails 有关 Routes 的问题 at 2014年11月03日

    @Perry 可行。但是为什么要这么做呢?提交表单后的 action 确实是 create user,这样修改不符合 design pattern

  • 明天哪位好心人帮忙前排占个座 at 2014年11月03日

    额。。占什么位置 - -。。。

  • Rails 有关 Routes 的问题 at 2014年11月03日

    @Perry 看一下 rails 的官方 doc

    Call render to create a full response to send back to the browser
    Call redirect_to to send an HTTP redirect status code to the browser
    

    redirect_to 会直接重新 call UsersConroller#new, 此时@user就是一个新的 object, 它的 errors 是 nil 如果是 render, @user还是原来的 object, 错误在 errors 里,所以可以显示

  • 写完了,天快亮了,81 页 at 2014年11月03日

    辛苦了,期待 keynotes 😄

  • will_paginate 分页问题 at 2014年11月03日

    @dgy1126

    1. API 返回 array 可以。但是不必生硬地使用will_paginate,它可能不是一个适合的 gem
    2. 从架构方面讲,因为你的 rails 不能直接访问 DB,数据是从 API 来的。为什么不能直接显示 array? 你们需要的分页应该是 api pagination. FYI - https://github.com/davidcelis/api-pagination
    3. 更推荐你们实现自己的 API 分页,Keep it simple
  • 关于 rspec 中 its 的功能的疑问 at 2014年11月03日

    RSpec 2.x 中,it 会寻找subject的值. 如

    before { @user = User.create }
    subject { @user }
    it { should respond_to(:to_s) }  
    

    这里 it 就是指 @user

    而且,如前两位所说,it, its, should已经被 RSpec 3 取消了 (changelog - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3)

  • will_paginate 分页问题 at 2014年11月03日

    @dgy1126 查看了一下will_pagnate的代码 (https://github.com/mislav/will_paginate/blob/623e9c5390998a2aca283bca28009f7d479d5f0f/lib/will_paginate/array.rb#L29)

    WillPaginate::Collection.create(page, per_page, total) do |pager|
      pager.replace self[pager.offset, pager.per_page].to_a
    end
    

    因为当前 array 的 size 只有 10,但是你要把它 replace 从 index 40 - 50,所以返回 nil

    irb(main):014:0> array, another_array = [1,2,3], [3,4,5]
    => [[1, 2, 3], [3, 4, 5]]
    irb(main):015:0> array.replace another_array[40..50].to_a
    => []
    

    之前说的由 api 处理,意思是在程序的 archtecture 层面上你目前的实现方式不是很好,IMO

  • will_paginate 分页问题 at 2014年11月03日

    同意 @small_fish__ 的说法。数据既然是 api 请求,那么应该是通过修改 api 请求的参数来获取分页数据

    再看 will_paginate, 在 github 上说

    will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb, DataMapper and Sequel
    

    是直接对数据库进行 SQL 查询来实现分页

  • Atom 和 Sublime 哪个写 Ruby 更顺手一些?都要配置哪些插件? at 2014年11月02日

    现在一般用sublime. Multiple Selections, Split Editing etc 的功能挺实用的

  • [上海][2014年11月8日] 中国高性能架构和运维大会,免费参会 + 免费午餐 + 茶歇! at 2014年11月02日

    支持。期待国外站的活动! :)

  • [2014 年][10 月 20 日~11 月 12 日] 七牛三周年嘉年华,感恩有你! at 2014年11月02日

    33

  • 性能监控的好工具 - NewRelic 简介 at 2014年11月02日

    谢谢 @quakewang ! 期待有 Get started 建议教程~~

  • 上一页
  • 1
  • 2
  • 3
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English